cancel
Showing results for 
Search instead for 
Did you mean: 

Questions on how RTC clock usage STM32F103

Dioswilson
Associate II

I am planing to have a time functionality on a project I want to make.

After reading the manual I undestood I have a 32 bit counter which increases with TR_CLK.
Let's say I want to update the clock every 1ms, that would leave me with aproximately 49.5 days of clock, which is not enough.
Did I understood correctly? Is this how it should be used?

What should I do to save more time? Should I manually save time into flash or smth?

I've seen some "Calendar" functionality on CubeMX so I guess something is possible (I'd like to stay out of HAL functions)

Thanks in advance, best regards.

2 REPLIES 2

Normally, RTC is clocked from a 32.768kHz crystal and you program the prescaler so, that TR_CLK increments the counter itself once in a second, that gives you some 136 years of time.

The 32.768kHz input frequency cannot be prescaled to 1kHz. You can use HSE/128 as input to RTC, but that can't run under VBAT alone.

JW

Techn
Senior III

What you can do is to update some variables called day,month, year etc.. During a trigger say every second or some other interval, you can check the counter, if the counter crossed 24 hrs, update the day counter and write that into the battery backed up RAM of the  RTC. While you do the next reboot, update your RAM variable also from RTC RAM. This way you can always get the correct counter up to any value. If you do a proper shutdown before switching of the power, the data stored in the RAM will be accurate and you need to write to the RTC RAM only once. Choice is yours.

This is the standard practice when the variable range is not within your desired. this way you can get 32bit X32 bit variable. I guess that is good enough.

you can take the logic from stm32f1xx_halxx ... rtc.c and do the bare metal equivalent by referring to RM for your chip.

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