Ms. Wang's greenhouse has three devices: the temperature and humidity sensor (slave 1), the exhaust fan controller (slave 2), and the water pump controller (slave 3). They cannot chat with each other on their own—they need a "host" to coordinate. Ms. Wang bought a central gateway that asks each device in turn every 2 seconds: "What's your temperature?" "Is your fan running?" "Is your water level normal?" The devices answer one by one, and the gateway aggregates the results on the screen in her office.
This pattern of "one host + many responders" is the Modbus master-slave architecture. There is a very apt metaphor for it—a classroom: the teacher (master) calls a name, and only the student who is called (slave) stands up and answers. Students cannot answer out of turn, and certainly cannot interrupt while the teacher is asking someone else.
Understanding the master-slave architecture is the starting point for understanding every Modbus message. Every frame you see is either "the master asking" or "some slave answering". When troubleshooting, your first reflex should always be: "Who asked? Who was asked? Did they answer?"
Master (client)—the side that asks questions and initiates every communication.
Slave (server)—the side that answers passively; it replies only when it receives a request addressed to itself.
Note: Modbus's "client/server" is not the same thing as a "server" on the web. There is only one criterion here—whoever initiates the request is the master.
Every slave on the network has a unique number in the range 1–247—its "mailbox number". The first byte of a request frame literally means "who this letter is addressed to".
Address 0 is the reserved broadcast address: a request sent to 0 is executed by all slaves, but no slave answers (otherwise everyone would speak at once and the bus would descend into chaos). Broadcast can only be used for "write" operations—a broadcast "read" makes no sense, because nobody answers.
The master asking each slave in turn at a fixed rhythm is polling. The polling cycle is "how often one full round happens"—for example, the greenhouse gateway polls once every 2 seconds. The shorter the cycle, the fresher the data—but the busier the bus.
A complete Modbus interaction has only two steps:
A slave never sends a message on its own. So if "the data isn't coming through", either the master didn't ask, or the slave didn't answer, or it did answer and you didn't look.
Suppose the gateway wants to read the holding registers of "slave 1" and "slave 5" (both starting at 0x0000, quantity 2). The two requests are almost identical—only the address byte and the CRC checksum that changes with it are different:
| Request | Slave address | Function code | Starting address | Quantity | CRC-16 |
|---|---|---|---|---|---|
| Read slave 1 | 01 | 03 | 00 00 | 00 02 | C4 0B |
| Read slave 5 | 05 | 03 | 00 00 | 00 02 | C5 8F |
01 → 05
03
00 00 00 02
C4 0B → C5 8F
| Field | Frame 1 (slave 1) | Frame 2 (slave 5) | Meaning |
|---|---|---|---|
| Slave address | 01 | 05 | The only address byte that changes (▲) |
| Function code | 03 | 03 | Same |
| Starting address | 00 00 | 00 00 | Same |
| Quantity | 00 02 | 00 02 | Same |
| CRC-16 | C4 0B | C5 8F | Changes with the address (▲) |
The CRC covers the whole frame (including the address byte), so when the address changes, the CRC must be recomputed—that is exactly what makes it a "fingerprint": if any single byte is corrupted in transit, the receiver can detect it.
The greenhouse gateway's polling table looks roughly like this:
| Order | Who is asked | What is asked | Rate |
|---|---|---|---|
| 1 | Slave 1: temperature and humidity sensor | Read temperature, humidity | Every 2 s |
| 2 | Slave 2: exhaust fan controller | Read fan on/off state | Every 2 s |
| 3 | Slave 3: water pump controller | Read pump on/off state | Every 2 s |
If a slave fails to answer within a polling cycle, the gateway marks that record in red; after several consecutive failures, it raises a "device offline" alarm.
Late at night the greenhouse temperature drops sharply and Ms. Wang needs to switch off all devices at once. A single broadcast write request (address 0) makes every slave perform a "shutdown", and there is no need to wait for any reply—that is the value of broadcast: one command, executed by everyone.
The cost is equally clear: broadcast has no acknowledgement. If some slave never received it, the master has no way of knowing. So broadcast only fits scenarios where "failure and retry are acceptable" (for example, a coordinated shutdown or reset).
On an RS-485 serial bus, all devices share one pair of wires. If two masters send requests at the same time, the two frames "collide" on the line and the slaves hear nothing but garbage—the CRC check is bound to fail. That is why an RTU network can have only one master per serial bus.
Open the Lab page:
01 to 05, and the CRC at the end changes too (from C4 0B to C5 8F);In this chapter you learned the skeleton of Modbus: one master polling in turn, up to 247 slaves answering by mailbox number, and address 0 as broadcast; over TCP there can be multiple clients, but the question-and-answer rhythm stays the same.
Next, we return to Ms. Wang's greenhouse and answer another question: what data type is the "temperature" inside slave 1 stored as? Where is the exhaust fan's on/off switch hidden? That is the four data types.