初始化代码如下,中断函数如下,发送正常,中断无法进入。
void Uart5Init(u32 bound){
//GPIO端口设置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
//使能时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE);
/* Configure UART5 Rx (PD2) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Configure UART5 Tx (PC12) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//波特率、字长、停止位、奇偶校验位、硬件流控制、异步串口为默认(被屏蔽字设置)
USART_InitStructure.USART_BaudRate = bound;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
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(UART5, &USART_InitStructure);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);//开启中断
USART_Cmd(UART5, ENABLE); //使能串口
}
void UART5_IRQHandler(void) //串口5中断服务程序
{
unsigned char recvData;
if(USART_GetITStatus(UART5, USART_IT_TXE) != RESET)
{
USART_ClearITPendingBit(UART5, USART_IT_TXE);
}
if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
{
recvData =USART_ReceiveData(UART5);//(UART5->DR); //读取接收到的数据
}
}