2017-06-12 04:36 PM
Hello.
I have a question about RTC BATTERY BACK UP.
I am using RTC.
And an external battery.
When the power is ON / OFF, the RTC TIME backup function works well.
However, RTC_DATE is not backed up.How to solve the problem please let me know.
Below is the battery schematic and c source.
static void MX_RTC_Init(void)
{RTC_TimeTypeDef sTime;
RTC_DateTypeDef DateToUpdate;/**Initialize RTC Only
*/ hrtc.Instance = RTC; hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND; hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM; 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_DR1) != 0x32F2){ sTime.Hours = 0x1; sTime.Minutes = 0x0; sTime.Seconds = 0x0;if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
{ _Error_Handler(__FILE__, __LINE__); }DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
DateToUpdate.Month = RTC_MONTH_JANUARY; DateToUpdate.Date = 0x6; DateToUpdate.Year = 0x17;if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK)
{ _Error_Handler(__FILE__, __LINE__); }HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR1,0x32F2);
}}
/* Private variables ---------------------------------------------------------*/
RTC_DateTypeDef Brams_RTC_Date;RTC_TimeTypeDef Brams_RTC_Time;void RTC_TimeShow(void)
{ HAL_RTC_GetTime(&hrtc, &Brams_RTC_Time, RTC_FORMAT_BIN); HAL_RTC_GetDate(&hrtc, &Brams_RTC_Date, RTC_FORMAT_BIN); printf(''\r\n- Date : 20%02d/%02d/%02d'',Brams_RTC_Date.Year, Brams_RTC_Date.Month, Brams_RTC_Date.Date); printf(''\r\n- Time : %02d:%02d:%02d '',Brams_RTC_Time.Hours, Brams_RTC_Time.Minutes, Brams_RTC_Time.Seconds);}