Skip to content

Commit 4648adc

Browse files
committed
minor changes
1 parent 4cbeda6 commit 4648adc

File tree

1 file changed

+7
-9
lines changed
  • content/learn/05.communication/07.modbus

1 file changed

+7
-9
lines changed

content/learn/05.communication/07.modbus/modbus.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ Modbus is an open serial communication protocol used for transmitting informatio
1111

1212
Several versions of the Modbus protocol exist such as Modbus RTU, Modbus ASCII, Modbus TCP and Modbus Plus. It is based on a controller-peripheral (formerly known as master-slave) architecture and communication between nodes is achieved with send request and read response type messages. Modbus communicates over several types of physical media such as RS-232/RS-485 or Ethernet. The original Modbus interface ran on RS-232 serial communication but most of the later Modbus implementations use RS-485 because it allows for longer distances, higher speeds and the possibility of multiple devices on a single multi-drop network. The communication over serial RS-485 physical media works with two-wire transmit and receive connections.
1313

14-
On interfaces like RS-485 and RS-232, the Modbus messages are sent in plain form over the network and the network will be dedicated to only Modbus communication. However, if your network requires multiple heterogeneous devices using a more versatile system, TCP/IP over ethernet based protocol is recommended. In this case, Modbus and other types of mixed protocols can co-exist in the same physical interface at the same time. The main Modbus message structure is peer-to-peer, but it can also function on point-to-point and multidrop networks. As mentioned, the Modbus protocol communicates using a controller-peripheral technique in which only one device can initiate transactions, called queries.
14+
On interfaces like RS-485 and RS-232, the Modbus messages are sent in plain form over the network and the network will be dedicated to only Modbus communication. However, if your network requires multiple heterogeneous devices, TCP/IP over Ethernet based protocol is recommended. In this case, Modbus and other types of mixed protocols can co-exist in the same physical interface at the same time. The main Modbus message structure is peer-to-peer, but it can also function on point-to-point and multidrop networks. As mentioned, the Modbus protocol communicates using a controller-peripheral technique in which only one device can initiate transactions, called queries.
1515

1616
![](assets/ModbusProtocol.png)
1717

1818
## How does Modbus work?
19-
Each Modbus message has the same structure, consisting of four basic elements which are present in each message and the sequence and order of these elements are the same for all messages. This allows for easy content parse. The conversation is always started by the controller and when a message is sent, the peripheral interprets the message and responds to it. Modbus sends functions which communicate read and write instructions to the peripheral’s internal memory registers to configure, monitor and control the peripheral’s inputs and outputs. Modbus devices will typically include a register map outlining where the configuration input and output data can be written and read from. You should always refer to the peripheral’s register map of your device to gain a better understanding of its overall operation.
19+
Each Modbus message has the same structure, consisting of four basic elements which are present in each message. The sequence and order of these elements are the same for all messages. This allows for easy content parse. The conversation is always started by the controller and when a message is sent, the peripheral interprets the message and responds to it. Modbus sends functions which communicate read and write instructions to the peripheral’s internal memory registers to configure, monitor and control the peripheral’s inputs and outputs. Modbus devices will typically include a register map outlining where the configuration input and output data can be written and read from. You should always refer to the peripheral’s register map of your device to gain a better understanding of its overall operation.
2020

2121
Modbus requests follow a simple structure:
2222
![](assets/requestFrame.png)
2323

2424
### Device Address
25-
Every peripheral device has its own address which it responds to when addressed by the controller, while all other devices ignore the message if the address doesn't match their own. Device addresses are assigned in the range of 1 - 247, but without additional hardware, the stable number of devices should be limited to 32 as it could cause instability when attaching more devices.
25+
Every peripheral device has its own address which it responds to when addressed by the controller. All other devices ignore the message if the address doesn't match their own. Device addresses are assigned in the range of 1 - 247, but without additional hardware, the stable number of devices should be limited to 32 as it could cause instability when attaching more devices.
2626

2727
### Function Code
2828
The Function code tells the peripheral device if it should read or write data from the internal memory registers. Many of the data types are named from their use in driving relays, for example, a single-bit physical output is called a coil, and a single-bit physical input is called a discrete input or a contact. The following functions are supported by the Modbus poll:
@@ -40,7 +40,7 @@ The Function code tells the peripheral device if it should read or write data fr
4040
The data field contains the requested or send data. In the request form used by the Arduino Modbus library, the data field requires you to enter the starting registers and register count.
4141

4242
### CRC Error Check
43-
CRC stands for Cyclic Redundancy check and is an error detecting code commonly used in digital networks to detect accidental changes in digital data. CRC’s have their name because the check (data verification) value is a redundancy (it expands the message without adding information) and the algorithm is based on [cyclic codes](https://en.wikipedia.org/wiki/Cyclic_code#:~:text=In%20coding%20theory%2C%20a%20cyclic,efficient%20error%20detection%20and%20correction.). They are simple to implement in binary hardware, easy to analyze mathematically, and particularly good at detecting common errors caused by noise in transmission channels.
43+
CRC stands for Cyclic Redundancy check and is an error detecting code commonly used in digital networks to detect accidental changes in digital data. CRC’s have their name because the check (data verification) value is a redundancy (it expands the message without adding information) and the algorithm is based on [cyclic codes](https://en.wikipedia.org/wiki/Cyclic_code#:~:text=In%20coding%20theory%2C%20a%20cyclic,efficient%20error%20detection%20and%20correction.). They are simple to implement in binary hardware, easy to analyse mathematically, and particularly good at detecting common errors caused by noise in transmission channels.
4444

4545
Two bytes are added to the end of every Modbus message for error detection and every byte in the message is used to calculate the CRC. The receiving device then also calculates the CRC and compares it to the CRC from the sending device. If even one bit in the message is received incorrectly, the CRC’s will be different resulting in an error.
4646

@@ -50,7 +50,7 @@ The Modbus specification doesn't define exactly how the data is stored in the re
5050
## Use Modbus with Arduino
5151
Now that you have learned about the basics and functionalities of Modbus, it is time to talk about how you can use your Arduino to establish Modbus communication across devices. You can use your Arduino either as a controller or as a peripheral device depending on the setup. To make your life easier you can use the [Arduino Modbus library](https://www.arduino.cc/reference/en/libraries/arduinomodbus/) which allows you to implement the Modbus protocol over two different types of transport: serial communication over RS485 with RTU or Ethernet and WiFi communication using the TCP protocol. Because the Modbus library is dependent on the [RS-485 library](https://www.arduino.cc/reference/en/libraries/arduinors485/), you must include both of them in your code.
5252

53-
A lot of Arduino boards are Modbus compatible especially if you consider Ethernet-type messages. In case if you want to communicate via RS485, [MKR 485 Shields](https://store-usa.arduino.cc/products/arduino-mkr-485-shield) will help you convert any MKR board into a Modbus compatible device. Check out [this Tutorial](https://docs.arduino.cc/tutorials/mkr-485-shield/mkr-485-communication) to learn more about sending data between two [MKR 485 Shields](https://store-usa.arduino.cc/products/arduino-mkr-485-shield).
53+
A lot of Arduino boards are Modbus compatible especially if you consider Ethernet-type messages. In case you want to communicate via RS485, [MKR 485 Shields](https://store-usa.arduino.cc/products/arduino-mkr-485-shield) will help you convert any MKR board into a Modbus compatible device. Check out [this tutorial](https://docs.arduino.cc/tutorials/mkr-485-shield/mkr-485-communication) to learn more about sending data between two [MKR 485 Shields](https://store-usa.arduino.cc/products/arduino-mkr-485-shield).
5454

5555
When using the [Modbus library](https://www.arduino.cc/reference/en/libraries/arduinomodbus/), sending messages is fairly straightforward as you can see in the examplary request format function below:
5656

@@ -80,7 +80,7 @@ In this example, the starting register is stated as hexadecimal but if we scroll
8080

8181
We can also see that the register for U1 takes up 30107 and 30108 which means that the register count is 2.
8282

83-
With all this information we can now use the function requestFrom() inside the readVoltage() function:
83+
Using the `readVoltage()` function, defined within the parameters we discussed, will retrieve the voltage measurement from the Finder energy meter. Inside you can see how the `requestFrom()` is being called with `Device Address`, `Function Code`, `Starting Register` and `Register Count` as parameters.
8484

8585
```
8686
float readVoltage() {
@@ -102,9 +102,7 @@ float readVoltage() {
102102
}
103103
```
104104

105-
Using the `readVoltage()` functions, defined within given parameters we discussed, it will retrieve the voltage measurement from the Finder energy meter device.
106-
107-
The following section gives an overview of Modbus compatible Arduino boards and the libraries that you can use to enable Modbus protocol capability. Depending on the hardware you use, the libraries might vary, therefore it is important to always check your device specifications. As this article does not cover all types of Modbus implementation as it focuses on Modbus RTU. The following section also includes some more references to read about the different types of implementation in more detail.
105+
The following section gives an overview of Modbus compatible Arduino boards and the libraries that you can use to enable Modbus protocol capability. Depending on the hardware you are using, the libraries might vary, therefore it is important to always check your device specifications. As this article does not cover all types of Modbus implementation and mostly focuses on Modbus RTU, the following section includes more references to read about the different types of implementation in more detail.
108106

109107
### Modbus compatible Boards
110108
- all boards compatible with the [MKR 485 Shield](https://docs.arduino.cc/hardware/mkr-485-shield) and the [MKR ETH Shield](https://docs.arduino.cc/hardware/mkr-eth-shield)

0 commit comments

Comments
 (0)