Communication Architecture: Master-Slave Q&A

Understand the Modbus master-slave architecture: master/slave roles, unit address, broadcast and polling, and the difference between RTU and TCP

Chapter Objectives

Scenario: Building the Greenhouse Network

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.

Central Gateway polls every 2 s Temp / Humidity Sensor addr = 1 Exhaust Fan Controller addr = 2 Water Pump Controller addr = 3 RS485+ RS485− RS485+ RS485− RS485+ RS485− RS485+ RS485− RS485+ RS485− Request Response next next ① Master asks → slave answers ② Then move on to the next one (polling)
One master, many slaves: the master polls by address in turn (request → response → next slave); slaves never speak on their own initiative.

Why It Matters

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?"

Core Concepts: Roles, Addresses, and Transactions

Master and Slave (Client/Server)

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.

Unit Address / Unit ID

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".

Broadcast (Address 0)

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.

Polling

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.

Transaction Flow

A complete Modbus interaction has only two steps:

Master ──request──▶ Slave (addr=1)
Master ◀──response── Slave (addr=1)

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.

Protocol Details and Byte-Level Example: Same Request, Different Slaves

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:

RequestSlave addressFunction codeStarting addressQuantityCRC-16
Read slave 1010300 0000 02C4 0B
Read slave 5050300 0000 02C5 8F
■ RTU Address ■ Function Code ■ Data ■ CRC
Slave address (frame 1 → frame 2) 01 → 05
Function code (same in both frames) 03
Starting address + quantity (same in both frames) 00 00 00 02
CRC (frame 1 → frame 2, changes with the address) C4 0B → C5 8F
FieldFrame 1 (slave 1)Frame 2 (slave 5)Meaning
Slave address0105The only address byte that changes (▲)
Function code0303Same
Starting address00 0000 00Same
Quantity00 0200 02Same
CRC-16C4 0BC5 8FChanges 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.

Real-World Applications

Case 1: Greenhouse Polling (Main Storyline)

The greenhouse gateway's polling table looks roughly like this:

OrderWho is askedWhat is askedRate
1Slave 1: temperature and humidity sensorRead temperature, humidityEvery 2 s
2Slave 2: exhaust fan controllerRead fan on/off stateEvery 2 s
3Slave 3: water pump controllerRead pump on/off stateEvery 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.

Case 2: Broadcast—Shut Everything Down with One Command

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).

Counter-Example: What Happens with Two Masters

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.

Hands-On Lab Guide

Open the Lab page:

  1. Choose protocol RTU and operation "Read Holding Registers" (FC 03);
  2. Change the slave address from 1 to 5 (starting address 0x0000, quantity 2) and watch the hex frame on the right change;
  3. Focus on this: the address byte goes from 01 to 05, and the CRC at the end changes too (from C4 0B to C5 8F);
  4. Expected result: you get exactly the two frames in this chapter's table.

Chapter Summary and What's Next

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.