2017-10-25 03:09 AM
Hi there,
I'm using the RTC on my STM32F103 to keep the date and time but when I reset the MCU the date is lost.
I know that this behaviour is due to the RTC implementation ( it uses a counter ).
To prevent the date loss, I think to store the date into one or more backup register.
My date is composed by 3 byte (Year, Month and Date).
Could any one provide me a example about how to solve my problem?
Thanks!
#rtc-time-and-date #backup-registers #rtc-backup Note: this post was migrated and contained many threaded conversations, some content may be missing.2017-10-25 05:34 AM
Look at
https://community.st.com/0D50X00009XkW1nSAF
In the SPL we just managed the 32-bit count using epoch calendaring. See source for C library UNIX time management functions.
2017-10-25 08:07 AM
Hi Clive,
thanks for the link.
I have one question about the modification into HAL RTC library.
I saw that 'RTC_DateUpdate' is called only when the application try to read the time and the date from the RTC. So, if I never call HAL_RTC_GetDate and HAL_RTC_GetTime the date is never stored into the BKP_DR2. Am I right?
The second option is to store the unix time into the RTC second timer and use the function provided by time.h to convert the unix time to a date/time?
Thanks for the help
2017-10-25 08:13 AM
HAL's not my thing...
2017-10-25 08:16 AM
And about the second option?
The second option is to store the unix time into the RTC second timer and use the function provided by time.h to convert the unix time to a date/time?
2017-10-25 09:52 AM
Hello!
CNTH ,CNTL battery backuped real time clock registers can keep time and date for 136 years until wrapped.
Second option actually is not just an option if you want to have a battery backuped RTC with Calendar. It is imperative to use the
32b counter to keep the callendar and time.
Regards
vf
2017-10-25 10:01 AM
Hi Vangelis,
On my stm32f103, after a reset, only the time is resumed. And this is a know behaviour.
I also added a backup battery and when I re-plug the Vdd the MCU resume only the time but the date i always lost.
Every time I reboot the board I lose the Date!
The option B in to use the second RTC counter and keep track of unixtime?
Thanks!
2017-10-25 10:17 AM
The hardware only implements a second counter (can arguably tick faster/slower), it has no concept of date.
As stated, I've used SPL to implement an epoch based solution, I use one I wrote for WinCE, which is very similar to UNIX, but a different start date. Other times I use GPS day zero, depends on implementation simplicity and reduction of conversion back-and-forth between formats.
If the library you use is defective your option is to code something better.
2017-10-25 10:18 AM
>>
And about the second option?
I think I already stated that was the method I used/preferred.
2017-10-25 10:22 AM
I'm sorry but what is an SPL?
By the way, Is the second counter inside the RTC? I look into the datasheet but I don't find nothing.
A third option is to store the date into the internal flash memory.
Thanks