DS3231 RTC auto resets every 5 minutes

This is completely puzzling me. I'm using this library and examples for my DS3231 RTC module on a pro mini:

and here is the serial output:

8:14:54 7 5 2015
8:14:55 7 5 2015
8:14:56 7 5 2015
8:14:57 7 5 2015
8:14:58 7 5 2015
8:14:59 7 5 2015
8:10:00 7 5 2015
8:10:01 7 5 2015
8:10:02 7 5 2015
8:10:03 7 5 2015
8:10:04 7 5 2015
8:10:05 7 5 2015
8:10:06 7 5 2015
8:10:07 7 5 2015
8:10:08 7 5 2015

I have no clue as to why after every 5 minutes it keeps on resetting to 10 minutes instead of flipping over to 15 minutes. Please can anyone shed some light on this?

I'm pretty sure the error is in line #32. Oh wait...you didn't post your code.

Sorry I figured the link would suffice since I haven’t modified the code, here it is:

/*
 * TimeRTC.pde
 * Example code illustrating Time library with Real Time Clock.
 * This example is identical to the example provided with the Time Library,
 * only the #include statement has been changed to include the DS3232RTC library.
 */

#include <DS3232RTC.h>    //http://github.com/JChristensen/DS3232RTC
#include <Time.h>         //http://www.arduino.cc/playground/Code/Time  
#include <Wire.h>         //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)

void setup(void)
{
    Serial.begin(9600);
    setSyncProvider(RTC.get);   // the function to get the time from the RTC
    if(timeStatus() != timeSet) 
        Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time");      
}

void loop(void)
{
    digitalClockDisplay();  
    delay(1000);
}

void digitalClockDisplay(void)
{
    // digital clock display of the time
    Serial.print(hour());
    printDigits(minute());
    printDigits(second());
    Serial.print(' ');
    Serial.print(day());
    Serial.print(' ');
    Serial.print(month());
    Serial.print(' ');
    Serial.print(year()); 
    Serial.println(); 
}

void printDigits(int digits)
{
    // utility function for digital clock display: prints preceding colon and leading 0
    Serial.print(':');
    if(digits < 10)
        Serial.print('0');
    Serial.print(digits);
}

Sorry I figured the link would suffice since I haven't modified the code

You will get a lot more responses if you don't expect the reader to go to a different web site, download and expand the file, probably for a library they don't want or need. Also, Jack's code is always top notch and most of us here would be very surprised to find an error in it. It's more likely that the RTC board is wired incorrectly or is faulty.

econjack:
You will get a lot more responses if you don't expect the reader to go to a different web site, download and expand the file, probably for a library they don't want or need. Also, Jack's code is always top notch and most of us here would be very surprised to find an error in it. It's more likely that the RTC board is wired incorrectly or is faulty.

Duly noted, thanks for the tip.

The code uses a sync provider for the Time library.

   setSyncProvider(RTC.get);   // the function to get the time from the RTC

This tells the Time library to go read the RTC chip every five minutes and update the internal time in the Time library.

My guess is that something is not working properly with the RTC like it isn't running or maybe it isn't really a 3231 or 3232 chip.
So the code reads the time, the Time library bumps it for 5 minutes, then it goes out and reads the time from the RTC, which isn't incrementing so it sets the time backwards.

Jack made some recent changes to how the OSF bit is handled and it is now properly cleared whenever the time is set.

Make sure you have the latest version of the library and use it when setting the time.
I'm guessing that if you set the time in the RTC using the latest library code that your problem will go away.

--- bill

If the oscillator continues to stop, here is some imformation from the DS3231 data sheet

Bit 7: Oscillator Stop Flag (OSF). A logic 1 in this bit indicates
that the oscillator either is stopped or was stopped
for some period and may be used to judge the validity of
the timekeeping data. This bit is set to logic 1 any time
that the oscillator stops. The following are examples of
conditions that can cause the OSF bit to be set:

  1. The first time power is applied.
  2. The voltages present on both VCC and VBAT are insufficient
    to support oscillation.
  3. The EOSC bit is turned off in battery-backed mode.
  4. External influences on the crystal (i.e., noise, leakage,
    etc.).
    This bit remains at logic 1 until written to logic 0.

A 3232/3231/ will automatically start running when the main power is applied.
If the battery was low when main power went off and then main power is applied, the OSF bit will be set but the oscillator will not be running.
i.e. there is no way to stop the oscillator on the DS3232/DS3231 like you can on other RTC chips.

This is a very significant difference from the other RTC chips like the 1307 etc…
On those chips you have to explicitly deal with the “running” bit. If it is not set appropriately in those chips, you can set the time but time will not advance.

This is the reason I asked if the RTC was really a DS3232/DS3231.
The 3232/3231 library code will “kind of” work on the other RTC chips like the 1307 since the time keeping registers are compatible but if it is not a DS3232/DS3231 then the RTC could be stuck not working if the “running” bit is not set appropriately which will not get set by this library since this library is for the 3232/3231.

Since it has been a while, has anyone found a solution to the problem or was the RTC just defective?

lg, couka