cancel
Showing results for 
Search instead for 
Did you mean: 

Using RTC Alarm as a 4 hour timer. Getting the current time using HAL RTC API, adding 4 to the current hours value and setting the alarm for that time by keeping the minutes as the current time. The Alarm interrupt is late by 2-3 minutes. Why?

MY.2
Associate

The STM32F030CCT6 is put to Stop mode. It wakes up on getting the RTC ALARM interrupt which is being used as a 4 hour timer. (The wakeup timer of RTC is being used for another purpose hence this work around).

On getting the interrupt, the MCU calculates the time for which the next alarm should be set and enables the alarm. Then goes to stop mode. This happens every 4 hours.

When the alarm interrupt is received, the current RTC time (hours and minutes) is being logged. As per this time, the ALARM interrupt hits without any accuracy issues.

As per the log timestamps (log taken using tera term) there is a delay of 2-3 minutes whenever the ALARM interrupt hits every 4 hours.

I want to understand why this delay occurs in real time but I don't see any issue in the RTC time.

I set the RTC time to Hours: 9 , Minutes: 0, Seconds: 0 during RTC initialization.

Please let me know if any further information is required to help me understand this accuracy issue.

2 REPLIES 2
RLind.3
Associate III

What oscillator are you using to drive your RTC? The internal (LSI, MSI, HSI) oscillators tend to be less accurate than external (LSE, HSE) ones. This could cause the issue you are seeing - the RTC is working correctly, but its timing is slightly out due to the oscillator. I believe you can calibrate the LSI against the HSI to increase its accuracy: https://stackoverflow.com/questions/57273229/stm32f072-lsi-calibration. If possible, I would recommend using a high accuracy LSE oscillator for driving your RTC - it will give you the best long term accuracy.

I am using the LSI oscillator to drive RTC. Thank you for your response. I will look into calibrating the LSI against the HSI. I don't have any external oscillators.

Thanks a lot for speedy response!