我用5个串口, 串口1.2.3、5 都可以正常进入中断,而串口4接收中断进不去,实在找不出问题,请大家帮忙
串口4 配置串口
********************************************************************/
void UART4_Init(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC |RCC_APB2Periph_AFIO, ENABLE); //使能UART5所在GPIOC的时钟
//使能串口1时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE);
//******************************************************************************
// 串口1所使用管脚输出输入定义
//******************************************************************************
// 定义UART4 TX (Pc10)脚为复用推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //tx pb10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; //
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //IO口复用推挽输出
GPIO_Init(GPIOC,&GPIO_InitStructure);
// 定义 USART143Rx (Pc.11)为悬空输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; //IO口的第十脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //IO口悬空输入
GPIO_Init(GPIOC,&GPIO_InitStructure); //初始化串口3输入IO口
//*********************************************
// 串口1参数初始化定义部分,串口4参数为19200 , 8 ,1 ,N 接收中断方式
//******************************************************************************
USART_InitStructure.USART_BaudRate = 19200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //设定传输数据位数
USART_InitStructure.USART_StopBits = USART_StopBits_1;//设定停止位个数
USART_InitStructure.USART_Parity = USART_Parity_No; //无校验
USART_InitStructure.USART_Mode = USART_Mode_Rx|USART_Mode_Tx; //使用接收和发送功能
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //不用控制流量
USART_Init(UART4, &USART_InitStructure); //配置串口参数函数
USART_ITConfig(UART4,USART_IT_RXNE,ENABLE); //接收使能
USART_ITConfig(UART4,USART_IT_TC,ENABLE);
USART_Cmd(UART4,ENABLE); //使能串口4
USART_ClearFlag(UART4,USART_FLAG_TC); // 清除中断标志
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;//Channel; USART1_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void UART4_IRQHandler(void)
{
u8 i;
if(USART_GetITStatus(UART4,USART_IT_RXNE) != RESET)
{
i = USART_ReceiveData(UART4);
USART_ClearITPendingBit(UART4,USART_IT_RXNE);
cReceiveBuffer4[ReceiveLength4] = i;
TimerOfCom4Delay = 10;
if(ReceiveLength4 <BufferSize)
ReceiveLength4++;
else
ReceiveLength4 = 0;
}
if(USART_GetITStatus(UART4,USART_IT_TC) !=RESET)
{
USART_ClearFlag(UART4,USART_FLAG_TC);
}
}
谢谢! |