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;
}
}
}
}
没有研究过。。。 RTC日期需要备份在单片机复位后读出备份日期 我现在也遇到了这样的问题,开机后显示2000年01月01日 在CUBE里设置备份,调用 :):):):):):):):):):) 楼主,请问你的问题有解决吗?可否分享下,谢谢! 关注一下,看大神解答 你好,请问问题解决了么?可否说说怎么解决的?我现在遇到同样的问题了,正在探索中。:) 大家问题都解决了吗,能否分享一下
页:
[1]
2