cancel
Showing results for 
Search instead for 
Did you mean: 

RTC Alarm interrupt skipped sometimes

Florian Moser
Senior

Hi all!

uC: STM32L433VCT

CubeMX, CubeIDE, CubeProgrammer

I've configured my RTC to set an alarm every minute. When an alarm occurs, the next alarm gets set and so on.

About once to twice a day, the rtc alarm is skipped, so there's a continous error, because no future alarms are set.

My function to calculate the next alarm is correct (rtc_get_next_time()) and the alarm was set to the correct time, regarding to the rtc handle (RTC_HandleTypeDef hrtc;) Just the alarm interrupt doesn't get triggered.

It is not happening at the same time of the day, it's pretty random. It never happend from 23:xx to 0:xx.

Here's how I set the alarm:

void main_set_rtc_alarm(uint8_t hour, uint8_t minute, uint8_t second)
{
	RTC_AlarmTypeDef sAlarm = {0};
	sAlarm.AlarmTime.Hours = hour;
	sAlarm.AlarmTime.Minutes = minute;
	sAlarm.AlarmTime.Seconds = second;
	sAlarm.AlarmTime.SubSeconds = 0x0;
	sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
	sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
	sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
	sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
	sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
	sAlarm.AlarmDateWeekDay = 0x1;
	sAlarm.Alarm = RTC_ALARM_A;
 
	HAL_StatusTypeDef state = HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN);
 
	if (state != HAL_OK)
	{
		Error_Handler();
	}
}

When the alarm occurs:

void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
	timestamp_t next = rtc_get_next_time(rtc_get_current_time(),delay); // delay is 60s
        main_set_rtc_alarm(next.hour, next.minute, next.second);
}

I know this only works correct for delays up to 24h. That's just for testing purposes.

There are lots of different interrupts in this program. Maybe this causes the problem?

Thank you!

20 REPLIES 20

have you find the reason why missing the interrupt