Menu

Modbus Function Codes

Modbus function code overview covering the common public read and write operations, register-type mapping, and exception behavior.

Categories:

What They Are

A Modbus function code is the operation byte that tells the server what to do with the request. It defines whether the request reads or writes data and which register family is being accessed.

If the wrong function code is used for the expected data type, the device can respond with an exception even though transport and addressing are otherwise correct.

Within Modbus, function codes are the line between “the link is up” and “the request actually matches the device model.” The client can have the right IP address, serial settings, and register offset and still fail if the request asks for the wrong data family or unsupported write behavior.

That is equally true on Modbus RTU and Modbus TCP. The transport changes how the request gets there, but not which operation byte the server expects for coils, discrete inputs, input registers, or holding registers.

Common Public Function Codes

CodeNameTypical Data FamilyAccess
01Read CoilsModbus CoilsRead
02Read Discrete InputsModbus Discrete InputsRead
03Read Holding RegistersModbus Holding RegistersRead
04Read Input RegistersModbus Input RegistersRead
05Write Single CoilModbus CoilsWrite
06Write Single RegisterModbus Holding RegistersWrite
15Write Multiple CoilsCoilsWrite
16Write Multiple RegistersHolding RegistersWrite
23Read/Write Multiple RegistersHolding registersCombined read/write

Register Family Mapping

Register FamilyRead Function CodeWrite Function Code
Modbus Coils0105, 15
Modbus Discrete Inputs02None
Modbus Input Registers04None
Modbus Holding Registers0306, 16

Why Function-Code Mismatch Happens

Failure PatternWhat Usually HappenedPractical Result
Wrong data family assumptionA holding register was treated like an input register, or a status bit was treated like a coilThe device returns an exception or wrong data
Write path assumed too broadlyThe device supports reads but not the requested write behaviorReads work while writes fail
Device profile is narrower than the generic specThe protocol manual or firmware supports only a subset of public operationsThe request is valid Modbus in theory but not on that product
Gateway configuration used the wrong operationThe point type and function code drifted apart during mappingCommissioning looks like an addressing error when it is actually an operation mismatch

Exception Behavior

If a device rejects the request, it returns an exception response with the function code flagged and an exception code explaining the failure.

Exception CodeMeaningCommon Real-World Cause
01Illegal FunctionWrong function code for the device or register family
02Illegal Data AddressWrong address or off-by-one mapping
03Illegal Data ValueValue out of valid range
04Server Device FailureInternal device-side failure

Commissioning Notes

Function-code validation works best when it is tied to one known-good point in each data family the project actually uses. For example, confirm one coil, one input register, and one holding register before scaling up the full point list. That quickly separates transport health from data-family or write-path mistakes.