MODBUS© Protocol is a messaging structure, widely used for master-slave communication between devices.
Only one master (at the same time) is connected to the bus, and oneor several (247 maximum number) slaves nodes are also connected to the same serial bus.
When a MODBUSmaster wants information from a device, the mastersends a message that contains the device’s address,data it wants, and a checksum for error detection. Everyother device on the network sees the message, but onlythe device that is addressed responds.
There are two types of master requests:
- Unicast mode
- Broadcast mode
Fig. 1 Master – Slave communication in MODBUS
Fig. 2 Modbus OSI model
There are three popularMODBUS versions:
• MODBUS ASCII
• MODBUS RTU
• MODBUS/TCP
All MODBUS messages are sent in the same format.
Fig. 3 Modbus Frame
Theonly difference among the three MODBUS types is in howthe messages are coded.
A master addresses a slave by placing the slave address in the address fieldof the message. When the slave returns its response, it places its own address in the response address field to let the master knowwhich slave is responding.
MODBUS has up to 255 function codes
MODBUS ASCII
In ASCII mode each byte in a message is sent as two ASCII characters.
Example : The byte 0X5B is encoded as two characters : 0x35 and 0x42 ( 0x35 =”5″, and 0x42 =”B” in ASCII ).
The serial transmission consist of the following bits:
- 1 start bit
- 7 data bits, least significant bit sent first (A 7-bit data ismore efficient than 8, whentransferring 7-bit ASCII characters).
- 1 bit for paritycheck (even parity by default)
- 1 stop bit
For example the character “:” is sent as :
ASCII char | Hex | Binary |
: | 3A | 111010 |
Fig. 3 Serial transmission of “:” ASCII char
Fig. 4 MODBUS ASCII frame
In ASCII mode, a message is delimited by specific characters as Start-of-frames and End-of-frames. A message must start with a‘colon’ ( : ) character (ASCII 3A hex), and end with a ‘carriage return – line feed’ (CRLF) pair (ASCII 0D and 0A hex).
The allowable characters transmitted for all other fields are hexadecimal 0–9, A–F (ASCII coded). The devices monitor the buscontinuously for the ‘colon’ character. When this character is received, each device decodes the next character until it detects theEnd-Of-Frame.
Was this article helpful?
If you have any suggestions or questions, please leave a comment below.
2019-05-18T23:33:17+03:00By Yasen Stoyanov|Categories: Embedded Systems|Tags: microcontrollers|1 Comment
Related Posts
FreeRTOS: Using Software Timers
January 4th, 2021| 5 Comments
Toolset for Debugging Embedded Programs
November 23rd, 2020| 0 Comments
This site uses Akismet to reduce spam. Learn how your comment data is processed.