cancel
Showing results for 
Search instead for 
Did you mean: 

Why Cubemx use 0x32F2 as an indicator for the RTC configuration?

ali rostami
Associate III
Posted on September 11, 2017 at 07:58

I've created a program with activated RTC peripheral by cubemx. After analyzing the code and searching in the internet, I found out that the reason of writing 0x32F2 in RTC_BKP_DR1 is for checking weather the RTC was configured before or not. but here is my question that why it uses 0x32F2 as an indicator and not another number? Is there any reason?

static void MX_RTC_Init(void)

{

RTC_TimeTypeDef sTime;

RTC_DateTypeDef DateToUpdate;

/**Initialize RTC Only

*/

hrtc.Instance = RTC;

hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;

hrtc.Init.OutPut = RTC_OUTPUTSOURCE_CALIBCLOCK;

if (HAL_RTC_Init(&hrtc) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Initialize RTC and set the Time and Date

*/

if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) != 0x32F2){

sTime.Hours = 1;

sTime.Minutes = 0;

sTime.Seconds = 0;

if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;

DateToUpdate.Month = RTC_MONTH_JANUARY;

DateToUpdate.Date = 1;

DateToUpdate.Year = 15;

if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR1,0x32F2);

}

}

#rtc_bkp_dr1 #rtc
0 REPLIES 0