2023-09-30 12:01 AM - edited 2023-09-30 12:16 AM
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?
Solved! Go to Solution.
2023-10-17 11:05 PM
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.
2023-10-02 05:18 PM - edited 2023-10-02 05:20 PM
I still have nothing. Seems like the HAL functions to perform all the actions called for in the datasheet.
ISR Flag does not clear:
Still can only get a single interrupt. Single alarm handler, that's it..... Please advise.
2023-10-02 05:32 PM
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);
2023-10-17 11:05 PM
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.