cancel
Showing results for 
Search instead for 
Did you mean: 

Setting time and date on STM32F103

stenasc
Senior
Posted on June 10, 2014 at 10:14

Hi,

I'm porting code from a M0 to an M3 part and libraries are quire a bit different.

I need a quick tutorial on initializing the RTC and setting  time and date using the stm32f103 part. I've already obtained the date and time. I just need to adjust the RTC to hold these values.  Also, what function do I call to check the updated time and date once set? A code snippet would be great.

Thank you

Bob
2 REPLIES 2
Posted on June 10, 2014 at 13:39

As I recall, the F1 uses a Seconds-since-Epoch model, like UNIX Time, so you have to write routines to translate back and forth to calender centric representations

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
John F.
Senior
Posted on June 10, 2014 at 14:46

In C you can store UTC time as a 32 bit uint (time_t (in the RTC registers)) or store calendar time as as (tm) type. Ignoring conversions for locale, use mktime() to convert from tm to time_t or use gmtime() to convert UTC time to a tm time struct.