AUTOMATIZA_LAB
Industrial Control (B2B)

How to Read Modbus Registers: Function Codes, Addresses and Frame Examples

Short answer: in Modbus every piece of data lives in one of four tables (coils, discrete inputs, input registers and holding registers) and is accessed with a function code: 01/02 read bits, 03/04 read 16-bit registers, 05/06 write one value and 15/16 write several. The address printed in the manual (for example 40001) is almost never the one that travels in the frame (0): that is the most common off-by-one error.

The cable is wired correctly (if not, start with the RS485 wiring guide) and yet the device does not answer, or answers with numbers that make no sense. In most cases the problem is not electrical: it is a wrong address, a wrong register type or a byte-order mismatch. This guide explains how Modbus is organized inside and how to read a real frame byte by byte.

The four data tables

Modbus does not store named "variables": it stores four numbered tables, and each device documents which value sits at which position.

  • Coils: read/write bits, typically outputs such as relays. Read with function 01 and written with 05 (one) or 15 (several).
  • Discrete inputs: read-only bits, typically digital inputs. Read with function 02.
  • Input registers: read-only 16-bit values, typically measurements such as temperature or voltage. Read with function 04.
  • Holding registers: read/write 16-bit values, typically parameters and setpoints. Read with function 03 and written with 06 (one) or 16 (several).

The practical rule: measuring usually lives in input registers (04), configuring in holding registers (03/06/16), switching on and off in coils (01/05). But each manufacturer decides, so the device manual rules. Some devices put measurements in holding registers, and then you read them with 03.

Video: how Modbus works under the hood

This RealPars video covers the general picture of Modbus (master/slave, RTU vs. TCP) before diving into the table and function-code detail in this guide — useful if the protocol's overall logic still isn't clear.

The address trap: why 40001 is address 0

Older manuals number the tables with a prefix: coils 0xxxx, discrete inputs 1xxxx, input registers 3xxxx, holding registers 4xxxx. So "40001" means "first holding register". But in the Modbus frame the address is a 16-bit number that starts at 0: the first holding register travels as 00 00.

That causes the most repeated mistake in the field:

  • If the manual says 40001 or "register 1" and your software uses 0-based addresses, you must request address 0.
  • If you ask for 1 instead of 0, you read the next register: a different value that looks "almost" right and is hard to notice.
  • Some programs let you choose "base 0" or "base 1", and each manufacturer documents it differently. When in doubt, test with a value you know (such as the serial number or room temperature) and check that it matches.

What a Modbus RTU frame looks like

An RTU frame has four parts:

  1. Slave address: 1 byte, from 1 to 247 (0 is broadcast and nobody replies).
  2. Function code: 1 byte (03, 06, etc.).
  3. Data: depends on the function.
  4. CRC16: 2 check bytes, sent low byte first.

Between frames the bus must stay silent for at least 3.5 character times: that is how the slave knows the frame is over. Bytes are shown in hexadecimal.

Example 1: read 2 holding registers

Master request to slave 1: read 2 holding registers starting at address 0.

01 03 00 00 00 02 C4 0B

  • 01: slave 1.
  • 03: function "read holding registers".
  • 00 00: starting address 0.
  • 00 02: register count, 2.
  • C4 0B: CRC16.

Slave reply, if register 0 holds 230 and register 1 holds 100:

01 03 04 00 E6 00 64 1A 2F

  • 04: number of data bytes (2 registers × 2 bytes).
  • 00 E6: first register, 0x00E6 = 230.
  • 00 64: second register, 0x0064 = 100.
  • 1A 2F: CRC16 of the reply.

Example 2: switch a coil on

Request: set coil 0 of slave 1 to ON (function 05, the ON value is written as FF 00).

01 05 00 00 FF 00 8C 3A

A relay module replies by repeating exactly the same frame (echo), which confirms the command was executed. To switch it off, send 00 00 instead of FF 00.

Example 3: write a register

Request: write the value 3 into holding register 1 of slave 1 (function 06).

01 06 00 01 00 03 98 0B

The reply is also an echo of the frame you sent.

To build your own frames, check a CRC or decode a captured response without doing the math by hand, use the Modbus RTU calculator: every example in this guide can be reproduced there.

Exceptions: when the slave says no

If the slave receives the request but cannot fulfill it, it answers with the function code plus 0x80 and an exception code. For example, a read request (03) to an address that does not exist returns:

01 83 02 C0 F1

  • 83: function 03 with the error bit set.
  • 02: exception "illegal data address".

The most common codes: 01 illegal function (the device does not support that code), 02 illegal address (you read a register that does not exist, or asked for a count outside the range), 03 illegal value and 04 slave failure. An exception means the wiring and the CRC are fine: the device heard you and answered. That already rules out half of the problems.

32-bit values and decimals

Registers are 16 bits wide. A 32-bit value (an energy counter, a floating-point number) takes two consecutive registers, and manufacturers do not agree on the order: some send the high word first and others the low word. If a 32-bit read gives an absurd number, the two words probably need to be swapped (programs often call this "word swap" or "CDAB").

For decimals, many devices send scaled integers: a 00 FD (253) may mean 25.3 °C, with a 0.1 scale factor listed in the manual. Negative values usually arrive as 16-bit two's complement.

No reply? A diagnostic checklist

  1. Baud rate, parity and stop bits identical on master and slave (many devices ship at 9600 baud, 8 data bits, no parity, 1 stop bit, but check the manual).
  2. Slave address correct and unique on the bus.
  3. Register type correct: try 03 if 04 gives an exception, and the other way round.
  4. Base-0 or base-1 address: try the next and the previous address.
  5. A/B polarity swapped: if the device never answers, it is the first suspect.
  6. Only one master talking on the bus at a time.

To test without writing code, any Modbus query program on a PC works with a USB to RS485 converter like the Waveshare one. And if the destination is an Ethernet network, a Modbus RTU to TCP gateway like the PUSR DR302 or the Waveshare RS232/485/422 with PoE does the translation without touching the device.

Catalog devices driven by these functions

A couple of concrete examples of how the functions above are used, without inventing registers that are not on the listing (each device's exact map is in its manual):

  • Modbus RTU relay modules such as the 8-channel, the 16-channel and the 32-channel: each relay is a coil switched on with function 05, and several at once with 15. The 32-channel listing says the module address can be set up to 255, but the standard reserves addresses 248 to 255, so it is best to stay within 1 to 247.
  • Temperature and humidity sensors with RS485 output such as the Tzone: measurements are read as registers, normally scaled integers (for example tenths of a degree), with the function the manual specifies.

To see the read from the software side, the Node-RED with a Modbus sensor guide shows how the register-read request is configured and the result interpreted, and the quick RS485 vs Modbus guide reviews the difference between the cable and the protocol.

Frequently asked questions

What is the difference between function codes 03 and 04? 03 reads holding registers (read/write, typically parameters) and 04 reads input registers (read-only, typically measurements). If a device does not answer one, try the other: some manufacturers put measurements in holding registers.

Why is my register 40001 not read with address 40001? Because 40001 is a manual numbering: the prefix 4 marks the holding-register table and the number 1 is position 1, which in the frame travels as address 0. Request address 0, or the one that applies depending on whether your program counts from 0 or from 1.

What does exception 02 mean in Modbus? "Illegal data address": the device received the request, but the register you asked for does not exist or the requested count is out of range. It is a good sign: wiring, speed and CRC are fine, you only need to fix the address or the count.

How do I read a 32-bit value in Modbus? It takes two consecutive 16-bit registers. Since manufacturers have no standard order, if the number comes out absurd you have to swap the order of the two words in your program.

How many devices can I connect on one Modbus RTU bus? The protocol allows slave addresses from 1 to 247. In practice a standard RS485 bus supports 32 unit loads; many modern devices draw less than one unit load, but that is stated in each device's data sheet.

Related products

See full ranking →
#1
🏆 Best seller
Waveshare RS232/485/422 to Ethernet Gateway (PoE)

Waveshare RS232/485/422 to Ethernet Gateway (PoE)

RS485/ModbusPoEDIN rail
4.2 · 133 reviews

Supports all three serial standards (RS232/485/422) on one device, so it works for both old instruments with an RS232 port and multi-device RS485 buses. PoE power is a real plus in installations where there's no outlet near the panel — a single Ethernet cable carries both data and power. Confirm whether your Modbus master needs TCP Server or Client mode before buying; the mode is set in software, it doesn't come fixed from the factory.

#2MOLLOM VFD 1.5kW (2HP) — Single-Phase to Three-Phase 220V

MOLLOM VFD 1.5kW (2HP) — Single-Phase to Three-Phase 220V

220V 1P→3P2HPCNC
3.9 · 33 reviews

Accepts single-phase OR three-phase input to 220V three-phase output — the manufacturer's own title spells this out ("Single or Three Phase Input"), so it's not just the typical choice for workshops without a three-phase feed: it also works if your setup is already three-phase and you just want speed control. This is the entry-level model in the MOLLOM G70 family (siblings from 0.75kW/1HP up to 3kW/4HP in the same series), meant for spindles and small CNC motors, not large industrial loads. The output range up to 3000Hz is only useful if your specific spindle takes advantage of it — for a standard 60Hz motor it's irrelevant.

#3
⭐ Top rated
VFD 4kW (5HP) Vector Control — 220V 1-Phase/3-Phase

VFD 4kW (5HP) Vector Control — 220V 1-Phase/3-Phase

Vector control5HP1P/3P
4.3 · 24 reviews

Has vector control (not just scalar V/F), which holds torque better at low RPM — important if you'll be threading or cutting at reduced speed. At 5HP/4kW it covers larger motors than the entry-level model, and accepts both single-phase and three-phase input, giving flexibility depending on the electrical setup available. Rated up to 26A — confirm your wiring and breakers can handle that current before installing. It's made by HKS, sold with a power selector from 0.75kW up to 7.5kW on the same listing — if 5HP is too much or too little for you, sibling variants are a click away without hunting a different listing. One thing to know: it doesn't include a braking resistor — if your application needs to stop the motor fast instead of letting it coast to a stop by inertia, that part is a separate purchase (this catalog doesn't yet have one with a confirmable review history).