I am working with Arduino Due connected to a meter via RS485. (RXD2 and TXD2 or arduino connected to RO and DI of ISL83485 IC; A and B of ISL83485 connected to the meter).
At the first, I send a packet to the meter and after receiving an specific response, send another packet.
Through this task, I have to manage the suitable time to send or receive data to/from the meter (controlling DE and /RE pins); otherwise I will miss sent or received data.
I am searching the way which solve my problem . (a library, manipulating a register, adding a delay after sending the packet, a sample code or etc.)
The best way I have found to do this is to take a measurement of Serial.availableForWrite() just after Serial.begin(). Whenever you see this value, you know that the outgoing Arduino serial buffer is empty and the hardware buffer is transmitting the last byte. Add a timeout to this which is longer than a byte and then you can disable the transmitter.
The Teensy has hardware pins to control RS485 chips but when I tested it I could not make it work. The software solution is a little crude but good enough for my project. I don't remember if the Due has similar hardware pins.