Abnormal reading after stm32f4 RTC time setting

RTC_GETTIME () and RTC_GETDATE () were ordered in different order, the time should be read first and then the date should be read, then OK!

void set_time(struct time_st *t) {
c_datetypedef date_value;
RTC_TimeTypeDef time_value;

te_value. RTC_Date = t->; D; .
date_value RTC_Month = t – & gt; M; .
date_value RTC_WeekDay = t – & gt; W; .
date_value RTC_Year = t – & gt; Y;
RTC_SetDate (RTC_Format_BIN, & amp; date_value);// set date

time_value. RTC_H12 = RTC_H12_AM; .
time_value RTC_Hours = t – & gt; h; .
time_value RTC_Minutes = t – & gt; m; .
time_value RTC_Seconds = t – & gt; s;
RTC_SetTime (RTC_Format_BIN, & amp; time_value); // Set time
}
Void get_time(struct time_st *t, struct time_st *t, struct time_st *t, struct time_st *t);
RTC_TimeTypeDef time_value;

RTC_GetTime (RTC_Format_BIN, & amp; time_value);
RTC_GetDate(RTC_Format_BIN,& date_value);

->; Y = date_value.RTC_Year;
t – & gt; M = date_value.RTC_Month;
t – & gt; D = date_value.RTC_Date;
t – & gt; W = date_value.RTC_WeekDay;

t – & gt; h = time_value.RTC_Hours;
t – & gt; m = time_value.RTC_Minutes;
t – & gt; s = time_value.RTC_Seconds;
}

Read More: