Skip to main content
costi
Associate III
Jan 28, 2021 7:33 AM UTC
Solved

STM32L1 RTC interrupt using EXTI20 and wake-up from sleep mode

I programmed the STM32L151RET6 to gives the RTC interrupt using line EXTI20. The system is waking-up from sleep mode at every second, it execute a small code and left the interrupt.

For example:

void RTC_IRQ_Handler(void)

{

// { my code here }

//

   PWR->CR |= PWR_CR_DBP;      

   //

   RTC->ISR &= ~RTC_ISR_WUTF;   

   //

  PWR->CR &= ~PWR_CR_DBP;

   //

   EXTI_ClearPendingExti20();

}

The interrup is working but I have few seconds delay/day.

The flag RTC_ISR_WUTF can be erase only if the flag PWR_CR_DBP is set before.

The RTC clock is working well if I don't use the interrupt.

If I let always the flag PWR_CR_DBP set, the interrupt is executed but the RTC clock is stoped. THe date and time are freeze.

If the flag RTC_ISR_WUTF is not reset inside of interrupt routine the interrupt is executed only once (it's normal).

The RTC clock which I used is LSE.

I thing that when DBP bit is set the RTC clock is stopped and this is the cause of the delay.

It is possible to reset the WUTF without to set before DBP?

In the reference manual there is an information like this:

"This register is write protected (except for RTC_ISR[13:8] bits). The write access procedure is described in RTC register write protection on page 514."

  • normally the WUTF have to be erase without set DBP before

but at the procedure to access RTC I found the information:

"RTC register write protection

After system reset, the RTC registers are protected against parasitic write access with the DBP bit of the PWR power control register (PWR_CR). The DBP bit must be set to enable RTC registers write access."

  • so I understand that the DBP has to be set to access the RTC register, mandatory

Again, set the DBP at every interrupt interval causes a few seconds delay/day.

There is somebody with the same problem?

This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
Jan 29, 2021 4:01 PM UTC

OK so instead of

  RTC->ISR &= ~RTC_ISR_WUTF;  

try

  RTC->ISR = ~(RTC_ISR_WUTF | RTC_ISR_INIT);  

Does it make any difference?

JW

8 replies

costi
costiAuthor
Associate III
Jan 29, 2021 10:40 AM UTC

any idea ?

waclawek.jan
Super User
Jan 29, 2021 2:59 PM UTC

It sounds like you set RTC->ISR.INIT inadvertently, maybe in some other code you don't show here.

Do you use Cube/HAL?

JW

costi
costiAuthor
Associate III
Jan 29, 2021 3:21 PM UTC

Standard Library register definition I used.

waclawek.jan
waclawek.janBest answer
Super User
Jan 29, 2021 4:01 PM UTC

OK so instead of

  RTC->ISR &= ~RTC_ISR_WUTF;  

try

  RTC->ISR = ~(RTC_ISR_WUTF | RTC_ISR_INIT);  

Does it make any difference?

JW

costi
costiAuthor
Associate III
Jan 31, 2021 7:17 AM UTC

I'm sure that your suggestion would have solved my problem because the issue was happened because I left set calendar function with INIT flag set.

And with your suggestion the INIT flag would have been reset.

Thanks.

waclawek.jan
Super User
Jan 31, 2021 12:33 PM UTC

Thanks for coming back with the solution. Glad you got it working.

JW