cancel
Showing results for 
Search instead for 
Did you mean: 

HAL RTC

Sandeep Dhokne
Associate II
Posted on October 09, 2017 at 13:52

@

Hi,

I did my project in cubemx  with STM32F405.

But unfortunately i forgot to add/initialize rtc in cubemx.

Now i want to add rtc in my project.

And i don't know how to add it (because my code size is too much heavy and i dont want to do rework in cubemx).

Can you please tell me how can i do this without cubemx?   

Thank you.

#

15 REPLIES 15
Sandeep Dhokne
Associate II
Posted on October 16, 2017 at 12:14

RTC starts working.

when i compared stm32f405 rtc time with my dell laptop rtc then  i observed on an average for a every 1 min 3 seconds are added extra.

(for 20 min. 1 min. added extra!!)

stm32f405 rtc time is moves faster than server time.

how can i control this?

Thank you.

Posted on October 16, 2017 at 11:22

Thank you.

Posted on October 16, 2017 at 12:22

use a 32k external oscillator/crystal for LSE to drive the RTC

Sandeep Dhokne
Associate II
Posted on October 17, 2017 at 13:31

I'm already using 32.768kHz crystal for same.

Till this problem is observed. 

Sandeep Dhokne
Associate II
Posted on October 29, 2017 at 08:16

Hello,

Now i'm using 3V battery supp;ly for RTC when there no power supply.

But when i switch off power supply rtc stuck at that time.

When i switch on power rtc time start from that stuck time.

As per protocol rtc should work on battery and also update date and time.

Point-1:Power ON with Battery

Time:11:40:20 Date:29/10/2017

Point-2:

After Switching off power supply for 10 min.

Date and Time should be 

Time:11:50:20 Date:29/10/2017

but it is same as Time:11:40:20 Date:29/10/2017

please help.

My RTC Initialization code is:-

void MX_RTC_Init(void)

{

unsigned int Status;

Status = 1;

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.OutPut = RTC_OUTPUT_WAKEUP;

hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

sTime.Hours = 0x10;

sTime.Minutes = 0x10;

sTime.Seconds = 0x10;

sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

sTime.StoreOperation = RTC_STOREOPERATION_SET;

sDate.WeekDay = RTC_WEEKDAY_MONDAY;

sDate.Month = 0x08;

sDate.Date = 0x15;

sDate.Year = 0x47;

Status = HAL_RTC_Init(&hrtc);

while(Status != HAL_OK)

{

Status = HAL_RTC_Init(&hrtc);

}

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

sTime.Hours = 0x10;

sTime.Minutes = 0x10;

sTime.Seconds = 0x10;

sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

sTime.StoreOperation = RTC_STOREOPERATION_SET;

Status = 1;

Status = HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);

while(Status != HAL_OK)

{

Status = HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);

}

sDate.WeekDay = RTC_WEEKDAY_MONDAY;

sDate.Month = 0x08;

sDate.Date = 0x15;

sDate.Year = 0x47;

Status = 1;

Status = HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD);

while(Status != HAL_OK)

{

Status = HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD);

}

HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR0,0x32F2);

}

/**Enable Calibrartion*/

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

{

_Error_Handler(__FILE__, __LINE__);

}

}
Posted on October 29, 2017 at 11:14

Are you sure your RTC's clock is LSE and not LSI?

Read out and post content of RCC_BDCR.

JW