各位大佬好,目前用STM32F030RCT6三个外部中断PA0,PC5,PC12三个外部中断,PA0,PC12都使用正常当我配置PC5的时候就一直进PC12的中断,PC5之前是用作串口3的接收站,单片机STOP模式休眠后PC5用作外部中断 ,代码如下 /************************************************************** 函数名称:uart_exti_init 函数功能:RX引脚配置为外部中断 输入参数:无 返 回 值:无 备 注:无 **************************************************************/ void uart3_exti_init(void) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStruct; EXTI_InitTypeDef EXTI_InitStruct; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); // GPIOC时钟 /* 关闭UART中断、复位UART、复位GPIO */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, DISABLE); GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_0); USART_ITConfig(USART3, USART_IT_RXNE, DISABLE); USART_Cmd(USART3, DISABLE); GPIO_DeInit(GPIOC); USART_DeInit(USART3); //USART3_TX PC4 //USART3_RX PC5 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //按键PC5 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //输入模式 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; //下拉输入 GPIO_Init(GPIOC, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); //使能系统时钟配置 SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource5); //连接EXTI5给GPIOC5 EXTI_InitStruct.EXTI_Line = EXTI_PinSource5; //中断线标号5 EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; //外部中断模式 EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿中断EXTI_Trigger_Falling EXTI_InitStruct.EXTI_LineCmd = ENABLE; //中断线使能 EXTI_Init(&EXTI_InitStruct); NVIC_InitStruct.NVIC_IRQChannel = EXTI4_15_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 0x00; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); } /*************************************** * 函数描述:外部中断初始化 * 输入参数:No * 返 回 值:No * 说 明: * 修改记录: ****************************************/ void EXTI_KEY_Init(void) { EXTI_InitTypeDef EXTI_InitStruct; NVIC_InitTypeDef NVIC_InitStruct; GPIO_InitTypeDef GPIO_InitStruct; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12; //按键PC12 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; //输入模式 GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_2; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN; //下拉输入 GPIO_Init(GPIOC, &GPIO_InitStruct); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); //使能系统时钟配置 SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource12); //连接EXTI0给GPIOC0 EXTI_InitStruct.EXTI_Line = EXTI_Line12; //中断线标号0 EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; //外部中断模式 EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿中断EXTI_Trigger_Falling EXTI_InitStruct.EXTI_LineCmd = ENABLE; //中断线使能 EXTI_Init(&EXTI_InitStruct); NVIC_InitStruct.NVIC_IRQChannel = EXTI4_15_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 0x00; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); } /*************************************** * 函数描述:外部中断12服务程序 * 输入参数:No * 返 回 值:No * 说 明: * 修改记录: ****************************************/ void EXTI4_15_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line5) != RESET)//判断线5上的中断是否发生,可以理解为标志位 { EXTI_ClearITPendingBit(EXTI_Line5);//清除LINE5上的中断标志位 } if(EXTI_GetITStatus(EXTI_Line12) != RESET)//判断线12上的中断是否发生,可以理解为标志位 { EXTI_ClearITPendingBit(EXTI_Line12);//清除LINE12上的中断标志位 } } /***************************************************** * 函数:对应的串口三初始化 * 参数:baud---波特率设置 * 功能:按照设置初始化串口三 * 备注: *****************************************************/ void USART3_Init(uint32_t baud) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); // GPIOC时钟 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //串口3时钟使能 GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_1);//PC4-USART3_Tx GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_1);//PC5-USART3_Rx USART_DeInit(USART3); //复位串口3 //USART3_TX PC4 //USART3_RX PC5 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //复用推挽输出 GPIO_Init(GPIOC, &GPIO_InitStructure); // USART_InitStructure.USART_BaudRate = baud;//波特率; USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式 USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位 USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式 USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //开启接收中断 // USART_ITConfig(USART3, USART_IT_TXE, ENABLE); //开启发送中断 USART_Init(USART3, &USART_InitStructure); //初始化串口3 //设置中断优先级 NVIC_InitStructure.NVIC_IRQChannel = USART3_6_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x02; //抢占优先级2 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能 NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存 USART_Cmd(USART3, ENABLE); //使能串口 } |
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource5); //连接EXTI5给GPIOC5
EXTI_InitStruct.EXTI_Line = EXTI_PinSource5; //中断线标号5
EXTI_InitStruct.EXTI_Line = EXTI_Line12; //中断线标号0
评分
查看全部评分
不是这个问题
就是这个问题,找了几天,非常感谢!