2009-08-02 03:23 AM
RTC Update Problem
2011-05-17 03:46 AM
I am trying to update my RTC with a new date/time. My code is modified from the RTC example, and is essentially the following:
RTC_WaitForLastTask(); RTC_SetCounter(Time); RTC_WaitForLastTask(); Time is a 32 bit unix timestamp. The first time I run this on the CPU (detected, as in the example, by a flag in backup register 1), it works. But later, if I update again, it fails by staying in the second call of RTC_WaitForLastTask() forever. Breaking on the loop and looking at the RTC->CRL register (via J-Link in IAR 5.2) shows the RTOFF bit as low and always low. The only thing I did significantly different from the example was I do not enable the interrupt (no NVIC settings, no call to RTC_ITConfig) because I do not want to reset to 0 after 23:59:59. Instead, as mentioned, I use the 32 bit counter as a unix style timestamp, so no such reset is required. Any idea what could be causing this? Thanks, Jeff2011-05-17 03:46 AM
Found the issue. The sample code only enabled the clocks when initializing the RTC. Its not needed to read the RTC, but is needed to write it.
2011-05-17 03:46 AM
Hello
I have the same problem. You said that you remove the second call and it works fine? In the manual reference (section 8.3.4), we have to call RTC_WaitForLastTask() each time we write in RTC registers. So, we don't have to remove it. Is it the final solution? Or is there an other reason why we get this issue?2011-05-17 03:46 AM
2011-05-17 03:46 AM
Hello,
After a reset, I set the 32 KHz LSE and I check the status of RCC_FLAG_LSERDY to make sure that the clock is set. I call RTC_WaitForSynchro() to make sure that the clocks are synchronized. Later, in the source code, I set the RTC_SetCounter(). Before and after this call, I call RTC_WaitForLastTask(). But at the second call, it doesn't exit from the second RTC_WaitForLastTask(). I have a watchdog reset and it works second time. I have always the problem when I power up the board.2011-05-17 03:46 AM
Quote:
On 07-11-2008 at 20:35, Anonymous wrote:
Later, in the source code, I set the RTC_SetCounter(). Before and after this call, I call RTC_WaitForLastTask(). But at the second call, it doesn't exit from the second RTC_WaitForLastTask(). I have a watchdog reset and it works second time. I have always the problem when I power up the board.I had the same problem. You need to add the following before writing to the RTC's registers. PWR_BackupAccessCmd(ENABLE); //Allow access to the RTC and Backup Registers [ This message was edited by: turbineltd on 02-08-2009 15:54 ]