STM32 's Usart interrupts the dead loop, forming a panic.

Source: Internet
Author: User

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.

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.