打印
[应用相关]

STM32L151 RTC时钟,程序复位后,时钟怎么从设置的起始钟点...

[复制链接]
257|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jcky001|  楼主 | 2021-12-28 11:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
void RTC_Configuration(void) { //EXTI_InitTypeDef EXTI_InitStructure; //NVIC_InitTypeDef NVIC_InitStructure; RTC_InitTypeDef RTC_InitStructure;
/ Enable PWR and BKP clocks / RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/ Reset RTC Backup Domain / RCC_RTCResetCmd(ENABLE); RCC_RTCResetCmd(DISABLE);
/ Allow access to rtc / PWR_RTCAccessCmd(ENABLE);
/ 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();
/ Configure the RTC data register and RTC prescaler /
RTC_InitStructure.RTC_AsynchPrediv = 0x7F; RTC_InitStructure.RTC_SynchPrediv = 0xFF; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init(&RTC_InitStructure);
Set_DateTime(); }
u8 RtcInit(void) { //检查是不是第一次配置时钟 u8 flag = 0;
if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0xA55A) //从指定的后备寄存器中读出数据:读出了与写入的指定数据不相乎 { / RTC configuration / RTC_Configuration();
if(flag == 0){  RTC_WriteBackupRegister(RTC_BKP_DR0, 0xA55A);}
} else { / Enable the PWR clock / RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); / Allow access to RTC / PWR_RTCAccessCmd(ENABLE); / Wait for RTC APB registers synchronisation / RTC_WaitForSynchro(); }
RTC_IRQConfig();
return 0; //ok }

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1414

主题

3785

帖子

5

粉丝