I've been searching everywhere and I couldn't find a concrete answer. Any help or pointers are appreciated!
I have a board that has a DS1307 (Tiny RTC) module connected to the 3.3V ESP8266 chip, and have identified an issue with the chip ceasing to work on 3.3V input when the battery is installed. The solution was to increase the module's VCC voltage to 5V.
With that, I thought I solved the problem for good and I could resume working on other parts of the code and circuit, but then found out that the clock stops running when the 5V power is removed.
The module has been modified as such to run safely on the 3.3V I2C bus and CR2032 (not LIR2032) battery. (Red diagonal line means that component is removed, green line means it's been replaced with a wire link)
The code used is the same as RTCLib sample code but cut down to only use hours, minutes and seconds:
#include "RTClib.h"
RTC_DS1307 rtc;
void setup () {
Serial.begin(57600);
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
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 loop () {
DateTime now = rtc.now();
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
}
The code works as intended when the power is supplied, however the module stops counting seconds after about 5~7 seconds when the power is cut. For example:
Power removed at 12:00:00, then wait 1 minute = When power is restored, it starts counting at 12:00:07, not 12:01:00 or such
The clock does not need to be very accurate, however it should at least keep the timer going when the power is cut. What is happening here? Any help would be appreciated!
(Note: The same deal happens when it's connected to 3.3V Arduino Nano. It's not a problem of the MCU itself, it seems.)
TL;DR:
The module works fine with and without the battery on 5V power as supplied.
The module does keep the last time it has counted to when the battery is connected and the VCC power is disconnected.
The problem is that it does not keep running to keep the time current, and gets stuck few seconds after powering off.
The MCU is not the problem. This symptom happens on both Arduino and ESP8266 using 3.3V I2C communication (but the module still gets 5V)
What I'm looking for is a solution to the problem of the clock not running when it's on battery power. NOT it straight-up not working.
Yes, that is true, but isn't the point of a real-time clock... it being a clock? As in it keeps track of time no matter what happens to the rest of the circuit? If putting a battery in it doesn't keep it going, there is something seriously wrong with it, and I can't figure out why.
The datasheet for the DS1307 states that the minimum supply voltage is 4.5V. Like it or not, you'll need a 5V supply in your circuit somewhere, as well as level shifters on the SDA and SCL lines.
Using a voltmeter, check the voltage at pin 3 of DS1307. I've had issues with batteries not making a connection in Chinese made battery holders.
Yes, I have ensured that it runs at at least 4.5V (VCC-GND). The modification only decouples SCL/SDA line from VCC for 3.3V MCUs, and disables charging the coin cell. As I said, the module still runs on 5V line. (Moreover, if the I2C communication didn't work at all, the time wouldn't display and it should display "Can't find RTC".)
See if you can get one to work. What Arduino are you using? The chip must have at least 4.5V to operate, here is a link to the data sheet I checked: https://www.analog.com/media/en/technical-documentation/data-sheets/ds1307.pdf Also you do not need level shifters on the I2C per data sheet: Serial Data Input/Output. SDA is the data input/output for the I2C serial interface. The SDA pin is open drain and requires an external pullup resistor. The pullup voltage can be up to 5.5V regardless of the voltage on VCC.
Arduino Nano, modified to run at 3.3V, and a ESP8266 development board. Both do work when 5V is supplied to VCC pin of the module, however at least with that specific module I used, it stops counting when that power is removed.
I tested a total of 7 modules, and here's the result:
Module 1: Keeps the time correctly
Module 2: Does not continue counting time after power is cut
Module 3: Ditto
Module 4: Counts for 2 seconds, then stops after power is cut
Module 5: Ditto
Module 6: Counts for 2~4 seconds, then stops after power is cut
Module 7: Counts for 5~7 seconds, then stops after power is cut
All 7 modules have the same modifications done to them, so I'm lost as to why only one seems to be working correctly.
I don't understand the circuit, particularly R7, R4 and R6.
When the main power to the module is turned off, is Vcc disconnected, or is it grounded? If it's diconnected, you have 683.3K resistance to the SQW OUT pin. Why would they do that?
Well, it just seems it's not oscillating on coin cell power. I don't know why. Does an unmodified module have the same problem?