How to continue RTC when power is off

General discussion on mikroC PRO for ARM.
Post Reply
Author
Message
pensees
Posts: 15
Joined: 29 Sep 2020 05:45

How to continue RTC when power is off

#1 Post by pensees » 29 Dec 2020 09:14

RTC module is working fine when power is on.

But power changes to off, RTC value remained before power off.

I don't use external battery. Just use RTC battery and the battery is not discharged. (Coin cell battery)

I want to know how to use RTC battery when power is off. (I'm using STM32F407ZG)


Thanks.
Attachments
config.png
config.png (3.27 KiB) Viewed 1417 times

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: How to continue RTC when power is off

#2 Post by filip » 30 Dec 2020 15:21

Hi,

Did you connect the battery to the adequate pin - VBAT?

Regards,
Filip.

pensees
Posts: 15
Joined: 29 Sep 2020 05:45

Re: How to continue RTC when power is off

#3 Post by pensees » 04 Jan 2021 01:41

Hi,

I think my connection is right...
But, I want to confirm it.

Attach connection screenshot.

<Additional>
Where is VBAT pin??


Thanks.
Attachments
connection.jpg
connection.jpg (277.7 KiB) Viewed 1351 times

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: How to continue RTC when power is off

#4 Post by filip » 04 Jan 2021 16:35

Hi,

OK, you have a mikromedia board so everything is connected as it should.

Which RTC example did you try ?

Regards,
Filip.

pensees
Posts: 15
Joined: 29 Sep 2020 05:45

Re: How to continue RTC when power is off

#5 Post by pensees » 05 Jan 2021 01:40

I'm using "RTC for STM32F2xx/3xx/4xx" RTC library.


< In "driver.c" >

RTC_InitStruct rtcInit;
//RTC_DateTime timeRTC; // for once

...

void Init_MCU() {
rtcInit.RTC_HF = RTC_HourFormat_24;
rtcInit.RTC_AsynchPrediv = RTC_ASYNC_PREDIV;
rtcInit.RTC_SynchPrediv = RTC_SYNC_PREDIV;
RTC_Init(&rtcInit);

// set RTC once
// timeRTC.Year = 21;
// timeRTC.Month = 01;
// timeRTC.Date = 04;
// timeRTC.Hours = 13;
// timeRTC.Minutes = 30;
// timeRTC.Seconds = 30;
// timeRTC.AMPMSel = RTC_AMPMSel_AM;
// RTC_SetDateTime(&timeRTC);

...
}


< In events_code.c >

void event_handler() {
RTC_DateTime rtcDateTime;
RTC_GetDateTime(&rtcDateTime);

...
}


Thanks.
Attachments
RTC_library.png
RTC_library.png (17.71 KiB) Viewed 1322 times

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: How to continue RTC when power is off

#6 Post by filip » 05 Jan 2021 15:46

Hi,

Please have a look at the following links, you will see there how to properly set the RTC on STM32 :
https://libstock.mikroe.com/projects/vi ... ternal-rtc
viewtopic.php?f=178&t=50510
viewtopic.php?f=178&t=49563

Regards,
Filip.

pensees
Posts: 15
Joined: 29 Sep 2020 05:45

Re: How to continue RTC when power is off (solved)

#7 Post by pensees » 06 Jan 2021 03:04

Thanks for filip, I solved problem.

1) Using “REGISTER-NAMEbits.NAME-OF-BIT” instead of “REGISTER-NAME.NAME-OF-BIT”

2) Using LSE clock for RTC clock source (in my case, RCC_BDCR register is set after RCC_BDCR resets.)


I found external reset (push reset button in board) repeats, RTC value differences from real time.



Thanks.

Post Reply

Return to “mikroC PRO for ARM General”