2013-07-10 07:33 AM
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 #lsi2013-07-10 08:14 AM
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?2013-07-10 08:33 AM
2013-07-10 08:42 AM
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.
2013-07-10 01:30 PM
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.
2013-07-11 05:45 AM
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);
}