cancel
Showing results for 
Search instead for 
Did you mean: 

RTC Update Problem

jwormsley2
Associate II
Posted on August 02, 2009 at 12:23

RTC Update Problem

6 REPLIES 6
jwormsley2
Associate II
Posted on May 17, 2011 at 12:46

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,

Jeff

jwormsley2
Associate II
Posted on May 17, 2011 at 12:46

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.

cgrenier
Associate II
Posted on May 17, 2011 at 12:46

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?

16-32micros
Associate III
Posted on May 17, 2011 at 12:46

Hi,

After having disabled the RTC APB1 interface, the software must first wait for the RSF bit (Register Synchronized Flag) in the RTC_CRL register to be set by hardware before reading the RTC registers. This ensures the two RTC domain clocks are synchronized.

Cheers,

STOne-32.

cgrenier
Associate II
Posted on May 17, 2011 at 12:46

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.

turbineltd
Associate
Posted on May 17, 2011 at 12:46

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 ]