‎2019-04-19 01:21 AM
Hi all,
I'm faced with a strange issue: updating the RTC calendar does not seem to be possible after a wake-up from standby mode.
I have a piece of code that updates the RTC calendar (date and time are uint32_t):
// rtc disable write protection
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
// rtc enable calendar init
RTC->ISR |= RTC_ISR_INIT;
while ((RTC->ISR & RTC_ISR_INITF) != RTC_ISR_INITF) {}
// set the time
rtc_set_time(time);
rtc_set_date(date);
// rtc disable calendar init
RTC->ISR &= ~RTC_ISR_INIT;
// rtc enable write protection
RTC->WPR = 0XFF;
This piece of code can be called multiple times to change the RTC calendar without any issue. It works well.
However if the MCU enters standby mode and then exists that mode, this code won't work anymore, because the following loop of code never ends:
while ((RTC->ISR & RTC_ISR_INITF) != RTC_ISR_INITF) {}
I can still read the calendar and it works fine, but I can't update it.
My RTC initialisation code behaves slightly differently when it starts from a "cold" boot versus when it wakes up from standby:
The only way I have found to get around this issue is to perform a full reset of the RTC domain each time the MCU boots. Since this reset also erases the date and time, I backup them up and restore them after the reset. However this feels like a terrible hack.
Any ideas what I'm doing wrong?
Best regards,
Alain
Solved! Go to Solution.
‎2019-04-19 02:18 AM
OK. It was my bad. Write access to the backup register was not correctly setup on wakeup. After correction it all works now.
Apologies for the distraction. :(
Best regards,
Alain
‎2019-04-19 02:18 AM
OK. It was my bad. Write access to the backup register was not correctly setup on wakeup. After correction it all works now.
Apologies for the distraction. :(
Best regards,
Alain