cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f103 RTC Write Protection

PeterKurt
Associate
Posted on December 12, 2015 at 14:38

Hello,

i try to get my program work, but im unable to modify the rtc registers. I know that there is a Write Protection, which you can unable by polling the RTOFF Bit and then set the CNF Bit. It doesnt work. I used the CubeMX Code, than my STM std. Lib and than i try it manually by the Debugger, there were no change in the registers. The seconds of the rtc run correct. Cube MX


RTC_TimeTypeDef sTime;

RTC_DateTypeDef DateToUpdate;

RTC_AlarmTypeDef sAlarm;


/**Initialize RTC and set the Time and Date 

*/

hrtc.Instance = RTC;

hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;

hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM;

hrtc.DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;

hrtc.DateToUpdate.Month = RTC_MONTH_JANUARY;

hrtc.DateToUpdate.Date = 1;

hrtc.DateToUpdate.Year = 0;

HAL_RTC_Init(&hrtc);


sTime.Hours = 0;

sTime.Minutes = 0;

sTime.Seconds = 0;

HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BIN);


HAL_RTC_SetDate(&hrtc, &DateToUpdate, FORMAT_BIN);


/**Enable the Alarm A 

*/

sAlarm.AlarmTime.Hours = 1;

sAlarm.AlarmTime.Minutes = 2;

sAlarm.AlarmTime.Seconds = 3;

sAlarm.Alarm = RTC_ALARM_A;

HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN);

My onwn code: set_alarm


while
((RTC->CRL & RTC_FLAG_RSF) == 0) 
// wait for last task

{} 


RTC->CRL |= RTC_CRL_CNF; 
//enter configuration mode


RTC->ALRH = data>>16;

RTC->ALRL = data; 


RTC->CRL &= ~RTC_CRL_CNF; 
//exit configuration mode


while
((RTC->CRL & RTC_FLAG_RTOFF) == 0) 
// wait for last task

{} 

the status after MX_RTC_Init() CRH 0x02 CHL 0x38 PRLH 0x00 PRLL 0x00 DIVH 0x00 DIVL 0x7A28 CNTH 0x00 CNTL 0x00 ALRH 0x00 ALRL 0x00
0 REPLIES 0