cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Transmit but nothing is sent

Hi. I'm using these lines of code

Result= HAL_UART_Transmit(serial, BufferSerialWrite, BufferSize, HAL_MAX_DELAY);

to send data but, after some hours, nothing exits from the uart. I have to reboot the mcu.

How can I resolve this problem?

The line of cose

HAL_UART_Init(serial);

hasn't got any effect

6 REPLIES 6

Lots to work with here..

What STM32 part?

Does it return an error? Works for hours and stops, or never works?

Check status/errors reported in USART SR, inspect in debugger.

Sure it is not another problem? Like getting stuck in Hard Fault Handler, or in interrupt context.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

It is a STM32F091. It works for many hours. I obtain always Result= HAL_OK

I will retry using the debugger.

Bob S
Principal

You do realize that HAL_MAX_DELAY will tell the function to wait more than 49 DAYS before timing out? Try setting this to a more reasonable value and see if you then get an error returned from HAL_UART_Transmit().

Look at the source for HAL_UART_Transmit(), see where it loops waiting for a flag or timeout. In fact, run with your debugger, wait till it "hangs" then break. That should show you which flag it is waiting for. The BIG question is what that flag isn't getting set/reset.

That is *IF* the problem is in the HAL_UART_Transmit() function. Otherwise it may be in a fault or interrupt handler as @Community member​ mentioned.

Maybe the problem was about the wrong setup of the mcu clock.

in mozbek we trust
Associate II

Did you check oscillator on your Tx pin can you see any messages there ?