完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
问题现象:
我用的芯片是STM32F103VCT6,在VBAT脚加了3.3V电池,断电后,该引脚确实有电压 但是断电后,再上电,时间从新开始了,不能记录我之前修改好的 我看了一下寄存器,RTC_CNTH这个里面是用来存放断点之前的时钟数据的,但是断电之后再上电,这个里面的数据都没有了 但是软件复位就可以,依然有记录。 这是怎么回事呢? 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(); } void RTC_Config(void) { //l*** 2011.12.7 下面三句用来对BKP寄存器清0,缺一不可,只供实验用 //RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); //Allow access to BKP Domain //PWR_BackupAccessCmd(ENABLE); //BKP_WriteBackupRegister(BKP_DR1, 0x0); //BKP_WriteBackupRegister(BKP_DR1, 0x0); //Reset Backup Domain //2011.12.7 if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5 ) { //Backup data register value is not correct or not yet programmed (when the first time the program is executed) // g_bNVRamBl=0; //电池电压低 //RTC Configuration RTC_Configuration(); Os_InitTime(); //修改系统时间 BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); } else { // g_bNVRamBl=1; //电池电压正常 //Check if the Power On Reset flag is set if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { } //Check if the Pin Reset flag is set else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { } // Enable PWR and BKP clocks RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); //Allow access to BKP Domain PWR_BackupAccessCmd(ENABLE); Os_InitTime(); RTC_WaitForLastTask(); } #ifdef RTCClockOutput_Enable //Enable PWR and BKP clocks RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); //Allow access to BKP Domain PWR_BackupAccessCmd(ENABLE); //Disable the Tamper Pin BKP_TamperPinCmd(DISABLE); //To output RTCCLK/64 on Tamper pin, the tamper //functionality must be disabled //Enable RTC Clock Output on Tamper Pin BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock); #endif //Clear reset flags RCC_ClearFlag(); } void Os_SetTime(TIME_S7* Time) { #if OS_CRITICAL_METHOD == 3 /* Storage for CPU status register */ OS_CPU_SR cpu_sr = 0; #endif u32 TimValue,IsLeap,i,DateNum=0; OS_ENTER_CRITICAL(); sSysTime.Year = Time->Year; sSysTime.Month = Time->Month; sSysTime.Date = Time->Date; sSysTime.Hour = Time->Hour; sSysTime.Minute = Time->Minute; sSysTime.Second = Time->Second; sSysTime.MillSec = Time->MillSec; IsLeap = IsLeapYear(&sSysTime); if(IsLeap==0) { for(i=0;i { DateNum = DateNum + EachMonth[IsLeap]; } TimValue=(sSysTime.Year-Ymark)*31536000+(DateNum+sSysTime.Date)*86400+sSysTime.Hour*3600 + sSysTime.Minute*60 + sSysTime.Second+sSysTime.MillSec/1000; } else { for(i=0;i { DateNum = DateNum + EachMonth[IsLeap]; } /* the value to store in RTC counter register */ TimValue=(sSysTime.Year-Ymark)*31622400+(DateNum+sSysTime.Date)*86400+sSysTime.Hour*3600 + sSysTime.Minute*60 + sSysTime.Second+sSysTime.MillSec/1000; } /* Enable PWR and BKP clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); /* Change the current time */ RTC_SetCounter(TimValue); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); // RTC_T_NUM = RTC_GetCounter(); // RTC_WaitForLastTask(); OS_EXIT_CRITICAL(); } |
|
相关推荐
1个回答
|
|
移植我们的代码看看。我的那个RTC代码。
|
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1784 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1621 浏览 1 评论
1088 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
729 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1680 浏览 2 评论
1938浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
734浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
570浏览 3评论
596浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
559浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 19:56 , Processed in 0.728493 second(s), Total 76, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号