Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- void setup() {
- // Start the serial port
- Serial.begin(9600);
- // Start the I2C interface
- Wire.begin();
- pinMode(3, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(3), writeOut, FALLING);
- }
- void writeOut()
- {
- Serial.println("Recieved");
- }
- void loop() {
- //First lets set the alarm 2
- setAlarm();
- }
- void setAlarm()
- {
- // Set our alarm bits
- Wire.beginTransmission(0x68); //begin session to RTC
- Wire.write(0x0B); //Address we wish to write to
- Wire.write(0B1000000); //A2M2 Enabled with 10 for minutes
- Wire.write(0B1000000); //A2M3 Enabled with 11 set for hours (24 hr format)
- Wire.write(0B1000000); //A2M4 Enabled with trig on Day 1
- Wire.write(0B0000110); //Alarm 2 enabled, interupt enabled, alarm 1 disabled, oss diabled
- Wire.write(0B0000000); //Disable Osc Stop bit, 32khz, A2 flag, A1 flag
- Wire.endTransmission(); //End write Session
- Wire.beginTransmission(0x68); //begin write session for 0x0B
- Wire.write(0x0B); //goto the bit we want
- Wire.endTransmission(); //close our request
- Wire.requestFrom(0x68, 5);
- for (int i = 0; i < 5; i++)
- {
- Serial.print("Line " + (String)i + " :");
- Serial.print(Wire.read(), BIN);
- Serial.print("\r\n");
- }
- Serial.println("--------------");
- while (true)
- {
- delay(1000);
- Wire.beginTransmission(0x68); //begin write session for 0x0B
- Wire.write(0x00); //goto the bit we want
- Wire.endTransmission(); //close our request
- Wire.requestFrom(0x68, 16);
- for (int j = 0; j < 16; j++)
- {
- if (j == 0)
- {
- byte timeVal = Wire.read();
- int ten = timeVal >> 4;
- int one = timeVal & 0b00001111;
- Serial.println("T" + (String)ten + (String)one);
- }
- else if (j == 14)
- {
- Serial.print(Wire.read(), BIN);
- Serial.println();
- Serial.print(Wire.read(), BIN);
- Serial.println();
- }
- else
- {
- Wire.read();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement