cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4Discovery RTC+VBAT reset

totti001
Associate II
Posted on July 10, 2013 at 16:33

Hy all!

I've a STM32F4Discovery board. I want to use the RTC library. I see the board schematic, and I think the VBAT pin is always on VDD.

I configure the RTC with LSI, and wake up event, and write a number to the backup0 register.

The code is view the backup0 register data, and it is the previously wrote number, az rtc init function not calling.

The problem is, the first time I set the time and date, everything is working. After I pushed the reset pin, read the backup0 register the value is good, but the time, date wakeup values is 0.

I read several documents and read if a VBAT is connected the register data is remaining.

Whats the problem?

Thanks a lot

#stm32 #rtc #discovery #lsi
5 REPLIES 5
Posted on July 10, 2013 at 17:14

Whats the problem?

Dunno, show some test case code.

Be aware that LSI is not in the backup power domain, and the LSE parts are not populated. A reset from standby event can be detected, and the RTC initialized differently, ie you have to unlock access but not trash/reset the configuration.

I'm also not sure a hard reset is the usual way to go, have you tried STOP or STANDBY?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
totti001
Associate II
Posted on July 10, 2013 at 17:33

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6kz&d=%2Fa%2F0X0000000bui%2F02ev1L39rZsfiModeqjEqxvZ.5LaeDidm6u1T4UBGOQ&asPdf=false
Posted on July 10, 2013 at 17:42

Are you sure your aren't doing this

/* Write to the first RTC Backup Data Register */
RTC_WriteBackupRegister(RTC_BKP_DR0, FIRST_DATA);

too early? I'd probably move that AFTER the RTC_Init(), when the write protect has been cleared, and then CONFIRM that the data is actually set BEFORE the reset.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
totti001
Associate II
Posted on July 10, 2013 at 22:30

When egy read after reset the register the value is the previously wrote value, so the function call is in the best palce I think. The problem is the reset delete all RTC register values exept the backup and the sram registers.

totti001
Associate II
Posted on July 11, 2013 at 14:45

Problem is solved. The problem with the LSI clock. When reset the uC the rcc register is set to the default, so the RTC can't get clock. The RTC registers not cleared, but need sync to read it.

So if you use LSI the correct code is:

if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2 )
{
/* RTC configuration */
RTC_Configuration();
}
else
{
/* The RTC Clock may varies due to LSI frequency dispersion. */
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
RTC_ClearITPendingBit(RTC_IT_WUT);
EXTI_ClearITPendingBit(EXTI_Line22);
}