RTC lost time

SukkoPera
Wed May 02, 2018 4:12 pm
In the last few days I’ve been testing the internal RTC on a Blue Pill. I connected a CR2032 to Vbat and I was quite happy with how it worked, keeping correct time even during power off.

Although, during a test I powered on the board and the RTC reset to 1978. Any idea what might have happened? Flat battery? What’s the recommended Vbat circuit, just the battery or maybe add a cap in parallel?


ag123
Wed May 02, 2018 6:10 pm
if it is an unprotected contraption made up of wires and ‘dupont’ pins there are a few occasions the pin either comes loose i.e. open circuit vbat or on other occasions i think i shorted vbat, when that happens, it wouldn’t be surprising if rtc reset in those circumstances

victor_pv
Wed May 02, 2018 9:59 pm
If you can repeat the exact same test with the same battery, you can try writting a value to one of the RAM registers protected by the VBAT, then upon reset if the date goes back to 1978 read that RAM value and check if it’s still the one you saved.
I believe as long as the RAM can keep the value, the RTC should also keep running.

ahull
Thu May 03, 2018 2:39 am
I would suggest soldering the connections to your battery holder, rather than relying on these so called “du-pont” wires.

Having said that, 1978 is an odd date to revert to, I thought the STM32F10X reverted to a date/time value of zero when the battery was disconnected which should correspond with Thursday, 1 January 1970 00:00:00 as these devices use “Epoch time” The 1st Jan 1978 has an epoch timestamp of 252460800


Pito
Thu May 03, 2018 6:45 am
Btw upload of a sketch messes the RTC even it is Vbat backuped..

SukkoPera
Thu May 03, 2018 7:47 am
I agree that 1978 is weird, but I might remember incorrectly. Anyway it happened a second time yesterday, and just after an upload (while the board was connected through USB), so Pito might be right, but what are you referring to, in particular?

ahull
Thu May 03, 2018 11:25 am
The connections provided by a lot of the clone “du-pont” wires (Chu-pont perhaps) are not very reliable. If you want a stable connection, then solder a battery holder to your board. I’m assuming you are not using a board that has a built in battery holder.

SukkoPera
Thu May 03, 2018 12:15 pm
I see, but the second time it happened the board was being powered!

fpiSTM
Thu May 03, 2018 12:27 pm
Which Clock is used for RTC clock? LSI? LSE? HSE?

SukkoPera
Thu May 03, 2018 2:01 pm
LSE

SukkoPera
Tue May 08, 2018 7:53 pm
OK, it was 1970, not ’78.

The RTC seems to reset when I open the serial terminal a few moments after connecting the board to the computer. Here’s the output of my program, which is supposed to print the time once every second:

RTC has set the system time

18:37:44 8/5/2018
0:00:18 1/1/1970
0:00:20 1/1/1970
0:00:21 1/1/1970


SukkoPera
Tue May 08, 2018 7:59 pm
OK, and here we go:

RTC has set the system time

19:57:45 8/5/2018
SETTING TIME TO 19
0:00:19 1/1/1970
0:00:21 1/1/1970


Leave a Reply

Your email address will not be published. Required fields are marked *