2012-05-18 02:30 AM
I am using in my STM32L151CB project internal RTC timer.
The RTC clock source is selected HCE clock divided into 16 (RCC_RTCCLKSource_HSE_Div16). I using quarz crystal 9830400Hz - ABM2 I load in to a async_prediv 127 and to f sync_prediv 4799 digit value. I check the registry and found that the seconds seconds to go faster than 10 or more times. Init codedefine HSE_CLOCK_RTC
void
RTC_Config(
void
)
{
RTC_InitTypeDef RTC_InitStructure;
ErrorStatus err;
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_RTCAccessCmd(ENABLE);
RCC_RTCResetCmd(ENABLE);
RCC_RTCResetCmd(DISABLE);
RCC_RTCCLKCmd(DISABLE);
#if defined(LSE_CLOCK_RTC)
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSI is ready */
while
(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
#elif defined(LSI_CLOCK_RTC)
RCC_LSICmd(ENABLE);
while
(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
#elif defined(HSE_CLOCK_RTC)
RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div16);
RCC_HSEConfig(RCC_HSE_ON);
while
(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) {
}
#else
#error ''Error define please RTC_CLK_SRC!''
#endif
#if defined(HSE_CLOCK_RTC)
RTC_InitStructure.RTC_AsynchPrediv = (uint32_t)0x7F;
RTC_InitStructure.RTC_SynchPrediv = (uint32_t)0x12BF;
/* ((9830400 /16) / (127+1)) = 4800 = (4800-1)*/
#else
/* Calendar Configuration with LSI supposed at 32KHz */
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
RTC_InitStructure.RTC_SynchPrediv = 0xFF;
/* (32KHz / 128) - 1 = 0xFF*/
#endif
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
if
(!RTC_Init(&RTC_InitStructure)){
TRACE_ERROR(
''RTCInit prescaler Error \r\n''
);
}
else
{
TRACE_INFO(
''RTCInit prescaler SUCCESS\n\r''
);
}
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
}
Thank you in advance for your help.