op0707-305712 发表于 2016-2-22 11:13:33

STM32F103 HAL库 RTC,掉电后日期显示2000-00-00,时间显示正常

如题,是否有其他朋友遇到类似问题。
我分析hal库,发现在“HAL_RTC_SetDate”函数中,有怎么一条判断,才导致无法写入日期:
/* Reset time to be aligned on the same day */
/* Read the time counter*/
counter_time = RTC_ReadTimeCounter(hrtc);

/* Fill the structure fields with the read parameters */
hours = counter_time / 3600;
if (hours > 24)
{
    /* Set updated time in decreasing counter by number of days elapsed */
    counter_time -= ((hours / 24) * 24 * 3600);
    /* Write time counter in RTC registers */
    if (RTC_WriteTimeCounter(hrtc, counter_time) != HAL_OK)
    {
      /* Set RTC state */
      hrtc->State = HAL_RTC_STATE_ERROR;

      /* Process Unlocked */
      __HAL_UNLOCK(hrtc);

      return HAL_ERROR;
    }

    /* Read current Alarm counter in RTC registers */
    counter_alarm = RTC_ReadAlarmCounter(hrtc);

    /* Set again alarm to match with new time if enabled */
    if (counter_alarm != RTC_ALARM_RESETVALUE)
    {
      if(counter_alarm < counter_time)
      {
      /* Add 1 day to alarm counter*/
      counter_alarm += (uint32_t)(24 * 3600);

      /* Write new Alarm counter in RTC registers */
      if (RTC_WriteAlarmCounter(hrtc, counter_alarm) != HAL_OK)
      {
          /* Set RTC state */
          hrtc->State = HAL_RTC_STATE_ERROR;

          /* Process Unlocked */
          __HAL_UNLOCK(hrtc);

          return HAL_ERROR;
      }
      }
    }
}

党国特派员 发表于 2016-2-23 11:10:37

没有研究过。。。

gujiao 发表于 2016-2-23 16:37:45

RTC日期需要备份在单片机复位后读出备份日期

奏奏奏 发表于 2016-11-5 21:28:12

我现在也遇到了这样的问题,开机后显示2000年01月01日

五哥1 发表于 2016-11-8 16:53:25

在CUBE里设置备份,调用

asssdz-382474 发表于 2016-11-8 19:15:36

:):):):):):):):):):)

alisa123 发表于 2016-11-29 10:02:44

楼主,请问你的问题有解决吗?可否分享下,谢谢!

peter001 发表于 2016-11-29 10:17:32

关注一下,看大神解答

nefusmzj 发表于 2017-6-12 21:05:36

你好,请问问题解决了么?可否说说怎么解决的?我现在遇到同样的问题了,正在探索中。:)

CloseRainOpenFl 发表于 2018-1-22 11:47:49

大家问题都解决了吗,能否分享一下
页: [1] 2
查看完整版本: STM32F103 HAL库 RTC,掉电后日期显示2000-00-00,时间显示正常