Skip to main content
stenasc
Associate III
June 10, 2014
Question

Setting time and date on STM32F103

  • June 10, 2014
  • 2 replies
  • 1065 views
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
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    June 10, 2014
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    John F.
    Associate III
    June 10, 2014
    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.