When I try setting the time to anything from 2000 to 2012, it works. When I use a date greater than 2012, it just resets it back to 2000. Any idea why this might be?
Script:
#include <Wire.h>
#include <DS1307.h>
int rtc[7];
void setup()
{
Serial.begin(115200);
RTC.stop();
RTC.set(DS1307_SEC,0);
RTC.set(DS1307_MIN,0);
RTC.set(DS1307_HR,0);
RTC.set(DS1307_DOW,0);
RTC.set(DS1307_DATE,0);
RTC.set(DS1307_MTH,0);
RTC.set(DS1307_YR,12); // << Changing this to 2000 to 2012 works, 2013 onwards does not.
RTC.start();
}
void loop()
{
RTC.get(rtc,true);
for(int i=0; i<7; i++)
{
Serial.print(rtc[i]);
Serial.print(" ");
}
Serial.println();
delay(1000);
}
I’m using an Arduino RTC DS1307 AT24C32 (from here: http://www.ebay.co.uk/itm/170794819927).
I have wired it according to the diagram, but since I have an Arduino Mega 2560, pins 4 and 5 are now 20 (SDA) and 21 (SCL).
Hmm there does seem to be a bug with the set(int, int) method:
case DS1307_MTH:
if(v<13 && v>-1)
{
rtc_bcd[DS1307_MTH]=((v / 10)<<4) + (v % 10);
}
break;
case DS1307_YR:
if(v<13 && v>-1)
{
rtc_bcd[DS1307_YR]=((v / 10)<<4) + (v % 10);
}
break;
} // end switch
Looks like they may have just (inadvisably) copied that conditional from the set-month case. You could change that line in your DS1307.cpp file to something like
if (v<100 && v>-1) // n.b. this will break in year 2100
That seems to be a different RTC library than what came with my Time library (1.0.2)