cancel
Showing results for 
Search instead for 
Did you mean: 

how to handle HAL_UART_ERROR_ORE?

yafisdamda
Associate II
Posted on December 16, 2015 at 12:31

Hi everybody!

I am using STM32F0 and stm32 cube as my development platform. 

I wanted to know the causes for uart over run error and what is the best solution to handle uart over run error.

I am facing this problem in Uart receive interrupt. It is always generating overrun error and i am unable to process uart received data. The uart baud rate is 9600.

Any suggestions would be a great help.

Thanks

#cubemx #stm32 #overr #uart-error
9 REPLIES 9
Posted on December 16, 2015 at 18:14

Hi yafis.mohamed,

''An overrun error occurs when a character is received when RXNE has not been reset. Data can not be transferred from the shift register to the RDR register until the RXNE bit is cleared''

 

More details are available under 

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/DM00091010.pdf

.

To handle an overrun error, you can refer to section 41 and 42 of

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00122015.pdf?s_searchtype=keyword

.

-Shahrzad-

yafisdamda
Associate II
Posted on December 17, 2015 at 07:55

Thanks.!

Understand the reason for over run error.

But all the steps mentioned in the above docs are been taken care by the HAL uart driver. What could be the reason it still occurs?

Could it be the slave is faster than the host?

what are the steps to be taken in the error handler callback?

AvaTar
Lead
Posted on December 17, 2015 at 09:00

IMHO shahrzad's answer was not very clear.

The problem is, you are spending too much time in an interrupt routine, either the UART interrupt itself, or another one with equal or higher priority. You don't service the RXNE interrupt until the next character arrives, and overwrites RX.

I don't know if/how Cube messes interrupts up - I stick to the SPL. But you generally need to avoid delays and lengthy operations in the interrupt context. A good (bad) example are printf-style functions, which mostly use UART interrupts, too.

yafisdamda
Associate II
Posted on December 17, 2015 at 11:51

Thanks AvaTar. That clears a lot of stuff.

yafisdamda
Associate II
Posted on December 18, 2015 at 12:11

what would be the ideal things to do in the error callback.?

clearing the interrupt, flushing the DR register i guess..

Anything else.? I am not able to stop the overrun.

AlexF
Associate II
Posted on June 26, 2018 at 11:54

I know this is an old thread, but I write it down for those people who have trouble with the same problem...

The HAL driver enables the UART controller.

When you have a sender connected which sends data permanently, the receiver is active.

If you then enable the interrupt, you get an overrun error immediately.

Eliminate the __HAL_UART_ENABLE in the HAL_UART_Init function, and use it when you are ready to receive via interrupt.

Posted on July 07, 2018 at 00:42

Hi Alex, I am having the same problem - I have a sender permanently sending data, and my receiver is the STM32L4 chip.  If I have HAL_UART_Receive() called before signal is sent, I have no problem. 

If the sender is sending data before HAL_UART_receive() is called, I get an overrun error.   I've tried to use __HAL_UART_CLEAR_FLAG( &huart5, CLEAR_FLAG_OREF) which does clear the overrun flag, but I still cannot read with HAL_UART_receive() or via RXNE.  

I am looking for a solution that, when overrun does occur, flush Rx buffer, clear over run flag, and try again (read the next available message).  I haven't gotten this working... Perhaps I am missing a step or two?  

RusikOk
Associate III

what worked for me was this:

__HAL_UART_CLEAR_FLAG(&huart1, UART_CLEAR_OREF);
HAL_UART_Receive_IT(&huart1, &Vcc, sizeof(Vcc));

eduardo_reis
Associate III

Thank you @RusikOk. It did solve the problem for me too. The only difference on what I did is that I call `__HAL_UART_CLEAR_FLAG` indirectly using the macro

 

__HAL_UART_CLEAR_OREFLAG(&huart3);