RTC ALARM A Stops working after Mid-Night
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
- Labels:
-
RTC
-
STM32L1 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-06 08:11 AM
Probably
sAlarm.AlarmDateWeekDay = 0;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
selects Alarms only on sundays only . Get FreRtos to ignore days for alarm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-06 08:13 AM
sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; ??
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-06 08:30 AM
The "sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;" should ideally ignore anything in the "AlarmDateWeekDay" field. Regardless of weather it is set for weekdays or date. And I have tested it with different dates to, it works.
Thanks for the reply !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-06 08:32 AM
The documentation does not say much about it. I picked it up from one of the examples.
There are only 2 options for it : "RTC_HOURFORMAT12_AM" & "RTC_HOURFORMAT12_PM". Using either of them does not change anything.
Do you know what they are for ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-16 05:58 AM
Let me guess - in your RTC init function there is this line:
hrtc.Init.HourFormat = RTC_HOURFORMAT_12;
The "sAlarm.AlarmTime.TimeFormat" field is needed if you've previously chosen 12 hour format for RTC. Otherwise it is ignored.
The field "sAlarm.AlarmTime.TimeFormat" indicates whether the value that you write to "sAlarm.AlarmTime.Hours" is AM or PM (by the way the hour value must be less or equal to 12).
So if you don't change the "TimeFormat" for your alarm after midnight, you would get your interrupts only half of the day.
P.S.
There is an easier way to have an interrupt once every our - just mask everything except seconds, minutes and subseconds:
sAlarm.AlarmMask = (RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS) ;
sAlarm.AlarmTime.Seconds = 0;
sAlarm.AlarmTime.Minutes = 0;
sAlarm.AlarmTime.SubSeconds = 0;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
ALARM_ActivateAlarm(&sAlarm);
This way you get an interrupt each time an hour has changed in RTC (regardles of what time format did you use).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-16 06:44 AM
hello tarasov.alex.m,
thank you for the response. Your answer makes a lot of sense.
But I have already initialized the rtc in 24 hour format like you mentioned.
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
The problem still persists. :(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-16 07:00 AM
Are you sure this is correct?
sAlarm.AlarmTime.Hours = ( sTime.Hours + uBackupCheckingHours ) % 24;
I think it should be 12 if you are using following.
sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
well, that is what I read
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-16 07:05 AM
From one of the above answers, I think it will ignore "sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM" as the rtc time format is set to 24 hours.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-16 07:09 AM
Are you sure the RTC is not configured in BCD format? And what is the value of uBackupCheckingHours?