为什么在使用STM32F207的RTC的Date更新和时间更新不是同步的。超过24时后Date不是同时加一,而是在某个时候才加1.那么奇怪的。请高手指教
初始化涵数
u8 RTC_init(void)
{
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
/* LSI used as RTC source clock */
/* 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();
/* Calendar Configuration with LSI supposed at 32KHz */
RTC_InitStructure.RTC_AsynchPrediv = 0x02;
//32KHz/16=2KHz ,下面再分频2分成1ms左右
RTC_InitStructure.RTC_SynchPrediv
= 0x01; /* (32KHz / 16) - 1 = 0xFF*/
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure);
/* Enable Wakeup Counter */
RTC_WakeUpCmd(ENABLE);
}
int main(void)
{
RTC_TimeTypeDef TI;
RTC_DateTypeDef DA;
LCD_PinInit();
LCD_Init();
RTC_init();
while(1)
{
RTC_GetDate(RTC_Format_BIN,&DA);
RTC_GetTime(RTC_Format_BIN,&TI);
LCD_3bit(0,0,DA.RTC_Year,YELLOW, BLACK, 0);
LCD_3bit(32,0,DA.RTC_Month,YELLOW, BLACK, 0);
LCD_3bit(64,0,DA.RTC_WeekDay,YELLOW, BLACK, 0);
LCD_3bit(96,0,DA.RTC_Date,YELLOW, BLACK, 0);
LCD_3bit(0,16,TI.RTC_Hours,YELLOW, BLACK, 0);
LCD_3bit(32,16,TI.RTC_Minutes,YELLOW, BLACK, 0);
LCD_3bit(64,16,TI.RTC_Seconds,YELLOW, BLACK, 0);
}
} |
|