Open zekageri opened 10 months ago
@zekageri Thanks for using my library.
The DS3231 datasheet contains more information about battery operation. For example function isRunning()
returns the inverted value of bit OSF
(Oscillator Status Flag) in the status register. When isRunning()
returns false
(OSF
bit is set), it means:
EOSC
bit is turned off in battery-backed mode. (explicitly stop the oscillator by calling clockEnable(false)
)You're checking the battery state correct in function checkBattery()
at boottime. Only when the oscillator was stopped, function rtc.clockEnable(true)
should be called (this starts the oscillator, bit EOSC
set in control register) and the RTC date/time should be re-programmed. Function clockEnable(true)
also clears the OSF
status register here. That's the reason why the next rtc.isRunning()
returns true
.
Calling isRunning()
periodically at run-time returns the oscillator state which may be stopped by points 3 and 4. Theoretically, I think there is no way to detect a low-battery state at run-time to inform users to replace the battery. The RTC keeps running as long as:
Maybe an idea to add an ADC to measure the battery voltage? I'm not sure how fast the ADC pin drains the battery.
Success!
I have an arduino project with ESP32 and I'm using this library ( which is great btw ). Currently on power on I'm doing the following
If i call
rtc.clockEnable(true);
the library will tell me that the battery is ok even if it is drained. But if i don't set the clock to true it will never be ok, even if i replace the battery.What is the recommended way of handling the low battery? I want to report to the users that they should replace it even at runtime. So i would call the check battery function periodically.