cancel
Showing results for 
Search instead for 
Did you mean: 

UART RS485 how to manage half-duplex

Ramzes11
Visitor

Hello,
I implement RS-485 on STM32G491. I receive with ReceiveToIdle_DMA and I also transmit with DMA. I need to know if currently something is being received because that means I cannot send data now because RS485 is half-duplex. As far as I know I cannot use IDLE flag as it clears after interrupt and I need to know if RX line is now IDLE or now I am receiving data.

In sumarry - what condition should I check before sending data and changing DE state of the transceiver to make sure RX is silent now.

Looking forward to your replies!

4 REPLIES 4
Ramzes11
Visitor

Bonus questions:

  1. How would you handle MODBUS RTU requirement that correct space between chars is <= 1.5 char if ReceiveToIdle activates after just 1 char and as far as I know you cannot change it. So if other node has space between chars for example 1.3 it is correct but I would already get ReceiveToIdle_DMA interrupt.
  2. How would you handle MODBUS RTU requirement that there must be >=3.5 char space between frames. I implement Modbus Slave, so I need to wait at least 3.5 char after the request frame. I assume to use ReceiveToIdle so it gives me 1.0 char, so I need to wait additional 2.5 char. Of course there will be some time spent in my code but for very low bauds 2.5 char could be very significant (baud 9600, 2.5 char is 2.9 ms). Of course I assume that delays are not an option.
Chris21
Senior II

To determine that you should respond, you need to validate the received request, e.g., it's addressed to you and has a valid checksum.

Consider implementing your own USART interrupt handler, that way you can measure the inter-character gap time (using a timer that you reset when a character is received); a gap time > 3.5 char can be used to indicate that the received message is complete.

Hi,

Your microcontroller support Modbus RTU/ASCII regarding recognize silence. Please see reference manual RM0440.

USART_Modbus_Communication_STM32G4.png

Your USART have BUSY flag, that can be used to detect reception. But AFAIK most RS485 drivers doesn't provide information about "line free" condition. And even if they did provide this information, there would still be a chance that two nodes would start transmitting at the same time. Therefore you have to rely on communication protocol to avoid collisions.