Author Topic: STM32L0 RTC doesn't increment.  (Read 1568 times)

0 Members and 1 Guest are viewing this topic.

Online BoscoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 276
STM32L0 RTC doesn't increment.
« on: August 15, 2018, 05:32:58 pm »
Hi all,

I wonder if someone could shed some light on this and help me out maybe.

I've setup the RTC in Cube with a wakeup from sleep mode. This wakeup does work at the 5 second interval that I have set so the RTC is running.

The problem I have is when I read the time. I read the time then the date as just reading the time freezes the result. The values I read never change from 0:32:0, it doesn't matter what I initialise the time or date to. Does anyone know what I could be doing wrong?

Thanks

When I get the time:
Code: [Select]
void RTCGetTime(RTC_TimeTypeDef * sTime, RTC_DateTypeDef * sDate)
{
// Get the time and date
HAL_RTC_GetTime(&hrtc, sTime, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, sDate, RTC_FORMAT_BIN);
}

And the init:
Code: [Select]
void MX_RTC_Init(void)
{
  RTC_TimeTypeDef sTime;
  RTC_DateTypeDef sDate;

    /**Initialize RTC Only
    */
  hrtc.Instance = RTC;
  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  hrtc.Init.AsynchPrediv = 127;
  hrtc.Init.SynchPrediv = 255;
  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  if (HAL_RTC_Init(&hrtc) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Initialize RTC and set the Time and Date
    */
  if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2){
  sTime.Hours = 0x0;
  sTime.Minutes = 0x30;
  sTime.Seconds = 0x0;
  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  sDate.WeekDay = RTC_WEEKDAY_MONDAY;
  sDate.Month = RTC_MONTH_JANUARY;
  sDate.Date = 0x1;
  sDate.Year = 0x0;

  if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR0,0x32F2);
  }
    /**Enable the WakeUp
    */
  if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 5, RTC_WAKEUPCLOCK_CK_SPRE_16BITS) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

}
« Last Edit: August 15, 2018, 05:36:47 pm by Boscoe »
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3237
  • Country: gb
Re: STM32L0 RTC doesn't increment.
« Reply #1 on: August 15, 2018, 05:56:15 pm »
Seems to be a known problem.  According to that link ST know about it and say it's a "feature" that you must always read date after time.
 

Online BoscoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 276
Re: STM32L0 RTC doesn't increment.
« Reply #2 on: August 15, 2018, 07:36:22 pm »
Seems to be a known problem.  According to that link ST know about it and say it's a "feature" that you must always read date after time.

Thanks, bit I did. But still doesn't work.

I ended up just making my own driver in the end.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf