cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F070F6 RTC Alarm is off by -15% when in Standby Mode

Mary Solomo
Associate II

Hello,

I'm using the RTC Alarm to wakeup the MCU every 10min and after 10PM, sleep for 10 hrs. However, I noticed that the RTC just actually sleeps for 8:25 min and when it wakes up, the RTC time says 10minutes have passed. To illustrate:

Current time is 12:00:00

Alarm set to 12:10:00... Enter standby mode.

.

.

<sleeps for 8 minutes and 25 seconds, checked using smartphone stopwatch>

.

.

Wake up and prints current time at 12:10 but in reality it's only 12:08:25. The RTC time is now off by 8:25 minutes like I said, and this will accumulate as I continue this loop.

I'm using the HAL_Library and LSI at 40 KHz for the RTC clock. Is this a limitation of the hardware? 15% drift is significant. If not, anything that I might have missed in the configuration?

I referred to the STM32F0 HAL examples and I'm not sure what I might have missed in the coding part.

/* Init */

void librtc_Init(void)

{

/**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(__FILE__, __LINE__);

 }

}

/*

 * Date Config

 */

void librtc_DateConfig(void)

{

 RTC_DateTypeDef sdatestructure;

 /*##-1- Configure the Date #################################################*/

 /* Set Date: Tuesday February 18th 2014 */

 sdatestructure.Year = 0x14;

 sdatestructure.Month = RTC_MONTH_FEBRUARY;

 sdatestructure.Date = 0x18;

 sdatestructure.WeekDay = RTC_WEEKDAY_TUESDAY;

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

 {

/* Initialization Error */

Error_Handler();

 }

}

/*

 * Time Config

 */

void librtc_TimeConfig(TimeStampFormat* Time)

{

 RTC_TimeTypeDef stimestructure;

 /*##-2- Configure the Time #################################################*/

 /* Set Time: 02:20:00 */

 stimestructure.Hours = Time->hours;

 stimestructure.Minutes = Time->minutes;

 stimestructure.Seconds = Time->seconds;

 stimestructure.TimeFormat = RTC_HOURFORMAT_24;

 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;

 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;

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

 {

/* Initialization Error */

Error_Handler();

 }

}

1 ACCEPTED SOLUTION

Accepted Solutions

You're using the prescalers for a 32.768 KHz source, not a 40 or 37 KHz one.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

You're using the prescalers for a 32.768 KHz source, not a 40 or 37 KHz one.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi Clive, this solved the issue. Thanks a lot!