STM32 Serial receiver Interrupt overflow problem solving

Source: Internet
Author: User

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
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.