MAX485 RS-485 module

The blue MAX485 module turns a board's UART into RS-485, so boards meters apart talk over one twisted pair.

Aliases: MAX485, HW-0519, TTL to RS-485 module, RS485 module, MAX481, MAX483, MAX487, MAX3485, SP485, SN75176.

RS-485 sends each bit as a difference between two wires, A and B, instead of a level against ground, which is what lets it run hundreds of meters through electrical noise. It is half duplex: every module on the pair can listen, and one at a time may talk. It carries plain serial bytes, so Serial or SoftwareSerial works through it, and Modbus RTU (ModbusMaster.h) runs on top of it.

const int DIR = 4;              // DE and RE tied together
void setup() {
  pinMode(DIR, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  digitalWrite(DIR, HIGH);      // talk
  Serial.println("hello");
  Serial.flush();               // wait for the last bit before letting go
  digitalWrite(DIR, LOW);       // listen
  delay(1000);
}

Pins

Pin What it does
RO Receiver output: the bus as a logic level, to the board's RX.
RE Receiver enable, active low (/RE). High lets RO go (the pull-up holds it high).
DE Driver enable, active high. High puts DI on the bus.
DI Driver input: from the board's TX.
VCC 5 V (the chip is rated 4.75 to 5.25 V).
B, A The bus pair, also on the screw terminal. A goes to A, B to B.
GND Ground, shared with the board.

DE and RE are usually wired together to one pin: high to send, low to listen.

Properties

termination: the module's 120 ohm resistor across A and B (on by default). On a real bus only the two modules at the far ends keep theirs; untick it on the ones in between.

What the model gets right

The bus is solved as a circuit. Every module on the pair puts its terminator, its bias resistors, its receiver's 12 kohm input and, while DE is high, its driver into one network, and each receiver reads the voltages that come out. So two, three or ten modules on one pair really talk, half duplex.

The driver. DI high puts A above B; low puts B above A. Into the 60 ohm of two terminators the difference is about 1.8 V on 5 V, inside the data sheet's 1.5 V minimum for 54 ohm. DE low takes the outputs off the bus.

The receiver. RO is 1 when A is 200 mV or more above B and 0 when it is 200 mV or more below. Undriven, open or shorted inputs read 1 (the MAX485's fail-safe), so an idle bus does not look like a start bit. RE high lets RO go to the module's 10 kohm pull-up.

The module's resistors. 10 kohm pull-ups on RO, RE, DE and DI (so a module with DE and RE left open is transmitting), 20 kohm biasing A up and B down, and the 120 ohm terminator, as on the common module's schematic. Clones vary.

Mistakes show. Two modules with DE high at once fight: the pair sits near 0 V, receivers read nonsense, and the board says bus fight. A module with no ground is unpowered and sends nothing. On the canvas, the board shows TX, RX or both, and the voltage between A and B.

Any baud rate passes: the module never looks at bytes, only levels, so hardware Serial, SoftwareSerial and Modbus all work through it.

What it does not model

The propagation delays (tens of nanoseconds, about 1% of a bit at 115200 baud), the 2.5 Mbit/s limit, the driver's current limit and thermal shutdown (a fight passes about 80 mA for as long as it lasts), the -7 to 12 V common-mode range, and the supply current (nothing is drawn from VCC). The simulator has one ground, so two boards on separate supplies still share a reference even when their grounds are not wired together. Cable length and reflections are not modeled. Below 4.75 V the chip runs anyway, down to 3 V, with a smaller swing.

Common mistakes

Dropping DE right after Serial.print(). The hardware UART is still sending from its buffer, so the end of the message is cut off. Call Serial.flush() first (ModbusMaster does this for you between preTransmission and postTransmission).

Leaving the receiving module's DE high: it drives the bus too, and the two drivers fight.

Crossing A and B: every bit arrives inverted, so the bytes are garbage.