In the process of using a serial port to send data, it is found that the program will not execute the contents of the main function after first entering the serial port, and the content of the interrupt is not executed. Query a large number of data found that: the serial port in receiving too much data, there will be serial port overflow error, and enter the overflow interrupt (ore interrupt). Next comes the cause of the error and the workaround.
(1) What is ore interrupt. Why is it produced.
The cause is as described above.
The ore flag is in the USART_SR register, but it's worth noting that when we open the serial receiver interrupt, we also turn on the ore interrupt.
(2) How to solve.
After reading the above information, I know the program is dead in the serial port overflow interrupt. The first thing I think of when dealing with interrupts is to clear the interrupt flag, but it's a lot of trouble.
Method of clearing the ore bit: sequential execution of read operations to the USART_SR and USART_DR registers.
Note: Usart_clearitpendingbit (USART1, Usart_it_ore) is used here, and clearing the ORE bit has no effect.
And ORE interrupts can only be read using Usart_getflagstatus (USART1, Usart_flag_ore) (without enabling Usart_it_err interrupts)
These are read in this post http://blog.csdn.net/love_maomao/article/details/8234039 Post also pointed out the translation of the manual error, haha, very powerful blogger (in this confession).
Finally, attach the solution:
Interrupt Service function:
if (Usart_getflagstatus (USART2, usart_flag_ore)! = RESET)
{
Usart_clearflag (USART2, Usart_flag_ore); Clear overflow Interrupt
}
If (Usart_getitstatus (USART2, usart_it_rxne)! = RESET)
{
Usart_clearitpendingbit (USART2, Usart_it_rxne);
//rebuf[num++] = Usart_receivedata (USART2); Read serial data
}