cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L071-RTC-SETTING

jz KN
Associate II
Posted on March 22, 2018 at 09:31

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.

0690X0000060A9mQAE.png

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

#hour #rtc #stm32l0
1 ACCEPTED SOLUTION

Accepted Solutions
jz KN
Associate II
Posted on March 26, 2018 at 08:19

I have get the point to solve this problem. I have forgotten to set the params '

DayLightSaving

' and'

StoreOperation

' when I set the time using HAL_RTC_SetTime(&hrtc,&tmp2,RTC_FORMAT_BIN); So everything goes ok after I set these two paras when I set hours-minites-seconds.

View solution in original post

1 REPLY 1
jz KN
Associate II
Posted on March 26, 2018 at 08:19

I have get the point to solve this problem. I have forgotten to set the params '

DayLightSaving

' and'

StoreOperation

' when I set the time using HAL_RTC_SetTime(&hrtc,&tmp2,RTC_FORMAT_BIN); So everything goes ok after I set these two paras when I set hours-minites-seconds.