2025-01-03 03:36 AM - edited 2025-01-04 03:41 AM
Today, for the first time I tried to set up RTC alarm using STM32U5G9 MCU. I need RTC alarm (IRQ) to fire on every second change, that is, when subsecond counter is zero - it is configured to count 32kHz clock pulses from 32k to 0 using 15-bit subsecond register which should zero exactly every one full second.
Probably what needs to be done is this: 1. alarm needs to enabled, 2. subsecond SS mask needs to be set to 14:0 (all 15 bits are compared), 3. RTC IRQ needs to be enabled, 4. within ISR alarm has to be reset (RTC_SCR_CALRAF) or auto-clear (RTC_CR_ALRAFCLR) flag needs to be set in advance (sAlarm.FlagAutoClr = ALARM_FLAG_AUTOCLR_ENABLE).
The above does not work, RTC IRQ does not fire even once. RTC date/time works OK so it is not a clock issue.
Please advice. What am I missing?
I am familiar with ST Wiki publication on this subject here but it did not work, I was unable to fire RTC IRQ even once. In any case, I think the described approach is very unreliable - what if RTC IRS gets interrupted by another high-priority IRS executing for more than a second before new alarm is set?
Solved! Go to Solution.
2025-01-03 05:35 AM - edited 2025-01-03 08:06 AM
@TDK I am showing that such config would cause a match on the 1st second of every minute (not on every second), effectively triggering alarm every minute e.g. at 12:00:01, 12:01:01, 12:02:01 and so on.
But you got me thinking again. What I was missing the most was masks! Hours, Minutes, Seconds and Date have to be masked out. Otherwise, they will be used in addition to subseconds causing alarm to fire only on the 1st day of every month at 00:00:00. Here is corrected, working config:
2025-01-03 04:31 AM
You didn't modify the seconds as indicated in the link.
If you want it to fire every second, without modifying anything, mask seconds, minutes, hours, etc so it fires when the subseconds match regardless of anything else.
2025-01-03 05:35 AM - edited 2025-01-03 08:06 AM
@TDK I am showing that such config would cause a match on the 1st second of every minute (not on every second), effectively triggering alarm every minute e.g. at 12:00:01, 12:01:01, 12:02:01 and so on.
But you got me thinking again. What I was missing the most was masks! Hours, Minutes, Seconds and Date have to be masked out. Otherwise, they will be used in addition to subseconds causing alarm to fire only on the 1st day of every month at 00:00:00. Here is corrected, working config: