Skip to main content
Visitor II
August 18, 2020
Question

RTC Alarm interrupt skipped sometimes

  • August 18, 2020
  • 11 replies
  • 5603 views

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!

    This topic has been closed for replies.

    11 replies

    Visitor II
    August 25, 2020

    I'm really confused right now.

    My IRQ handler looks like this:

    void RTC_Alarm_IRQHandler(void)
    {
     rtc_debug_pinstate = HAL_GPIO_ReadPin(RTC_DEBUG_GPIO_Port, RTC_DEBUG_Pin);
     rtc_debug_pinstate = !rtc_debug_pinstate;
     HAL_GPIO_WritePin(RTC_DEBUG_GPIO_Port, RTC_DEBUG_Pin, rtc_debug_pinstate);
     
     application_rtc_alarm();
     
     HAL_RTC_AlarmIRQHandler(&hrtc);
    }

    The pin get's toggled correctly everytime...

    Here's was happens in application_rtc_alarm:

    void application_rtc_alarm(void)
    {
    	rtc_reset_security_timer();
    	application_save_interval();
    	application_set_next_alarm();
    }
     
     
    void rtc_reset_security_timer(void)
    {
    	rtc_security_counter = 0;
    	rtc_security_counter_max = 0;
    }
     
    void application_save_interval(void)
    {
    	if(!application_should_save && !application_saving)
    	{
    		application_should_save = 1;
    	}
    	else error_handle(APP_ALREADY_SAVING,SOFT);
    }
     
    void application_set_next_alarm(void)
    {
    	if(!application_set_next_alarm_var) application_set_next_alarm_var = 1;
    	else error_handle(RTC_ALARM_ALREADY_PENDING,SOFT);
    }

    rtc_reset_security_timer() should reset the security timer, but that seems not to happen, because it counts till rtc_security_counter = 62 and rtc_security_counter_max = 63.

    There's also no sign that application_save_interval() and application_set_next_alarm() have been called.

    But as I said, the pin is toggled correctly everytime...

    Explorer
    December 22, 2023

    have you find the reason why missing the interrupt