Electronic – Correctly using RE and DE with RS485

microcontrollerrs485serial

I'm trying to build a RS-485 project using MAX485's. However, I'm having trouble finding out how to correctly use the RE and DE pins. Some PDF's and websites say that RE and DE should be tied together and then connected to a pin on a microcontroller (for example). Other places seem to have various combinations of connecting DE to ground and RE to positive, and other such things.

Additionally, the places that say RE and DE should be tied together and then connected to a microcontroller, also have conflicting information about how these should then be controlled through the software.

So my questions are:

  • What am I actually supposed to do with RE and DE? Do I need any pull up or pull down resistors also?
  • How do I control RE and DE assuming they are controlled by my microcontroller? Do I set them high/low then send data then set them low/high again? Do I do the same for receiving data?

Any help on this would be appreciated, and also if there are any links to sites with this specific information about DE/RE would be good.

Best Answer

You don't need any pull-up or pull-down resistors if you're driving those pins with normal output pins on your micro.

DE is the 'Driver Enable' pin and must be pulled high while you're transmitting data. Depending on your micro and how you're using its interrupts you may need to be careful about when you pull it back low - check that all of the bits are completely finished first or you risk truncating the end of your message. You must pull it back low before you'll be able to receive anything.

RE is the 'Receiver Enable' pin and must be pulled low whenever you want to be able to receive data.

You'll notice that the DE and RE pins have opposite polarity. DE is active-high and RE is active-low.
So you can tie them together and control them from one pin if you want to - high means you want to transmit (DE active, RE inactive), and low means you want to receive (RE active, DE inactive).

Another possibility is to tie RE to ground and only control DE.
You would use this configuration is you want to be able to listen to yourself talk. This would be useful in cases where there could be multiple masters talking on your RS-485 bus and you need to check that what you think you're sending is not being corrupted by another transmission occurring at the same time.

If you're only ever going to be either transmitting or receiving then you could tie both DE and RE high (permanent transmit) or both low (permanent receive).