程序是这样设置的,有没有问题?
void Setup_RTC(void) { struct tm now; if(BKP_ReadBackupRegister(BKP_DR1) != CONFIGURATION_DONE) { RTC_Configuration(); now.tm_year = DEFAULT_YEAR; now.tm_mon = DEFAULT_MONTH - 1; //转化成0-11月 now.tm_mday = DEFAULT_DAY; now.tm_hour = DEFAULT_HOURS; now.tm_min = DEFAULT_MINUTES; now.tm_sec = DEFAULT_SECONDS; Time_SetCalendarTime(now); BKP_WriteBackupRegister(BKP_DR1, CONFIGURATION_DONE); } else { /* Enable PWR and BKP clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP,ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); RCC_ClearFlag(); RCC_RTCCLKCmd(ENABLE); /* Wait for RTC registers synchronisation */ RTC_WaitForSynchro(); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Setting RTC Interrupts-Seconds interrupt enabled */ /* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } BSP_IntVectSet(BSP_INT_ID_RTC, RTC_Handler); BSP_IntPrioSet(BSP_INT_ID_RTC, RTC_Second_UIP); BSP_IntEn(BSP_INT_ID_RTC); } void RTC_Configuration(void) { /* Enables the clock to Backup and power interface peripherals */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Allow access to Backup Registers */ PWR_BackupAccessCmd(ENABLE); /* Backup Domain Reset */ BKP_DeInit(); /* Enable 32.768 kHz external oscillator */ RCC_LSEConfig(RCC_LSE_ON); /* Wait for LSE ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET); /* Config RTC clock source (external clock: 32.768K) */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); /* RTC Enabled */ RCC_RTCCLKCmd(ENABLE); /* Wait until last write operation on RTC registers has finished */ // RTC_WaitForLastTask(); /* Wait for RTC registers synchronisation */ RTC_WaitForSynchro(); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Setting RTC Interrupts-Seconds interrupt enabled */ /* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC,ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Set RTC prescaler: set RTC period to 1 sec */ /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ RTC_SetPrescaler(32763); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }