cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411 RTC 32768 cal Freq only 490Hz

erastusC
Associate III

I wonder if any one can help me.

The rtc Cal freq produced by the init code below produces on 490Hz.  The RTC clock is loosing about 55 sec in 20 minutes.

Is there a way to increase this freq without replacing the crystal?

 

static void MX_RTC_Init(void)

{

/* USER CODE BEGIN RTC_Init 0 */

/* USER CODE END RTC_Init 0 */

 

RTC_TimeTypeDef sTime = {0};

RTC_DateTypeDef sDate = {0};

/* USER CODE BEGIN RTC_Init 1 */

/* USER CODE END RTC_Init 1 */

/** Initialize RTC Only */

hrtc.Instance = RTC;

hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

hrtc.Init.AsynchPrediv = 127;

hrtc.Init.SynchPrediv = 255;

hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

if (HAL_RTC_Init(&hrtc) != HAL_OK)

{

Error_Handler();

}

 

/* USER CODE BEGIN Check_RTC_BKUP */

 

/* USER CODE END Check_RTC_BKUP */

 

/** Initialize RTC and set the Time and Date

*/

sTime.Hours = 18;

sTime.Minutes = 4;

sTime.Seconds = 11;

sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

sTime.StoreOperation = RTC_STOREOPERATION_RESET;

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

{

Error_Handler();

}

sDate.WeekDay = RTC_WEEKDAY_SATURDAY;

sDate.Month = RTC_MONTH_JANUARY;

sDate.Date = 24;

sDate.Year = 26;

 

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

{

Error_Handler();

}

 

/** Enable Calibrartion

*/

if (HAL_RTCEx_SetCalibrationOutPut(&hrtc, RTC_CALIBOUTPUT_512HZ) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN RTC_Init 2 */

 

/* USER CODE END RTC_Init 2 */

 

}

 

 

 

Thank you

3 REPLIES 3
mƎALLEm
ST Employee

Hello,

1- Please use </> button to share your code. Read How to write your question to maximize your chances to find a solution. I invite you to edit your post to be inline to this community rule.

2- This knowledge base article may help you: How to calibrate the STM32's real-time clock (RTC)

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
TDK
Super User

> Is there a way to increase this freq without replacing the crystal?

No, 55s in 20min is 5% off. That's 50000 ppm. That is way more than you can correct for in software. You'll have to fix whatever is wrong with the circuit.

If you feel a post has answered your question, please click "Accept as Solution".
Peter BENSCH
ST Employee

@erastusC 

You didn't specify which clock you are using to test the RTC. As @TDK said, your deviation is so large that it can't possibly have anything to do with a (real) 32768Hz crystal.

Let's do the math: if you multiply your 490Hz by the corresponding divisor of 64, you get 31360Hz. Then you look at the documentation of the STM32F411 (data sheet) and see that the free-running LSI has a frequency of min 17kHz, typ 32kHz and max 47kHz – do you notice anything?

Exactly – you clocked the RTC from the LSI and not from the LSE.

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.