03 — FUNCTION CODES
8 function codes, organized by read/write × bit/word.
Estimated 8 minutes.
The verb in every Modbus sentence.
The function code is the first byte of the PDU. It tells the slave what action you want — read these bits, write that register, etc. There are only eight you really need to know.
Two axes: read/write × bit/word.
Each function fits exactly one cell. Memorize the grid and you have memorized Modbus.
Bit operations work on coils and discrete inputs.
A coil is a single bit you can read OR write. A discrete input is a single bit you can only read. Think of coils as outputs on a digital PLC and discrete inputs as digital input contacts.
Coils vs discrete inputs.
Coils on the left (R/W). Discrete inputs on the right (read-only).
Word operations work on registers.
A register is a 16-bit slot. Holding registers are read/write (general scratch space). Input registers are read-only (analog values from the device).
Holding vs input registers.
Two independent register pools — neither overlaps the other or the coils.
Wire the factory.
Six devices on the floor. Eight function codes in the palette. Tap a chip then a device (or drag it) — the slave reacts live. Wire all 8 function codes to a device that fits.
The four read functions.
FC1 reads coils. FC2 reads discrete inputs. FC3 reads holding registers. FC4 reads input registers. Same shape on the wire — they only differ in which address space they target.
The four write functions.
FC5 writes ONE coil. FC6 writes ONE register. FC15 writes MANY coils. FC16 writes MANY registers. There is no write for input registers or discrete inputs because those are read-only by definition.
Turn on output #5.
A PLC has digital outputs mapped to coils. You want to turn on output #5. Which function code do you send?
- FC1 — read coils
- FC5 — write single coil
- FC6 — write single register
- FC15 — write multiple coils
Read 10 sensor values.
Ten analog sensors are mapped into the slave's input register space. You want all 10 values in one request. Which function?
- FC1 — read coils
- FC3 — read holding registers
- FC4 — read input registers
- FC15 — write multiple coils
The cheat sheet.
If you ever forget — this table is the whole lesson on one page.
The 8 function codes that matter.
- Reads — FC1 coils · FC2 discrete · FC3 holding · FC4 input.
- Writes — FC5 / FC6 single · FC15 / FC16 multiple.
- Bit functions target coils / discrete inputs.
- Word functions target holding / input registers.
Lesson 03 complete.
- You know all 8 standard function codes and what they target.
- You can place any function in the read/write × bit/word grid.
- You can pick the right function for a real-world ask.