最近项目需要用上了stm32f0系列的030cct6,有六个串口,调试配置六路串口的时候总是发现进入异常中断,然后一个个排除,发现仅有串口1和串口2进入接收中断并清除中断标志,串口3到串口6都无法进入接收中断清除中断标志。其后追到中断向量表,惊奇的发现竟然没有串口3到串口6的中断函数,百思不得其解,求各路大神帮帮忙
部分代码如下
void uart_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_USART6,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_USART3|RCC_APB1Periph_USART4|RCC_APB1Periph_USART5,ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9,GPIO_AF_1);//引脚复用配置
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10,GPIO_AF_1);//引脚复用配置.....1
GPIO_PinAFConfig(GPIOA, GPIO_PinSource0,GPIO_AF_4);//引脚复用配置
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1,GPIO_AF_4);//引脚复用配置.....4
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10,GPIO_AF_4);//引脚复用配置
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11,GPIO_AF_4);//引脚复用配置.....3
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2,GPIO_AF_1);//引脚复用配置
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3,GPIO_AF_1);//引脚复用配置.....2
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3,GPIO_AF_4);//引脚复用配置
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4,GPIO_AF_4);//引脚复用配置.....5
GPIO_PinAFConfig(GPIOA, GPIO_PinSource4,GPIO_AF_5);//引脚复用配置
GPIO_PinAFConfig(GPIOA, GPIO_PinSource5,GPIO_AF_5);//引脚复用配置.....6
//USART1_TX GPIOA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1_RX GPIOB.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART4_TX GPIOA.0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART4_RX GPIOB.1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART3_TX GPIOB.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART3_RX GPIOB.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART2_TX GPIOA.2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART2_RX GPIOA.3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART5_TX GPIOB.3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART5_RX GPIOB.4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART6_TX GPIOA.4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART6_RX GPIOA.5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
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_Init(USART1, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
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_Init(USART4, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
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_Init(USART3, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
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_Init(USART2, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
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_Init(USART5, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
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_Init(USART6, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_ITConfig(USART5, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_Cmd(USART1, ENABLE);
USART_Cmd(USART4, ENABLE);
USART_Cmd(USART3, ENABLE);
USART_Cmd(USART2, ENABLE);
USART_Cmd(USART5, ENABLE);
USART_Cmd(USART6, ENABLE);
//NVIC----TIM.c
}
void Nvic_Init(void) //中断优先级设置
{
NVIC_InitTypeDef NVIC_InitStructure;
/*******************Tim3中断优先级设定**************************系统**/
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*******************USART1中断优先级设定***********************SENSOR**/
NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*******************USART2中断优先级设定***********************SENSOR**/
NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*******************USART3中断优先级设定**************************UWB**/
NVIC_InitStructure.NVIC_IRQChannel=USART3_6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void USART1_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
temp = USART_ReceiveData(USART1);
//USART_SendData(USART1,temp);
}
}
void USART2_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART2,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
temp = USART_ReceiveData(USART2);
//USART_SendData(USART2,temp);
}
}
void USART3_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART3,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART3,USART_IT_RXNE);
temp = USART_ReceiveData(USART3);
//USART_SendData(USART3,temp);
}
}
void USART4_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART4,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART4,USART_IT_RXNE);
temp = USART_ReceiveData(USART4);
//USART_SendData(USART4,temp);
}
}
void USART5_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART5,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART5,USART_IT_RXNE);
temp = USART_ReceiveData(USART5);
//USART_SendData(USART5,temp);
}
}
void USART6_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART6,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART6,USART_IT_RXNE);
temp = USART_ReceiveData(USART6);
//USART_SendData(USART6,temp);
}
}
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD RTC_IRQHandler ; RTC through EXTI Line
DCD FLASH_IRQHandler ; FLASH
DCD RCC_IRQHandler ; RCC
DCD EXTI0_1_IRQHandler ; EXTI Line 0 and 1
DCD EXTI2_3_IRQHandler ; EXTI Line 2 and 3
DCD EXTI4_15_IRQHandler ; EXTI Line 4 to 15
DCD TS_IRQHandler ; TS
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_3_IRQHandler ; DMA1 Channel 2 and Channel 3
DCD DMA1_Channel4_5_IRQHandler ; DMA1 Channel 4 and Channel 5
DCD ADC1_COMP_IRQHandler ; ADC1, COMP1 and COMP2
DCD TIM1_BRK_UP_TRG_COM_IRQHandler ; TIM1 Break, Update, Trigger and Commutation
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM6_DAC_IRQHandler ; TIM6 and DAC
DCD 0 ; Reserved
DCD TIM14_IRQHandler ; TIM14
DCD TIM15_IRQHandler ; TIM15
DCD TIM16_IRQHandler ; TIM16
DCD TIM17_IRQHandler ; TIM17
DCD I2C1_IRQHandler ; I2C1
DCD I2C2_IRQHandler ; I2C2
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD 0 ; Reserved
DCD CEC_IRQHandler ; CEC
DCD 0 ; Reserved
__Vectors_End
请问楼主的问题是如何解决的?我找到STM32F030RC的USART3,4,5,6共用一个中断,中断号是29,但不知道进入中断后如何快速识别是哪个串口收到数据触发的中断,难道要对USART3-6的4个中断状态寄存器一个一个去测试?那就太花时间了。
/**
* @brief This function handles USART3 to USART6 global interrupts.
*/
void USART3_6_IRQHandler(void)
{
/* USER CODE BEGIN USART3_6_IRQn 0 */
/* USER CODE END USART3_6_IRQn 0 */
HAL_UART_IRQHandler(&huart3);
HAL_UART_IRQHandler(&huart4);
HAL_UART_IRQHandler(&huart5);
HAL_UART_IRQHandler(&huart6);
/* USER CODE BEGIN USART3_6_IRQn 1 */
/* USER CODE END USART3_6_IRQn 1 */
}
不知道其中的huart3,4,5,6是什么意思?
一周热门 更多>