STM32F103,4路串口中断接受没有问题,单测外部中断也没有问题,放在一起的时候,出问题了,外中断能影响串口中断(选用的是下降沿中断,单侧是没有问题的,和串口中断在一起的时候,发现串口丢数据了,而且在按键没有抬起时,串口不能接受了,在主循环里一个流水等也不流了)反复改NVIC里的中断优先级了,4路串口在115200 100MS定时发送500字节左右,都能正确响应(中断函数里就是收到什么在回发出来),同时定时器里控制灯闪和主程序里流水也没问题。好几天了,哪位给指教一下,对NVIC里的优先级什么的搞的云里雾里的,呵呵要求外中断级别是最低的,不能影响串口
俺在线等结果呢,在好几个群里发了问,都无人回应!!
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
/*********************外部中断0配置*************************/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource1); //把PA.0设置为外部中断0
EXTI_DeInit(); //将EXIT寄存器重设置为缺省值
EXTI_InitStructure.EXTI_Line = EXTI_Line1; //设置外部中断线0
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//EXTI_Mode_Interrupt; EXTI_Mode_Event //设置EXTI线路为重点请求
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //设置输入线路为下降沿为中断请求
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //中断使能
EXTI_Init(&EXTI_InitStructure);
//EXTI_GenerateSWInterrupt(EXTI_Line1);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); // 设置先占优先级2位,从优先级2位 ;
// Enable the TIM2 global Interrupt
/*
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; // TIM2 全局中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // 先占优先级 0 ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // 从优先级 0 ;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // IRQ通道被使能 ;
NVIC_Init(&NVIC_InitStructure);
*/
// Enable the TIM3 Interrupt
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel; // TIM3 全局中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // 先占优先级 1 ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; // 先占优先级 0 ;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // IRQ通道被使能 ;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel; // USART1 全局中断 ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel; // USART2 全局中断 ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
*/
/*
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel; // USART3 全局中断 ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 4;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
*/
/*
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQChannel; // USART4 全局中断 ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5;
//NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
*/
/* */
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQChannel;//EXTI0_IRQChannel;//设置外部中断0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;//主优先级为4
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//从优先级为4
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//中断使能
NVIC_Init(&NVIC_InitStructure);
}
void USART2_IRQHandler(void)
{
u8 mm,i,p,n;
if(USART_GetITStatus(USART2, USART_FLAG_ORE) != RESET)
{
mm=(u8)(USART_ReceiveData(USART2));
USART_SendData(USART2,mm);
}
}
void UART4_IRQHandler(void)
{
u8 mm,i,p,n;
//USART_SendData(USART1,'<');
if(USART_GetITStatus(UART4, USART_FLAG_RXNE) != RESET)
{
mm=(u8)(USART_ReceiveData(UART4));
USART_SendData(UART4,mm);
}
//USART_SendData(USART1,'>');
}
最开始调试的时候在中断里一直判断这个USART_FLAG_RXNE,后来在把4个串口都打开的时候在判断这个不行了,程序一直在这个中断里不出来,所以就判断USART_FLAG_ORE这个,目前串口还没问题,这个我稍后在查
|