cancel
Showing results for 
Search instead for 
Did you mean: 

When to use RTC_FORMAT_BIN and when to use RTC_FORMAT_BCD ?

GUIRAT.Youssef
Associate III
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.

4 REPLIES 4
Imen.D
ST Employee
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-

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on December 06, 2016 at 17:38

The RTC natively uses BCD

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
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 ?

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
Up vote any posts that you find helpful, it shows what's working..