Follow our official account and reply with “Introductory Material” to get a comprehensive guide from beginner to advanced on microcontrollers
The development board will guide you, and we will help you soar
Author | Wujì (WeChat:2777492857)
The full text is about2253words, and reading will take about 10 minutes
Previously, someone asked a rather amusing question: What is the difference between Modbus and RS-485?
When I worked on the power PDU project, I used 485 and Modbus, so today I will write an article to comprehensively analyze it.
1. Modbus
Modbus is a master-slave communication protocol used in the field of industrial automation, which can be understood as the chat rules between devices.
For example: Suppose there are several sensors (such as thermometers and hygrometers) in a factory and a control center that need to exchange data. However, they cannot send messages randomly, or it will become chaotic; at this point, Modbus serves as a predefined “conversation template.”
The control center (master device) acts like a boss and can only initiate the conversation, for example: “Temperature meter 1, what is the current temperature?”
The sensors (slave devices) act like employees and must respond according to the template: “Boss, it is currently 25℃.”
This is the core rule of Modbus: one question and one answer, simple and straightforward.
It remains popular today because it is simple enough:
1. Hardware agnostic: Data can be transmitted using various methods, such as network cables, wireless, or 485 bus.
2. Few commands: There are only a few basic operations like “read data” and “write data,” for example, “read the temperature value.”;
3. Highly adaptable: It is compatible with everything from old factory equipment to smart devices.
So remember: Modbus allows devices to understand each other in the simplest way; no need for unnecessary complications.
Next, I will use the analogy of unboxing a package to explain the message structure of Modbus, hoping it helps everyone understand better.
Modbus message template = “Delivery note + Package content”
Your command (for instance, read data/write data) is like the delivery note, and the data is like the goods packed inside the parcel.
Whether the master device (sender) or the slave device (receiver), they must fill the package in the following format:
Next, I will simulate a “dialogue” case between devices using the Modbus protocol (chat rules).
Master device (boss) asks:
Translate to plain language:
03: I want to “read holding registers“
00 00: Start reading from register address 0
C4 0B: Checksum (to ensure the data transmission is correct)
01 03 04 00 25 00 3A A1 C2
Translate to plain language:
03: Executed “read holding registers”
04: Returned 4 bytes of data (2 registers × 2 bytes)
00 25: Value of the first register (decimal 37, e.g., temperature 37℃)
00 3A: Value of the second register (decimal 58, e.g., humidity 58%)
If you have never worked with communication products, feeling this way is normal; once you parse it with a program, you will understand it is actually quite simple.
Industrial devices may use network cables, 485 buses, wireless, etc., to transmit data, but Modbus only standardizes the content format and does not concern itself with the transmission method (just like how delivery does not matter if it is by truck or plane; the format of the delivery note must be uniform).
After understanding the structure, even if the device uses a 30-year-old old protocol in the basement, you can still send commands according to the template using a microcontroller and reliably obtain the data.
2. RS485
Reflecting on the previous explanation, if Modbus is the delivery package, then RS485 is the transportation method for that package, or if Modbus is the content specification for the conversation, RS485 is the telephone line that ensures the conversation can take place.
RS485 is a physical transmission medium that allows a group of devices (such as sensors and controllers) to communicate with each other using two wires in noisy environments and over long distances, and it also supports communication with multiple devices on the same wire.
Why do industrial devices love using RS485 for data transmission?
1. Strong anti-interference: The twisted pair structure (like a spiral network cable) uses two wires (A/B lines) to transmit signals, determining data based on voltage difference (e.g., A being higher than B is “1,” and vice versa is “0”), which can withstand electromagnetic interference from factory equipment.
2. Long transmission distance: Standard transmission distance of 1200 meters; for instance, we used this for a container monitoring system at a port last year.
3. Flexible networking: Up to 127 slave devices can be connected, making it particularly suitable for scenarios where PLC controls multiple motors.
There are some hidden pitfalls I encountered when debugging devices in the past:
When the baud rate is set to 115200, the transmission distance shrinks to less than 50 meters; later, I consulted the manual and understood the golden ratio between transmission speed and distance:
9600bps → 1200 meters
115200bps → 90 meters
76800bps → 200 meters
RS-485 is the physical layer, while Modbus is the protocol layer.
|
|
|
|
Differential voltage signal
|
|
|
Twisted pair/shielded cable
|
|
|
None (depends on hardware balance)
|
|
|
Electromagnetic interference causes waveform distortion
|
Address conflicts lead to data overwriting
|
|
Oscilloscope to observe differential levels
|
Serial port debugging assistant to parse messages
|
|
|
|
RS485 and Modbus are actually independent; you can think of them as two separate entities that can be used together or independently. The Modbus protocol can run on RS485, and it can also run on custom communication protocols, while Modbus can be transmitted through RS485 or through hardware media like Ethernet.
3. RS485 + Modbus
The combination of RS485 and Modbus is very common in the industrial field; although this pairing is harmonious, there are a few points to pay attention to for stable communication debugging:
1. Address allocation should be reasonable just like hotel room numbers cannot be duplicated; it is recommended to use a pyramid distribution method:
PLC main unit → Address 0
First floor devices: 1-15
Second floor devices: 16-30
If there are fewer devices and the application scenario is relatively singular, using a simple sequence like 1.2.3.4… is also acceptable; previously, I worked on a PDU device where one master unit controlled 24 slave units, and that is how we allocated addresses.
2. Leave space for frame intervals: Devices need time to respond; just like rapid-fire questioning can overwhelm the respondent, so when writing programs, we will use a timer to control a frame interval of 3.5 character times.
3. Software solutions to prevent packet loss
If the device communicates at a 10ms interval, the software must handle packet loss prevention, especially in cases with large data volumes, such as the OTA upgrade function for the Wujì microcontroller project, where we download program data from the server. We used a queue + state machine parsing architecture that allows for nearly zero packet loss under stable network conditions, and below is a simple model.
Although RS485 and Modbus are excellent combinations, it also depends on the application scenario, and below are some pairing suggestions.

end

Below are more original works by Wujì on personal growth experiences, industry knowledge, and technical insights.
1.What is the growth path of an electronics engineer like? A 10-year 5000-word summary
2.How to quickly understand others’ code and thinking
3.How to manage too many global variables in microcontroller development projects?
4.Why do most C language development projects for microcontrollers use global variables??
5.How to implement modular programming in microcontrollers? The practicality will astonish you!
6.Detailed explanation of the use and actual effects of callback functions in C language
7.Step-by-step guide to implementing queue code in C language, easy to understand and super detailed!
8.Detailed explanation of pointer usage in C language, easy to understand and super detailed!