Direct focus: I use stm32f103 chip Usart2_irqhandler always interrupt, program dead loop.
1. Problems occurred:
The interrupt handler for the original program is:
void Usart2_irqhandler (void)
{
U8 key = 0;
Usart_clearflag (USART2,USART_FLAG_TC); Clear Interrupt Flag
if (Usart_getitstatus (usart2,usart_it_rxne)!=bit_reset)//Check whether the specified USART has been interrupted
{
Key=usart_receivedata (USART2);
Do something in this;
}
}
Running Result: The program starts is normal, but after running for a period of time, will continue to enter the interruption, usart_getitstatus check and no interruption occurred. This function is re-entered as soon as it exits, so the cycle is dead.
2, Reason analysis:
A number of information has been checked and the reference manual is as follows:
(1) Open Rxneie, RXNE and ore interrupts are turned on by default.
(2) must be the first time to clear 0 rxne, if not in time to clear the zero, the next frame of data will be generated overrun error!
(3) The error is caused by ore.
(4) Workaround to clear ore
With this foundation, directly on the solution:
3, the solution:
void Usart2_irqhandler (void)
{
U8 key = 0;
Usart_clearflag (USART2,USART_FLAG_TC | Usart_flag_ore); Clear interrupt flag and ore flag
if (Usart_getitstatus (usart2,usart_it_rxne)!=bit_reset)//Check whether the specified USART has been interrupted
{
Key=usart_receivedata (USART2);
Do something in this;
}
}
The program is normal after the change!!!
4. References
"STM32 serial port interrupt card dead main circulation problem analysis" http://blog.csdn.net/origin333/article/details/49992383
The
STM32 Usart interrupts the dead loop, forming a panic.