I'm having an issue wherein TR and SSR values don't logically match up, on an approximately 1 Hz read cycle where reads occur very close to the RTC update time. I'm perplexed, and almost ready to throw my board onto the interstate and get a job as a bagger at my grocery store.
- µC is STM32F405RG. SYSCLK is 168 MHz and PCLK1 is 42 MHz.
- RTC is configured and started once (board has a backup battery) on startup when not already configured.
- RTC is clocked by 32.768 KHz LSE.
- PREDIV_S is set to 1024 to provide millisecond time resolution.
- An external device delivers messages to the µC every 1 sec (±20 ms or so) via a USART, and as a first test I added a call to fetch RTC time on (after) receipt of these messages.
Sometimes, if the timing is just right (such that the time fetch occurs close to the 1 Hz RTC update), I’ll see times like this:
RTC: 2013/03/20 08:48:56.024
RTC: 2013/03/20 08:48:57.026
RTC: 2013/03/20 08:48:58.027
RTC: 2013/03/20 08:48:59.025
RTC: 2013/03/20 08:49:01.993 <-- hey, it did NOT take that long!
RTC: 2013/03/20 08:49:01.015 <-- whoa, we moved backward in time?
RTC: 2013/03/20 08:49:03.995
RTC: 2013/03/20 08:49:04.995
RTC: 2013/03/20 08:49:04.015
RTC: 2013/03/20 08:49:06.994
RTC: 2013/03/20 08:49:07.982
RTC: 2013/03/20 08:49:07.015
RTC: 2013/03/20 08:49:09.994
RTC: 2013/03/20 08:49:10.994
RTC: 2013/03/20 08:49:10.014
RTC: 2013/03/20 08:49:12.993
Here is the time fetch procedure:
1) Clear RTC_ISR.RSF and wait for it to assert (tried manually and via RTC_WaitForSynchro()).
2) Read RTC_TR, RTC_SSR, and RTC_DR registers, in that order (also tried swapping TR/SSR read).
For absolute clarity, here's the code:
Many thanks in advance!!