Skip to main content
Richard Lowe
Senior II
September 30, 2023
Solved

RTC Alarm EventCallback called only 1 time

Working with the RTC I'm having some issue with the callback only being called a single time.

 

void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) {
 RTC_AlarmTypeDef sAlarm;
 uint32_t hobb_time;

 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); // Does not seem to change the ISR register

 hobb_time = HAL_RTCEx_BKUPRead(hrtc, RTC_BKP_DR1);

 // Write the new hobbs incremented value to backup register
 HAL_PWR_EnableBkUpAccess();
 HAL_RTCEx_BKUPWrite(hrtc, RTC_BKP_DR1, ++hobb_time);
 HAL_PWR_DisableBkUpAccess();

 HAL_RTC_GetAlarm(hrtc, &sAlarm, RTC_ALARM_A, FORMAT_BIN);

 if(sAlarm.AlarmTime.Minutes > 58)
 {
 sAlarm.AlarmTime.Minutes = 0;
 }
 else
 {
 sAlarm.AlarmTime.Minutes = sAlarm.AlarmTime.Minutes + 1;
 }

 while(HAL_RTC_SetAlarm_IT(hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK){}
}

 

I have the alarm being triggered every 1 minute. I can see the alarmA flag and try to clear it with this macro: 


__HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);

But the ISR register is unaffected. 

I've masked the DAYS, SECONDS, etc.

sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS
 |RTC_ALARMMASK_SECONDS;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;

Anybody working with alarm events that only trigger a single time?

This topic has been closed for replies.
Richard Lowe
Richard LoweBest answer
Senior II
October 18, 2023

The following lines will disable the RTC and cause all my issues:

HAL_PWR_EnableBkUpAccess();
HAL_RTCEx_BKUPWrite(hrtc, RTC_BKP_DR1, ++hobb_time);
HAL_PWR_DisableBkUpAccess();

The first line is already called in the RTC_Init() function, but the the last line, HAL_PWR_DisableBkUpAccess() will disable the RTC..... So that is why it was only called once.

3 replies

Richard Lowe
Senior II
October 3, 2023

I still have nothing. Seems like the HAL functions to perform all the actions called for in the datasheet. 

  • Clear the interrupt on the Alarm
  • Clear EXTI interrupt
  • Write to protection registers
  • Re-enable the interrupt

ISR Flag does not clear:
Screenshot from 2023-10-02 17-19-33.png

 

Still can only get a single interrupt. Single alarm handler, that's it..... Please advise.

Richard Lowe
Senior II
October 3, 2023

This is in HAL_RTC_SetAlarm_IT. Seems to include everything in the Reference Manual.

/* Disable the write protection for RTC registers */
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);

/* Configure the Alarm register */
if(sAlarm->Alarm == RTC_ALARM_A)
{
 /* Disable the Alarm A interrupt */
 __HAL_RTC_ALARMA_DISABLE(hrtc);

 /* Clear flag alarm A */
 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);

 tickstart = HAL_GetTick();
 /* Wait till RTC ALRAWF flag is set and if timeout is reached exit */
#if defined(TAMP)
 while (READ_BIT(hrtc->Instance->ICSR, RTC_FLAG_ALRAWF) == 0U)
#else
 while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == 0U)
#endif /* TAMP */
 {
 if((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
 {
 /* Enable the write protection for RTC registers */
 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);

 hrtc->State = HAL_RTC_STATE_TIMEOUT;

 /* Process Unlocked */
 __HAL_UNLOCK(hrtc);

 return HAL_TIMEOUT;
 }
 }

 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
 /* Configure the Alarm A Sub Second register */
 hrtc->Instance->ALRMASSR = subsecondtmpreg;
 /* Configure the Alarm state: Enable Alarm */
 __HAL_RTC_ALARMA_ENABLE(hrtc);
 /* Configure the Alarm interrupt */
 __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRA);

 

Richard Lowe
Richard LoweAuthorBest answer
Senior II
October 18, 2023

The following lines will disable the RTC and cause all my issues:

HAL_PWR_EnableBkUpAccess();
HAL_RTCEx_BKUPWrite(hrtc, RTC_BKP_DR1, ++hobb_time);
HAL_PWR_DisableBkUpAccess();

The first line is already called in the RTC_Init() function, but the the last line, HAL_PWR_DisableBkUpAccess() will disable the RTC..... So that is why it was only called once.