2015-12-16 03:31 AM
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-error2015-12-16 09:14 AM
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 .To handle an overrun error, you can refer to section 41 and 42 of .-Shahrzad-
2015-12-16 10:55 PM
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?2015-12-17 12:00 AM
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.2015-12-17 02:51 AM
Thanks AvaTar. That clears a lot of stuff.
2015-12-18 03:11 AM
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.2018-06-26 02:54 AM
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.
2018-07-06 05:42 PM
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?
2023-08-25 03:18 AM
what worked for me was this:
__HAL_UART_CLEAR_FLAG(&huart1, UART_CLEAR_OREF);
HAL_UART_Receive_IT(&huart1, &Vcc, sizeof(Vcc));
2024-01-04 08:31 AM - edited 2024-01-04 08:32 AM
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