Skip to main content
ROBERTO ARRIBAS
Associate II
May 11, 2018
Question

STM32F4 RTC gets bad format values

  • May 11, 2018
  • 1 reply
  • 1407 views
Posted on May 11, 2018 at 11:16

Hi, I'm working with the RTC (LSE source) and I'm getting a bad format value, not a wrong value.

I call HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN); and HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN); to get the actual date and time, and when I represent it, it shows: 'Thu 10/05/2018 36:08:13.219', when it really has to be 'Fri 11/05/2018 12:08:13.219'. The date and time would be fine if it had subtracted 24 hours in time and the day had been increased.

I've debugged HAL_RTC_GetTime and when it reads the TR register, it gets the following:

/* Get the TR register */

tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK);

// tmpreg = 3541011 = 0x360813;

Any ideas of what may be happening?

Thanks in advance

    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    May 11, 2018
    Posted on May 11, 2018 at 12:01

    Seem to remember others complaining of HR > 24 in recent weeks, might want to scan the threads for related issues.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    ROBERTO ARRIBAS
    Associate II
    May 11, 2018
    Posted on May 11, 2018 at 12:46

    I think I've found the solution reading other threads

    https://community.st.com/0D50X00009XkWhySAF

    First, when setting date and time, both structures must be completely initialized. I've noticed that not setting e.g. Subseconds in time structure, it had a non-zerolarge value. So, to set all parameters is required.

    And second, before setting time and date (in that order), HAL_RTC_Init() must be called. STM32CubeMX writes in MX_RTC_Init() the line

    if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2){

    before executing the HAL_RTC_Init(). That way, if it is not the first boot time, HAL_RTC_Init() is not executed.

    Thanks for your support.

    waclawek.jan
    Super User
    May 11, 2018
    Posted on May 11, 2018 at 13:20

    First, when setting date and time, both structures must be completely initialized.

    This applies to EVERY structure used in all ST 'libraries' (SPL and Cube/HAL and Cube/LL). Often, there are functions which are intended to do this.

    JW