void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; //NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x2000); // 配置优先级分组,无抢占式优先级 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); // 配置USART1中断优先级 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // 配置USART2中断优先级 NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // 配置USART3中断优先级 NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // 2010-05-26, zhangxingjuan NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //中断通道 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //次优先级 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能 NVIC_Init(&NVIC_InitStructure); //初始化中断 } 串口配置 void USART123_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; // GPIO 初始化结构体 USART_InitTypeDef USART_InitStructure; // USART 初始化结构体 //***********Configure USART1 Tx Pin********* GPIO_InitStructure.GPIO_Pin = GPIO_Tx1PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); //***********Configure USART2 Tx Pin******** GPIO_InitStructure.GPIO_Pin = GPIO_Tx2PIN; GPIO_Init(GPIOA, &GPIO_InitStructure); //***********Configure USART3 Tx Pin********* GPIO_InitStructure.GPIO_Pin = GPIO_Tx3PIN; GPIO_Init(GPIOB, &GPIO_InitStructure); //***********Configure USART1 Rx Pin********* GPIO_InitStructure.GPIO_Pin = GPIO_Rx1PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //***********Configure USART2 Rx Pin********* GPIO_InitStructure.GPIO_Pin = GPIO_Rx2PIN; GPIO_Init(GPIOA, &GPIO_InitStructure); //***********Configure USART3 Rx Pin********* GPIO_InitStructure.GPIO_Pin = GPIO_Rx3PIN; GPIO_Init(GPIOB, &GPIO_InitStructure); //********USART1 configure para********* USART_InitStructure.USART_BaudRate = 2400; USART_InitStructure.USART_WordLength = USART_WordLength_9b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_Even; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_Init(USART1,&USART_InitStructure); /********USART2 configure para*********/ USART_Init(USART2,&USART_InitStructure); /********USART3 configure para**********/ USART_Init(USART3,&USART_InitStructure); // 使能USART1、2、3的接收中断 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); // 使能USART1、2、3 USART_Cmd(USART1, ENABLE); USART_Cmd(USART2, ENABLE); USART_Cmd(USART3, ENABLE); } /** * @描述:配置系统中断 * @入口参数: 无 */ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; //NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x2000); // 配置优先级分组,无抢占式优先级 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); // 配置USART1中断优先级 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // 配置USART2中断优先级 NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // 配置USART3中断优先级 NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //中断通道 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //次优先级 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能 NVIC_Init(&NVIC_InitStructure); //初始化中断 } 以上代码,串口发送数据没问题;但当接收数据时,无法进入USART中断(串口助手监视,是有数据的);研究了半天那个英文编程手册,也没找的出路;望大虾解救。。。。。小弟刚接触STM的片子 |
RE:为什么我stm串口中断不响应?
RE:为什么我stm串口中断不响应?
RE:为什么我stm串口中断不响应?