cancel
Showing results for 
Search instead for 
Did you mean: 

Setting RTC Alarm For A Specific Period From Now

ISeed
Senior

Hello,

I would like to set an RTC alarm to wake the system, let's say, 5 seconds from current time.

The example applications show how to set an alarm for a specific date+time in the future, but I want to set it for X milliseconds from current time.

One way would be to get the current timestamp in milliseconds and add X to it, convert it to date+time and set RTC alarm to it.

Another way would be if there is some RTC date+time algebra support, where I can just take a date+time and add milliseconds to it.

I have no idea how to do either.

Can you please advice me on how to solve this?

Thanks!

4 REPLIES 4

for STM32F10x is very simple to do this by setting the alarm reg to sum of the desired value in seconds and RTC counter.

For the other families, converting time_date to seconds , add desired value and convert it back to date_time can be done by using C lib time functions (#include <time.h>.

Consider use "RTC periodic wakeup unit" with settable values from a tenth of millisecond to 36 hours. You can find a lot of details here.

Well, seems like I'm in luck. STM32F100RBT was chosen, which, from my understanding, fall under STM32F10x .

Could you recommend example project that demonstrate this?

JAN R
Associate III

I use RTC ALARM A on my STM32L152. When I need wakeup in 5 second from current time I just read the actual time then I add 5 second to it and then new time I set to ALARM reg. It works reliably.

How do you add 5 seconds? Is there a function to add X seconds to a time struct, or you have your own module that changes the entire struct according to added delta? (that is, if current time is 1999:12:31:23:59:59, and you want to add 5 seconds, you make it into 2000:01:01:00:00:04)?