调试串口时,发现串口会出现频繁跳中断,导致无法执行主循环的问题!
调试发现是串口中断硬件BUG:
1. USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);使能了接收中断,那么ORE中断也同时被开启了。
2. ORE中断只能使用USART_GetFlagStatus(USART1, USART_FLAG_ORE) 读到(没有使能USART_IT_ERR中断时)
解决办法:
1. 初始化时,开启中断
USART_ITConfig(USART1, USART_IT_PE, ENABLE); //开启PE错误接收中断Bit 8PEIE: PE interrupt enable
//CR2 开启ERR中断
USART_ITConfig(USART1, USART_IT_ERR, ENABLE);
2. 在STM32中断函数增加USART_IT_ORE等异常中断的处理!
//开启CR3,bit0的EIE: Error interrupt enable, 处理USART_IT_ERR,USART_IT_ORE_ER,USART_IT_NE,USART_IT_FE 错误
if(USART_GetFlagStatus(USART1, USART_FLAG_ORE) != RESET)
{//同 @arg USART_IT_ORE_ER : OverRun Error interrupt if the EIE bit is set
ushTemp = USART_ReceiveData(USART1); //取出来扔掉
USART_ClearFlag(USART1, USART_FLAG_ORE);
}
if(USART_GetFlagStatus(USART1, USART_FLAG_NE) != RESET)
{//同 @arg USART_IT_NE : Noise Error interrupt
USART_ClearFlag(USART1, USART_FLAG_NE);
}
if(USART_GetFlagStatus(USART1, USART_FLAG_FE) != RESET)
{//同 @arg USART_IT_FE : Framing Error interrupt
USART_ClearFlag(USART1, USART_FLAG_FE);
}
if(USART_GetFlagStatus(USART1, USART_FLAG_PE) != RESET)
{//同 @arg USART_IT_PE : Parity Error interrupt
USART_ClearFlag(USART1, USART_FLAG_PE);
}
|