Advertisement
Guest User

DS3231 Alarm Interrupt Test

a guest
Jan 16th, 2019
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2.  
  3. void setup() {
  4.   // Start the serial port
  5.   Serial.begin(9600);
  6.  
  7.   // Start the I2C interface
  8.   Wire.begin();
  9.  
  10.   pinMode(3, INPUT_PULLUP);
  11.   attachInterrupt(digitalPinToInterrupt(3), writeOut, FALLING);
  12. }
  13.  
  14. void writeOut()
  15. {
  16.   Serial.println("Recieved");
  17. }
  18.  
  19. void loop() {
  20.   //First lets set the alarm 2
  21.   setAlarm();
  22. }
  23.  
  24. void setAlarm()
  25. {
  26.   // Set our alarm bits
  27.   Wire.beginTransmission(0x68); //begin session to RTC
  28.   Wire.write(0x0B); //Address we wish to write to
  29.   Wire.write(0B1000000); //A2M2 Enabled with 10 for minutes
  30.   Wire.write(0B1000000); //A2M3 Enabled with 11 set for hours (24 hr format)
  31.   Wire.write(0B1000000); //A2M4 Enabled with trig on Day 1
  32.   Wire.write(0B0000110); //Alarm 2 enabled, interupt enabled, alarm 1 disabled, oss diabled
  33.   Wire.write(0B0000000); //Disable Osc Stop bit, 32khz, A2 flag, A1 flag
  34.   Wire.endTransmission(); //End write Session
  35.  
  36.   Wire.beginTransmission(0x68); //begin write session for 0x0B
  37.   Wire.write(0x0B); //goto the bit we want
  38.   Wire.endTransmission(); //close our request
  39.   Wire.requestFrom(0x68, 5);
  40.  
  41.   for (int i = 0; i < 5; i++)
  42.   {
  43.     Serial.print("Line " + (String)i + " :");
  44.     Serial.print(Wire.read(), BIN);
  45.     Serial.print("\r\n");
  46.   }
  47.  
  48.  
  49.   Serial.println("--------------");
  50.  
  51.   while (true)
  52.   {
  53.     delay(1000);
  54.     Wire.beginTransmission(0x68); //begin write session for 0x0B
  55.     Wire.write(0x00); //goto the bit we want
  56.     Wire.endTransmission(); //close our request
  57.     Wire.requestFrom(0x68, 16);
  58.     for (int j = 0; j < 16; j++)
  59.     {
  60.       if (j == 0)
  61.       {
  62.         byte timeVal = Wire.read();
  63.         int ten = timeVal >> 4;
  64.         int one = timeVal & 0b00001111;
  65.         Serial.println("T" + (String)ten + (String)one);
  66.       }
  67.       else if (j == 14)
  68.       {
  69.         Serial.print(Wire.read(), BIN);
  70.         Serial.println();
  71.         Serial.print(Wire.read(), BIN);
  72.         Serial.println();
  73.       }
  74.       else
  75.       {
  76.         Wire.read();
  77.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement