2022-03-26 12:57 PM
MX_RTC_Init();
if (HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DRX) != 0X2233) {
printf(" Set Date and Time \r\n");
SetDateTime();
}
void SetDateTime(void) {
RTC_TimeTypeDef sTime = { 0 };
RTC_DateTypeDef sDate = { 0 };
/* USER CODE BEGIN Check_RTC_BKUP */
/* USER CODE END Check_RTC_BKUP */
/** Initialize RTC and set the Time and Date*/
sTime.Hours = 0x19;
sTime.Minutes = 0x45;
sTime.Seconds = 0x30;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) {
Error_Handler();
}
sDate.WeekDay = RTC_WEEKDAY_FRIDAY;
sDate.Month = RTC_MONTH_MARCH;
sDate.Date = 0x25;
sDate.Year = 0x22;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK) {
Error_Handler();
}
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DRX, RTC_BKP_DATA);
}
Solved! Go to Solution.
2022-03-26 02:40 PM
Then your LSE oscillator is probably not stable.
Read AN2867. Try on a "known good" board like Nucleo or Disco. Experiment with LSE drive level.
JW
2022-03-26 01:44 PM
There is no question, but I'll try to guess: LSI is not in battery-backup domain, so it stops working when VDD is removed.
LSI is also very imprecise, see datasheet.
JW
2022-03-26 02:08 PM
Thank you for the answer indeed I have a problem with the time display, it freezes as soon as I remove the power supply.
I started to test with LSE I have the same problem and also the fact that the display of seconds is not very stable (periodic)
2022-03-26 02:40 PM
Then your LSE oscillator is probably not stable.
Read AN2867. Try on a "known good" board like Nucleo or Disco. Experiment with LSE drive level.
JW
2022-03-26 02:52 PM
Thanks for your help
2022-03-26 03:19 PM
The problem is solved, it works very well, the problem comes from a fault in the oscillator at the level of the PC14-OSC32_IN and PC15-OSC32_OUT pins.
Thank you waclawek.jan for your orientation