cancel
Showing results for 
Search instead for 
Did you mean: 

How to fire RTC alarm every 1s?

TDJ
Lead

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?

TDJ_3-1735904047337.png

 

TDJ_1-1735902305185.png

 

TDJ_2-1735902389946.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDJ
Lead

@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:

TDJ_0-1735911205172.png

 

 

View solution in original post

2 REPLIES 2
TDK
Guru

You didn't modify the seconds as indicated in the link.

TDK_0-1735907432723.png

 

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.

If you feel a post has answered your question, please click "Accept as Solution".
TDJ
Lead

@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:

TDJ_0-1735911205172.png