cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L452 RTC wakeup timer works, but just once

WPuch
Associate II

I initialize RTC timer by first clearing RTC_CR register,then waiting until WUTWF bit is on, then setting RTC WUTR register to 100, and RTC_CR to 0x4420 (wakeup timer enable, wakeup interrupt enable, bypass shadow). Bypass shadow register is set for other things.

This setting should generate interrupt 2048/100=about 20 times per second

NVIC is enabled for RTC wakeup interrupt, EXTI is properly set to rising edge for line 20.

The interrupt handler clears bit in EXTI_PR1 by writing 1 and clear bit 10 in RTC_ISR.

NET EFFECT: one interrupt is generated. that's all.

What i am doing wrong.

11 REPLIES 11

STM32L010RB (Nucleo-L010RB)

Had the exact same problem and your solution fixed it.
In my code i wrote something in the RTC backup register:

HAL_PWR_EnableBkUpAccess();
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR1, 0);
HAL_PWR_DisableBkUpAccess();

If i uncommet HAL_PWR_DisableBkUpAccess(); it works like a charm also without your fix.

 

My solution was to add your clear flag code in the AlarmA Event Callback:

void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) {
	// *** 
	// custom code
	// ***

	// Clear the RTC Alarm-A Flag
	HAL_PWR_EnableBkUpAccess();
	__HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
	HAL_PWR_DisableBkUpAccess();
}

 

Now it triggers an Alarm as expected, thank you!