Showing results for 
Search instead for 
Did you mean: 

When using Uart on Stm32h7, I have a question about the problem that the messages I sent are coming.

Associate II


The current system is configured as shown in the figure above, and the serial communication is using RS485.
In the system configuration, UART3 and UART2 are used, and the message from the PC through UART3 is delivered to the device through UART2 from the MCU.
After that, the device processes the message and sends a response message, which is received by the MCU through UART2, and the response message is passed back to the PC through UART3.

The problem is that the MCU receives the message from the PC via UART3 normally, and sends the message to the device via UART2, but the message sent to UART2 is immediately received by the UART2 receiver, and the response message from the device is not received.

Currently, the code to send and receive data to UART2 is shown below.
1) Code to send data to Device
for(int i = 0 ; i < size; i++)
if(HAL_UART_Transmit(&sensorUart2Handle, (unsigned char *)&data[i], 1, 0x05) != HAL_OK)
uartTransmitEndState2 = 1;
> When the transmission is over, change from timer to Rx mode via uartTransmitEndState2 variable

2) Code to change from timer to receiver mode
> Change the Tx mode to Rx mode through uart2RxEnable function and make it listen through Receive interrupt.
> Note that the timer runs at 500KHz.
if(uartTransmitEndState2 == 1)
uartTransmitEndState2 = 0;
if(HAL_UART_Receive_IT(&sensorUart2Handle, (unsigned char *)rxOnebyte2, 1) != HAL_OK){}

In conclusion, the problem is that when you send data to UART2 and change to receive mode, you are receiving messages sent by UART2 instead of receiving messages sent by the device.

Do you have any idea how to fix this or what might be causing it?

Senior III

Your Device might have a "remote echo" mode: all what Device gets will be sent back (as echo).
It is pretty normal that UART devices do this "remote echo" (otherwise the PC would not see what it has sent).
All my UART implementations have such a "remote echo" (compared to enable "local echo" on PC, but usually a Device echos back what it has received).

Check if your Device does a "remote echo" (I would guess).

You should see still a response, e.g. after a command send (and echoed back) will send a respond for this command. But you have to discard the "remote echo".

For devices, this is the equipment you were using before. The device is also stm32 based and when I connect it to my PC or connect it to anything else, I don't get the echo that you mentioned, so I don't think it's an echo issue.

Is it possible to set and change the Echo mode in the stm32 Uart configuration? If so, I would appreciate it if you could tell me how.


I have neither used nor seen an automatic echo mode in the UART. So if it exists, you must activate it.

So check the peripheral and your setup.

And check your buffers, maybe there's some confusion about RX and TX buffers with 2 UARTs?