DS3231 RTC resetting to complied time on power cycle

Hi,

I have the DS3231 RTC module wired up to my arduino and am using the DS3231.h library. /dev/jarzebski: Zegar czasu rzeczywistego RTC DS3231

Works great, but on poeer cycle the time resets to the complied time and I have no idea why!

Any help would be appreciated.

*
  DS3231: Real-Time Clock. Simple example
  Read more: www.jarzebski.pl/arduino/komponenty/zegar-czasu-rzeczywistego-rtc-ds3231.html
  GIT: https://github.com/jarzebski/Arduino-DS3231
  Web: http://www.jarzebski.pl
  (c) 2014 by Korneliusz Jarzebski
*/

#include <Wire.h>
#include <DS3231.h>

DS3231 clock;
RTCDateTime dt;

void setup()
{
  Serial.begin(9600);

  // Initialize DS3231
  Serial.println("Initialize DS3231");;
  clock.begin();

  // Set sketch compiling time
  clock.setDateTime(__DATE__, __TIME__);
}

void loop()
{
  dt = clock.getDateTime();

  // For leading zero look to DS3231_dateformat example

  Serial.print("Raw data: ");
  Serial.print(dt.year);   Serial.print("-");
  Serial.print(dt.month);  Serial.print("-");
  Serial.print(dt.day);    Serial.print(" ");
  Serial.print(dt.hour);   Serial.print(":");
  Serial.print(dt.minute); Serial.print(":");
  Serial.print(dt.second); Serial.println("");

  delay(1000);
}
  clock.setDateTime(__DATE__, __TIME__);

resets the clock to compile date & time. Set it once then load a modified program that doesn't include that line.

Don't use the compiled time to set the clock. It's not accurate. Load a time setting example sketch instead, and set it manually.

dannable:

  clock.setDateTime(__DATE__, __TIME__);

resets the clock to compile date & time. Set it once then load a modified program that doesn’t include that line.

I uploaded the code once with the set time line, then commented it out and uploaded again.

I end up with:

Initialize DS3231
Raw data: 2000-1-1 0:0:5

Is the time incrementing every second?

It is yes, but only when powered. As soon as the power is turned off it resets to either the complied time, or (if commented) to 2000-1-1

samg2015:
It is yes, but only when powered. As soon as the power is turned off it resets to either the complied time, or (if commented) to 2000-1-1

It sounds like the RTC has no battery voltage.

I was starting to think that. I’ll go grab my voltmeter.

Thanks for your help.

Darn, new battery and still not holding the time.

I have a new DS3231 module, so I’ll try that, but then I’m kinda out of ideas.