cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, is there a problem with the HAL_RTC_SetDate function? If i set the year to 18, and read it back its never correct, always a year infront

aldridge.nicholas
Associate

RTC_TimeTypeDef sTime;

RTC_DateTypeDef sDate;

sTime.TimeFormat = RTC_HOURFORMAT_24;

sTime.Hours = 12;

sTime.Minutes = 12;

sTime.Seconds=34;

sDate.Date=8;

sDate.Month=12;

sDate.Year=20;

HAL_RTC_SetTime(&RtcHandle, &sTime, RTC_FORMAT_BIN);

HAL_RTC_SetDate(&RtcHandle, &sDate, RTC_FORMAT_BIN);

HAL_Delay(5000);

HAL_RTC_GetTime(&RtcHandle, &sTime, RTC_FORMAT_BIN);

HAL_RTC_GetDate(&RtcHandle, &sDate, RTC_FORMAT_BIN);

printf("Time %02d:%02d:%02d\r\n",sTime.Hours,sTime.Minutes,sTime.Seconds);

printf("Date: %02d/%02d/%04d\r\n",sDate.Date,sDate.Month,sDate.Year+2000);

Time 12:12:38

Date: 08/12/2021

2 REPLIES 2

Read out and post the content of RTC_DR register.

Which Cube/HAL?

JW

rbenv.3
Associate II

Hi, I had this same problem.

Set the field sDate.WeekDay before calling HAL_RTC_SetDAte.

Ronald Benvenutti