Go Down

Topic: RTC DS1307 does not keep time when unplugged (Read 976 times) previous topic - next topic

_Roms_

Hello,

I just received the SparkFun Real Time Clock Module but the clock stops when unplugged.

I checked the battery (reads 3V) and I'm using the sample code shipped with the RTC. No, I'm not resetting the time each time and I'm calling rtc.setTime only once ;)

Any help would be greatly appreciated!
Thanks!

PaulS

Quote
No, I'm not resetting the time each time and I'm calling rtc.setTime only once
The code you posted doesn't read the time correctly.
The art of getting good answers lies in asking good questions.

_Roms_

What do you mean? here's the sample code:
Code: [Select]

void setup()
{
  // Use the serial monitor to view time/date output
  Serial.begin(9600);
 
  rtc.begin(); // Call rtc.begin() to initialize the library
 
  // Now set the time...
  // rtc.setTime(16, 32, 7, 2, 31, 10, 16);  // Uncomment to manually set time
}

void loop()
{
  static int8_t lastSecond = -1;
 
  // Call rtc.update() to update all rtc.seconds(), rtc.minutes(), etc. return functions.
  rtc.update();

  if (rtc.second() != lastSecond) // If the second has changed
  {
    Serial.print(String(rtc.hour()) + ":"); // Print hour
    if (rtc.minute() < 10)
      Serial.print('0'); // Print leading '0' for minute
    Serial.print(String(rtc.minute()) + ":"); // Print minute
    if (rtc.second() < 10)
      Serial.print('0'); // Print leading '0' for second
    Serial.print(String(rtc.second())); // Print second
   
    lastSecond = rtc.second(); // Update lastSecond value
  }
}


aarg

  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

cattledog

Also confirm that the battery voltage is present at the DS1307 chip . Sometimes the battery holders can be defective. In this image, the two pins at the top left of the chip are ground(at the far left) and Vbat(next to the two pins going to the crystal oscillator 32C3Y). With power off and a multimeter, confirm that the battery voltage is present at the chip.


_Roms_

Thanks for the tips!

I will have to check a little more but it seems that I have 3V voltage (when running on battery). I will let you know later today.

My suspicion is that the oscillator is dead. I tried to shoot an email to Adafruit customer support, just in case...




cattledog

Quote
the clock stops when unplugged.
Quote
My suspicion is that the oscillator is dead.
An oscillator which runs on usb but not on battery is unusual.  Here is an old thread covering several ds1307 chip and oscillator problems when running on battery voltage. http://forum.arduino.cc/index.php?topic=303406.0


I would not expect these kinds of problems with a Spark Fun Module, but there may be some information in the thread you find useful.

el_supremo

Quote
I tried to shoot an email to Adafruit customer support
Why? You said it is a Sparkfun module.

Code: [Select]
   Serial.print(String(rtc.hour()) + ":"); // Print hour
Why are you using String for such a trivial operation? rtc.hour() returns an integer which is then converted to a String. Then ":" is concatenated to the integer String and then the resulting String is printed.
Code: [Select]
   Serial.print(rtc.hour());
    Serial.print(":");

Print the integer returned by rtc.hour(). Print the semicolon. Done. This has the added advantage that, unlike using the String library, it doesn't run the risk of running out of memory.

Pete
Don't send me technical questions via Private Message.

_Roms_

Sorry, I meant I sent an email to Sparkfun's customer support.

It seems I have a 0.5v reading at the DS1307 chip (as measured in the picture below)


Thanks a lot for the C tip, I doubt it's related to my issue but it's good to know for the future... :)

_Roms_

Update: After messing with the CH (Clock Halt) bit, I think I enabled the oscillator and it's working now!
Thanks @cattledog for the link! :)

PaulMurrayCbr

Pull out the little plastic tab that stops the battery discharging while the module is on the shelf at the shop.
http://paulmurraycbr.github.io/ArduinoTheOOWay.html


Go Up