·
Reference

Modbus Cheat Sheet

One-page reference. Print-friendly. Open from anywhere with ⌘K → “Cheat sheet”.

Function codes

HexNameNotes
01Read CoilsRead 1-bit outputs (R/W)
02Read Discrete InputsRead 1-bit inputs (RO)
03Read Holding RegistersRead 16-bit R/W registers
04Read Input RegistersRead 16-bit RO registers
05Write Single Coil0x0000 = OFF, 0xFF00 = ON
06Write Single RegisterWrite one 16-bit value
07Read Exception StatusSerial only — quick status byte
08DiagnosticsSerial only — sub-functions
0BGet Comm Event CounterSerial only
0FWrite Multiple CoilsUp to 1968 coils
10Write Multiple RegistersUp to 123 registers
11Report Server IDVendor / model info
14Read File RecordRare
15Write File RecordRare
16Mask Write RegisterAND/OR mask in place
17Read/Write Multiple RegistersWrite, then read in one transaction
18Read FIFO QueueRare
2BEncapsulated InterfaceMEI — device identification

Exception codes

HexNameMeaning
01Illegal FunctionFunction code not supported
02Illegal Data AddressAddress not in valid range
03Illegal Data ValueValue out of allowed range
04Server Device FailureUnrecoverable error on server
05AcknowledgeLong operation accepted — poll later
06Server Device BusyRetry later
08Memory Parity ErrorFile record memory error
0AGateway Path UnavailableGateway misconfigured
0BGateway Target No ResponseDownstream device silent

Framing & transports

TopicValue
RTU silent interval≥ 3.5 character times between frames
RTU inter-char gap> 1.5 char times restarts framing
RTU CRCCRC-16, poly 0xA001, init 0xFFFF, LO byte first
ASCII frameStarts ':' (0x3A), ends CR LF (0x0D 0x0A)
ASCII LRCTwo's complement of sum, hex-encoded
TCP MBAPTxID(2) + ProtoID(2)=0 + Length(2) + UnitID(1)
TCP port502 (default)
TCP unit IDDirect: 0xFF recommended or 0; gateway routing is product-specific

Addressing (1-based docs ↔ 0-based wire)

TableDoc rangeFunction codes
Coils00001–09999FC 01, 05, 0F · wire 0x0000+
Discrete Inputs10001–19999FC 02 · wire 0x0000+
Input Registers30001–39999FC 04 · wire 0x0000+
Holding Registers40001–49999FC 03, 06, 10, 17 · wire 0x0000+

Wire address = documented address − base (e.g. 40001 → 0x0000).

Serial defaults

TopicValue
Common baud9600, 19200, 38400, 57600, 115200
Default frame8 data, Even parity, 1 stop (8E1)
No parityUse 8N2 (two stop bits) per spec
RS-485 loading32 standard unit loads; above 32 needs documented unit-load or repeater evidence
TerminationNear both trunk ends; use the documented network values
BiasOne bus-wide network only when connected devices require it

Quick checks

  • Exception response = function code | 0x80, followed by 1-byte exception code.
  • RTU silent gap missing → frames concatenate; check 3.5-char timer.
  • Wrong word order on 32-bit → swap word pairs (CDAB vs ABCD) before scaling.
  • TCP timeout but no exception → check unit ID and gateway routing.