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

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)
{
printf("\tTranError");
}
}
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;
uart2RxEnable();
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?
