cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I am trying to communicate Uart in interrupt mode.We are able to successfully transmit & receive data to PC (through USB-UART).But when we connect to UART based modem then we are getting HAL_UART_ErrorCallback & transmission is failing. Pls help us.

PBira.1
Associate II

This error callback function is not getting called when we connect to PC. But we are getting during modem (UART based)communication only. Whats purpose of this callback ? Is there any configuration need to add ?

25 REPLIES 25

Which STM32?

There's an error code in huart->ErrorCode indicating the type of error.

/** @defgroup UART_Error_Code UART Error Code
  * @brief    UART Error Code 
  * @{
  */ 
#define HAL_UART_ERROR_NONE         0x00000000U   /*!< No error            */
#define HAL_UART_ERROR_PE           0x00000001U   /*!< Parity error        */
#define HAL_UART_ERROR_NE           0x00000002U   /*!< Noise error         */
#define HAL_UART_ERROR_FE           0x00000004U   /*!< Frame error         */
#define HAL_UART_ERROR_ORE          0x00000008U   /*!< Overrun error       */
#define HAL_UART_ERROR_DMA          0x00000010U   /*!< DMA transfer error  */

Does the modem's baudrate match the STM32's one? Observe Rx and Tx using oscilloscope.

JW

Thank you for your response.

I am trying to communicate with gsm module and it’s getting overrun error in TX call back function. Our uart transmit and receive line is 3.3 v ....We are setting converter for ttl match and result is same.

Please guide us how we can resolve this issue? We are using STM32F411VE discovery.

> it’s getting overrun error in TX call back function

Then you have to speed up your reception. If system clock is not at max, increase it; if baudrate can be changed, decrease it; if compiler optimization is off, switch it on; if you don't use DMA, start using it.

JW

Andrew Neil
Evangelist

"We are able to successfully transmit & receive data to PC (through USB-UART)"

Presumably, you tested this by typing stuff at a terminal?

"But when we connect to UART based modem then we are getting HAL_UART_ErrorCallback" ... "it’s getting overrun error"

As @Community member​ says, that's because you're not handling the received characters quickly enough - possibly (probably?) because you're trying to do too much in your handler.

Thing about it: when you type characters manually, you're only getting a few per second max - so the MCU has plenty of time to handle them.

But a modem can send characters back-to-back - so you need to be quick.

You should be able to demonstrate that by pasting stuff into your terminal, use using its file send facility ...

"it’s getting overrun error in TX call back"

Really - in the TX callback?

Overrun would normally be expected on RX

 Hi ,

Thank you for your replies.

We are using dock light app for communicating between PC n STM32 discovery . Where data can be sent in junks simultaneously and stm32 get those bytes. But if we use gsm modem (with level converter ) , receive get fails.

One more thing observed if you remove stm32 receive line and reconnect then you always next expected packet(like OK or Error)

Even though we clear bits it’s not working.

Please let us know your inputs.

Andrew Neil
Evangelist

"using dock light app for communicating between PC n STM32 discovery"

You mean this: https://docklight.de/ ?

"data can be sent in chunks simultaneously and stm32 get those bytes"

How big are the "chunks"? are you sure that the app isn't adding any inter-character delays?

Do you have an analyser or oscilloscope to verify what's actually happening on the wires?

"if we use gsm modem (with level converter ) , receive get fails"

Are you sure that the modem is actually working?

eg, can you communicate with it from Docklight ?

Are you sure that the modem is actually receiving your commands?

See https://www.avrfreaks.net/comment/2336161#comment-2336161 for some tips on debugging serial comms.

Piranha
Chief II

If the code is implemented as receive-process-receive, then it is inherently broken. As a minimum receiving must be implemented with double buffering and processing must be done outside the ISR. And still that will not work reliably because the HAL is full of bugs and bloat. For a sane implementation example look here:

https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx

PBira.1
Associate II

Thank you all for your response.

We have tried new interrupt based program and its working but we still see error and continuously UART error callback function (i.e. HAL_UART_ErrorCallback) getting called.

0693W000008xsbuQAA.png 

If this error is getting then we don't get any data in receive buffer. Please suggest us:

  1. How to handle this callback function so that it will clear and start receiving buffer again.
  2. How we can avoid this error ?