cancel
Showing results for 
Search instead for 
Did you mean: 

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

costi
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions

OK so instead of

  RTC->ISR &= ~RTC_ISR_WUTF;  

try

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

Does it make any difference?

JW

View solution in original post

8 REPLIES 8
costi
Associate III

any idea ?

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

Standard Library register definition I used.

I set RTC->ISR Init flag only at the RTC initialization and when I set the calendar, otherwise not.

Thanks for answer.

OK so instead of

  RTC->ISR &= ~RTC_ISR_WUTF;  

try

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

Does it make any difference?

JW

You are right. I made a mistake at the RTC initilization. I reset the RTC INIT flag after that I locked the RTC registers and the INIT flag was always true.

Starting with your suggestion I could solve my problem (my mistake)

Thank you for your support.

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.

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

JW