2022-03-10 06:35 PM
I have working code for an STM32L0 device that uses Alarm A of the RTC to wake / interrupt at the desired minute interval. I now require the ability to wake / interrupt at the desired hours AND minutes time. Previously all masks were masked except for the Alarm A minutes mask. Now all masks except for the Alarm A minutes AND hours masks are masked. I believe it should work as before only now the alarm needs to see a matching hours AND minutes value in order to cause the interrup. Is my understanding correct ? So, for example, if the current time is 0 hrs and 0 minutes and I set AlarmTime.Hours = 1 and AlarmTime.Minutes = 1 then I would expect a single interrupt 61 minutes from now.
2022-03-11 03:21 AM
Welcome, @Community member, to the community!
This is essentially a correct assumption, as the RTC works with alarm times in the same way as an alarm clock on the bedside table: a signal is given at a given time. In your case, the interrupt will be raised at 01:01am.
Regards
/Peter
2022-03-11 05:04 PM
Thank-you very much Peter.
The existing, known-working, code for minutes-based interrupts works as expected and basically follows the process:
i/ set masks: sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS|RTC_ALARMMASK_SECONDS;
ii/ set minutes: sAlarm.AlarmTime.Minutes = whatever
iii/ enable interrupt: if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
{ Error_Handler(); }
This scheme is only very slightly modified for the minutes + hours situation:
i/ set masks: sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_SECONDS;
ii/ set minutes: sAlarm.AlarmTime.Minutes = whatever
sAlarm.AlarmTime.Hours = whatever
iii/ enable interrupt: if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
{ Error_Handler(); }
In the existing minutes-based interrupt case an interrupt is generated after, say, 2 minutes if that is the desired interval setting - this is correct.
What seems to be happening in the minutes + hours case is that an interrupt is generated immediately rather than after 2 minutes - this is with sAlarm.AlarmTime.Hours = 0 and sAlarm.AlarmTime.Minutes = 2 and with a starting point of sTime.Hours = sTime.Minutes = 0. Any ideas ? Does it matter what order the AlarmMasks are set compared to the AlarmTimes ? I would guess not especially as the interrupt enabling happens afterwards ?
Thanks again.
2022-03-14 05:08 AM
Well, you are confusing the RTC functions Wake-Up (time difference) and Alarm (absolute time).
Please check in your application which start time you set at the power-on reset. If this is e.g. 03:00:00 and the alarm time is set to 2 minutes and masked for the minutes, the interrupt will be triggered at 03:02:00, so it looks like after 2 minutes, but then only after one hour, when the condition xx:02:xx applies again.
If, on the other hand, your start time is e.g. 03:50:00, the interrupt will only be triggered at 04:02:00, i.e. after 12 minutes, followed by the next one at 05:02:00, etc.
Details can be found in the reference manual of the family you are using, section Real-Time Clock (RTC), subsections Programmable Alarms and Periodic Auto-Wakeup.
Now, if you want to use the Wake-Up function, e.g. to wake up the system every 2 minutes, you only need to set the wake-up timer with either:
For the interrupt, you can put the action to be executed into the function
RTC_WKUP_IRQHandler().
Does it answer your question?
Regards
/Peter
2022-03-30 10:24 PM
hello Peter,
It's all working exactly as expected - there are no problems with the minutes+hours based interrupts (as expected).
The issue was something else unrelated to the fundamentals of RTC alarm minutes+hours interrupts (accessing the sAlarm structure in different source files even with one declared as extern seemed to be a problem).
Thank-you very much for your help, and apologies for not having provided you with an update sooner.
2022-03-31 01:10 AM
Great!
If the problem is resolved, please mark this topic as answered by selecting Select as best under your preferred answer. This will help other users find that answer faster.
/Peter