本帖最后由 飛饵 于 2020-7-19 17:49 编辑
使用STOP模式。RTC闹钟的EXIT线和按键EXTI线配置分封装成两个函数。哪个最后配置就只能用哪个。在最后配置RTC的就没法用按键唤醒,不然就反过来。
按键:
EXTI_InitTypeDef EXTI_initstructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
/* 按键引脚配置 */
//按键已经有专门的配置,这里省略
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource9);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource11);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource10);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource12);
EXTI_DeInit();
EXTI_initstructure.EXTI_Line = EXTI_Line11 | EXTI_Line9 | EXTI_Line10 | EXTI_Line12;
EXTI_initstructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_initstructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_initstructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_initstructure);
EXTI->EMR &= ~(1 << 11); //先关掉外部中断触发
EXTI->IMR &= ~(1 << 11);
EXTI->EMR &= ~(1 << 9);EXTI->EMR &= ~(1 << 10);EXTI->EMR &= ~(1 << 12);
EXTI->IMR &= ~(1 << 9);EXTI->IMR &= ~(1 << 10);EXTI->IMR &= ~(1 << 12);
/* NVIC配置 */
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RTC闹钟:
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* 外部中断配置 */
EXTI_DeInit();
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);
EXTI->EMR &= ~(1 << 17); //先关掉外部中断触发
EXTI->IMR &= ~(1 << 17);
NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
|