Skip to main content
GUIRAT.Youssef
Associate III
December 6, 2016
Question

When to use RTC_FORMAT_BIN and when to use RTC_FORMAT_BCD ?

  • December 6, 2016
  • 4 replies
  • 5138 views
Posted on December 06, 2016 at 11:44

Hi, 

I'am working on STM32L486RG MCU and I'am using RTC to get the real time value.

I know that ST provides 2 RTC format for the time : the RTC_FORMAT_BIN and RTC_FORMAT_BCD ( as defined in the HAL ). I know the difference between the 2 representations but I don't know exactly when it's useful to use the BCD format

and when to use the Binary format ?

I kindly need your help .

Thanks.

    This topic has been closed for replies.

    4 replies

    ST Technical Moderator
    December 6, 2016
    Posted on December 06, 2016 at 17:03

    Dear

    GUIRAT.Youssef

    ‌,

    You can refer to this application note, it may help you:

    http://www.st.com/content/ccc/resource/technical/document/application_note/group0/71/b8/5f/6a/8e/d5/45/0a/DM00226326/files/DM00226pdf/jcr:content/translations/en.DM00226pdf

    Using the hardware real-time clock (RTC) in low-power modes withSTM32 microcontrollers.

    Best Regards

    -Imen-

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    Tesla DeLorean
    Guru
    December 6, 2016
    Posted on December 06, 2016 at 17:38

    The RTC natively uses BCD

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    GUIRAT.Youssef
    Associate III
    December 6, 2016
    Posted on December 06, 2016 at 17:50

    Thanks Clive , I've already checked this by referring to the reference manual.

    My question is in which case is suitable to use Binary format rather than BCD format ?

    Also, I've seen the RTC_TimeStamp example provided by ST and they use the BCD format to set

    both Date and Time then they use Binary format to get the Date and Time . Why to do so ? Cannot we 

    use the same format for setting then use it again for getting the time ?

    Tesla DeLorean
    Guru
    December 6, 2016
    Posted on December 06, 2016 at 18:36

    The digital logic is easier with the BCD data, if you plan on doing math on the numbers, ie advancing alarm settings it is easier to use binary and check overflows (>59) and daisy chain from seconds, minutes, hours, days, etc.

    If you plan on taking the data and printing it the BCD data can be processed efficiently with shifts and masks rather than the more expensive printf() itoa() type implementation.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..