AnsweredAssumed Answered

STM32L071-RTC-SETTING

Question asked by jz KN on Mar 22, 2018
Latest reply on Mar 26, 2018 by jz KN

hi all,

   I'm using a board with one stm32l071.I have get code by stm32cubemx,and then I added my code on that.

But now I have a issue with RTC,after I set the RTC registers, the hour in the register is less than my setting.For eg, I set 15:30:00 to the RTC registers, but I will get 14:30:00 after my setting code.

This will occur when I debug in keil simulation using full speed running,but when I debug step by step,this will not occur!

Thanks for your help if you know how to solve the problem.

my code:

void Time_SetCalendarTime(struct tm t)
{
RTC_TimeTypeDef tmp2;
RTC_DateTypeDef dt;
HAL_StatusTypeDef ret;


dt.Year=t.tm_year-RTC_START_YEAR;/*start from 2018*/
dt.Month=t.tm_mon+1;
dt.Date=t.tm_mday;
dt.WeekDay=0;/*disable weekday*/

tmp2.Hours=t.tm_hour;
tmp2.Minutes=t.tm_min;
tmp2.Seconds=t.tm_sec;

ret = HAL_RTC_SetDate(&hrtc,&dt,RTC_FORMAT_BIN);
printf("set date..<%d>(0-OK,1-ERR,2-BUSY,3-TIMEOUT)\r\n",ret);
ret = HAL_RTC_SetTime(&hrtc,&tmp2,RTC_FORMAT_BIN);
printf("set time..<%d>(0-OK,1-ERR,2-BUSY,3-TIMEOUT)\r\n",ret);
return;
}

log:


 

2018-3-22   16:30:18
set date..<0>(0-OK,1-ERR,2-BUSY,3-TIMEOUT)
set time..<0>(0-OK,1-ERR,2-BUSY,3-TIMEOUT)
set date..<0>(0-OK,1-ERR,2-BUSY,3-TIMEOUT)
set time..<0>(0-OK,1-ERR,2-BUSY,3-TIMEOUT)
2018-3-22   15:30:18
AT update time suc!
2018-3-22   15:30:18
2018-3-22   15:30:19
2018-3-22   15:30:20
2018-3-22   15:30:21
2018-3-22   15:30:22

Outcomes