Application of MODBUS Protocol in Microcontrollers (2024)

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

Application of MODBUS Protocol in Microcontrollers (1)

Fig. 1 Master – Slave communication in MODBUS

Application of MODBUS Protocol in Microcontrollers (2)

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.

Application of MODBUS Protocol in Microcontrollers (3)

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 charHexBinary
:3A111010

Application of MODBUS Protocol in Microcontrollers (5)

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

Share This Story, Choose Your Platform!

Related Posts

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Application of MODBUS Protocol in Microcontrollers (2024)
Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 6630

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.