RESET button intermittently stops DS1307 RTC

Hi

The program below works fine most of the time, i am using the Datalogging Shield V1 (with new coin cell battery) and an Arduino Due. The code simply sets the time on the DS1307 the first time the code is run following the insertion of the coin cell battery. After that, it just prints the current time according the DS1307 on to the Serial Monitor in loop. The wiring is straightforward, but note i DONT have the Shield mounted on the DUE, so the only connections are:

SCL on Due → SCL Pin 5 on Shield
SDA on Due → SDA Pin 4 on Shield
5v on Due → 5v on Shield
GND on Due → GND on Shield

The code works but, i notice that occasionally after pressing the reset button on the DUE it sometimes causes the RTC to lose time and stop running. The only way to start it up again is to remove power to the DUE and to remove and reinsert the coin cell battery.

Does anyone have any suggestions as to what might be causing this issue and how i may go about debugging it?

Thanks
A.

#include "RTClib.h"
RTC_DS1307 rtc;
char buf1[20];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(57600);

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running, let's set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));    
  }

}

void dateTime2myFormat(char* buf1, int sizeofbuffer)
{
  DateTime now = rtc.now();
  sprintf(buf1, "%02d:%02d:%02d %02d/%02d/%02d",  now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());
}

void loop() {

  dateTime2myFormat(buf1, 20);

  Serial.print(F("Date/Time: "));
  Serial.println(buf1);

}

Because the reset is not a power down and was at the middle of the i2C conversation.
With reset: SCL=LOW then pull HIGH with i2C initialization. (Keep HIGH)… The 1307 could read as a LO/HI signal of the SCL

Try this at the very beginning of the setup().
pimMode(SCL,OUTPUT);
digitalWrite(SCL,LOW);
delay(2000); // make sure the 1307 reset by timeout with the clock set to LOW.

Good luck!.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.