|
发表于 2008-8-12 17:19:59
|
显示全部楼层
我设置如下:void RTC_Configuration(void)
{
/* Enable PWR and BKP clocks */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE); // 怀疑你漏了这句
/* Reset Backup Domain */
BKP_DeInit();
/* Enable LSE */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{}
/* Select LSE as RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* Enable RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* 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 1sec */
RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
}
我判断:
if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
{
PutString1("RTC 不曾配置....");
//RTC_Configuration();
PutString1("RTC 开始配置....");
Time_Adjust( y, m, d, h, mm, s);
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
}
else
{
if(RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
{
PutString1("\r\n电源复位....");
}
else if(RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
{
PutString1("\r\n External Reset occurred....");
}
可是重新上电还是不能保存时间不知道为什么请大家指点: |
|