AnsweredAssumed Answered

STM32F4Discovery : Using HSE clock source for RTC.

Question asked by marc on Mar 31, 2014
Latest reply on Apr 1, 2014 by Clive One
Dear community,

Knowing that the RTC manual stated that the LSI is not suitable for the RTC, I am trying to use the HSE clock source for the RTC.

I initialized the clock and RTC but the i was unable to read the time. Can you please help?

I initialized the clock as follows:

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  RCC_HSEConfig( RCC_HSE_ON );
  while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET)  {}
  RTC_InitStructure.RTC_AsynchPrediv = 0x7C;
  RTC_InitStructure.RTC_SynchPrediv  = 0x1F3F;
  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
  RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
  RTC_TimeStructure.RTC_Hours   = 1;
  RTC_TimeStructure.RTC_Minutes = 0;
  RTC_TimeStructure.RTC_Seconds = 0;
  RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);

In order to read the clock i am using the following:

        RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure);
        uwMin = RTC_TimeStructure.RTC_Minutes;
        uwSecond = RTC_TimeStructure.RTC_Seconds;
        uwSecond_h   = (((uint8_t)(RTC_TimeStructure.RTC_Seconds & 0xF0) >> 0x04)+ 0x30);
        uwSecond_l   = (((uint8_t)(RTC_TimeStructure.RTC_Seconds & 0x0F)) + 0x30);
        uwSecondfraction = 1000 - ((uint32_t)((uint32_t)RTC_GetSubSecond() * 1000) / (uint32_t)0x3FF);

Unfortunately all the variables (uwMin, uwSecond, uwSecond_h, uwSecond_l, uwSecondfraction) has 0 as value.

Thank you in advance for the help.

Best regards,