just fyi i got it working correctly using the normal rtc library everyone uses for the 1307 (ie normal version since the other lib only worked on 1.0.2 and below) anyway, fires every second, clears alarm second later. thanks to supremo for figuring this out for me.
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
void setup () {
// pinMode(16, OUTPUT);
// digitalWrite(16, LOW);
// pinMode(17, OUTPUT);
// digitalWrite(17, HIGH);//use this for piggyback
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
RTC.adjust(DateTime(__DATE__, __TIME__));
Wire.beginTransmission(0x68); //supremos code
Wire.write(0x0b); //alarm2 addr // writes 0x80 to 3 registers which sets alarm 2 fire off when seconds register == 00 ie once a minute
Wire.write(0x80); //data to 0x0b
Wire.write(0x80); //data to 0x0c
Wire.write(0x80); //data to 0x0d
Wire.endTransmission();
}
void loop () {
Wire.beginTransmission(0x68);
Wire.write(0x0f); //status reg addr
Wire.endTransmission();
Wire.requestFrom(0x68,1); // read status register to see if alarm fired
byte statusBuffer=Wire.read();
byte y = bitRead(statusBuffer,1); //af2 bit indicates alarm2 fired if ==1
if (y==1)
{
Wire.beginTransmission(0x68); // clear alarm af2 bit
Wire.write(0x0F); //status register normally B10000000, only bits 0 and 1 can be written to, only with a 0, to clr alarms
Wire.write(0x80);
Wire.endTransmission();
}
gettime();
delay(1000);
}
void gettime(){
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}