完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
复位后无论是rtc闹钟还是gpio都唤醒不了了..
static void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void EXTI_Key_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOA| RCC_APB2Periph_AFIO,ENABLE); NVIC_Configuration(); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13); EXTI_InitStructure.EXTI_Line = EXTI_Line13; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_InitStructure.EXTI_Line = EXTI_Line17; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd =ENABLE; EXTI_Init(&EXTI_InitStructure); } void RTC_Configuration(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); PWR_BackupAccessCmd(ENABLE); BKP_DeInit(); RCC_LSEConfig(RCC_LSE_ON); while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {} RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); RCC_RTCCLKCmd(ENABLE); RTC_WaitForSynchro(); RTC_WaitForLastTask(); RTC_ITConfig(RTC_IT_SEC, ENABLE); RTC_WaitForLastTask(); RTC_SetPrescaler(32767); RTC_WaitForLastTask(); } void RTC_CheckAndConfig(void) { if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { RTC_Configuration(); RTC_SetCounter(0); RTC_WaitForLastTask(); RTC_SET_ALARM(10); BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); } else { RTC_WaitForSynchro(); RTC_ITConfig(RTC_IT_SEC, ENABLE); RTC_WaitForLastTask(); } RCC_ClearFlag(); } void RTC_SET_ALARM(u32 sec) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); PWR_BackupAccessCmd(ENABLE); RTC_SetAlarm(RTC_GetCounter()+sec); RTC_WaitForLastTask(); RTC_ITConfig(RTC_FLAG_ALR,ENABLE); } void SYSCLKConfig_STOP(void) { RCC_HSEConfig(RCC_HSE_ON); while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) { } RCC_PLLCmd(ENABLE); while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); while (RCC_GetSYSCLKSource() != 0x08) { } } 中断 void KEY2_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line13) != RESET) { EXTI_ClearITPendingBit(EXTI_Line13); SYSCLKConfig_STOP(); } } void RTC_IRQHandler(void) { if (RTC_GetITStatus(RTC_IT_SEC) != RESET) { RTC_ClearITPendingBit(RTC_IT_SEC); RTC_WaitForLastTask(); } } void RTCAlarm_IRQHandler(void) { if(RTC_GetITStatus(RTC_IT_ALR)!= RESET)//ÄÖÖóÖD¶Ï { SYSCLKConfig_STOP(); RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, DISABLE); RTC_SetCounter(0); RTC_WaitForLastTask(); RTC_SET_ALARM(5); BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); RTC_ClearITPendingBit(RTC_IT_ALR); EXTI_ClearITPendingBit(EXTI_Line17); RTC_WaitForLastTask(); } } 主函数 int main() { //LED初始化 LED_GPIO_Config( ); while(1) { RTC_CheckAndConfig(); EXTI_Key_Config(); SysTick_Delay_Ms(50); LED2_ON; SysTick_Delay_Ms(500); LED2_OFF; PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI); } } |
|
相关推荐
1个回答
|
|
大哥,中断函数名不要乱改,比如你的void KEY2_IRQHandler(void),中断函数是要与启动文件相对应的,乱改的话系统就在中断向量表中找不到中断服务函数的入口,直接跳转到启动文件里面预先写好的空函数,并且在里面无限循环,实现不了中断。
最佳答案
|
|
5 条评论
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
使用stm32l451片子,对ad7606进行3通道100k采样值跳动问题?
884 浏览 1 评论
STM32进行DMA数据转运,为什么只有A组最后一位数据被转运到B组去?
1429 浏览 2 评论
1748 浏览 3 评论
1348 浏览 0 评论
嵌入式开发 Win11安装ST-Link 提示 设备描述符请求失败 怎么处理?
1476 浏览 0 评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-22 05:10 , Processed in 0.888075 second(s), Total 97, Slave 76 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号