Subseconds (RTC_SSR) are often misunderstood because they don't count up but count down:
"The ck_apre clock is used to clock the binary RTC_SSR subseconds downcounter. When it reaches 0, RTC_SSR is reloaded with the content of PREDIV_S."
With a clock of 32768Hz, PREDIV_S (the 15bit synchronous predivider) is normally set to 256-1. Due to the downcounter you have to think the other way around in order to program a time difference for a future interrupt, i.e. subtracting it from the current value and correct the underflow, like e.g.:
// for 32kHz, PREDIVS=255 --> e.g. 80/256*1s=312.5ms
uint32_t subseconds_diff = 80; // example
// threatens underflow?
if (subsecond < subseconds_diff)
{
// yes, add PREDIV_S+1 first:
subsecond = subsecond+hrtc->Init.SynchPrediv+1-subseconds_diff;
next_second++;
}
else
{
subsecond -= subseconds_diff;
}
Please insert the following lines to get the next alarm:
// mask date and weekday as only hh:mm:ss:sss is of interest:
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
// use subseconds:
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
// alarm is not triggered if missing:
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.Alarm = RTC_ALARM_A;
BTW: please use the Code Snippet button </> to insert source code.
When your question is answered, please close this topic by choosing Select as Best.
/Peter