2019-05-06 07:42 AM
I'm using STM32L152RE with FreeRtos for our project. We use RTC HAL library to handle the Calendar alarms.
I'm in a strange situation where the RTC_ALARM_A does not generate an interrupt after 12 midnight.
The current system is setup to generate an alarm interrupt every 1hr. This functionality is implemented in the following manner -
```
RTC Alarm Generated -> Interrupt Handler Triggers an Event -> Event gathers current time & adds 1hr to it, activates the alarm again.
```
void HourlyAlarmRoutine ( void )
{
// Get current caleneder Time
ALARM_sTime_t sTime;
ALARM_sDate_t sDate;
ALARM_GetCalendarTime(&sTime, &sDate);
// Set Alarm after (x + 1) hours
ALARM_sAlarm_t sAlarm;
sAlarm.Alarm = ALARM_BACKUP_ID;
sAlarm.AlarmDateWeekDay = 0;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
sAlarm.AlarmTime.Seconds = 00;
sAlarm.AlarmTime.Minutes = sTime.Minutes;
sAlarm.AlarmTime.Hours = ( sTime.Hours + uBackupCheckingHours ) % 24;
ALARM_ActivateAlarm(&sAlarm);
}
void ALARM_ActivateAlarm(ALARM_sAlarm_t* p_sAlarm)
{
// Not using SubSecond module
p_sAlarm->AlarmTime.SubSeconds = 0;
p_sAlarm->AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
if (HAL_RTC_SetAlarm_IT(m_rtcHandles[ALARM_RTC_ID], (RTC_AlarmTypeDef*)p_sAlarm,RTC_FORMAT_BIN)!= HAL_OK)
{
// Handle Error
}
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
}
The code works perfectly until after midnight. i.e It generates an interrupt every hour until after 12 midnight ( 00 hours ) . Trying to set an alarm for 1am throws and error.
Can anyone help me spot the mistake ?
Thanks
2019-05-16 07:14 AM
yes I'm sure that it is not in BCD Format. The always pass `RTC_FORMAT_BIN` when setting a alarm.
The value of `uBackupCheckingHours` can be any whole number from 1-23.
2019-05-16 07:29 AM
> The always pass `RTC_FORMAT_BIN` when setting a alarm.
I can see that, but the call to HAL_RTC_GetTime (where you should pass RTC_FORMAT_BIN too) was not pasted, I guess it's in your ALARM_GetCalendarTime function.
> can be any whole number from 1-23.
The comment is saying "Set Alarm after (x + 1) hours", so I guess in the current case it's always 1?
2019-05-16 07:40 AM
> I can see that, but the call to HAL_RTC_GetTime (where you should pass RTC_FORMAT_BIN too) was not pasted, I guess it's in your ALARM_GetCalendarTime function.
Yes, it does exactly that. Calls HAL_RTC_GetTime() with RTC_FORMAT_BIN
> The comment is saying "Set Alarm after (x + 1) hours", so I guess in the current case it's always 1?
That is correct, in the following case/example it is 1 hour. But it has been coded to take in changing hour values.
2019-05-16 08:53 AM
Hm... I was sure, that was the case. Ok, the way you set hours is fine. It should be something else.
What I see now is that you set "sAlarm.DateWeekDay" to an invalid value (it must be between 1 and 31). Probably it somehow affects the alarm, I can't check it right now, maybe will do it later. Try to set the field to a valid number.
2019-05-16 09:03 AM
That is exactly what I did next. I realized it was an invalid value. So I set "sAlarm.DateWeekDay" to 1. Since I already have the mask set to ignore weekday_date, it should not matter anyway. But I can confirm that it does not change the situation.
Appreciate the quick response :)
2019-05-16 01:10 PM
My answer was deleted? even trying to help someone nowadays looks a crime..
2019-05-16 01:26 PM
I can still see your answer.
2019-05-16 10:36 PM
@Soham Jani Can you write here your current version of HourlyAlarmRoutine? And also what version of stm32f4xx_hal_rtc.c (it can be found at the begining of the file) are you using?