You are currently viewing How to use modbus protocol in embedded system
how to use modbus protocol

How to use modbus protocol in embedded system

Spread the love

We know that importance of can and modbus protocol. if you don’t know about this communication protocol then click on hyperlink.

Modbus Protocol Device is a service that provides a connection using Serial communication (RS-485) or Ethernet using the Modbus protocol. for more more information
The Modbus Protocol Device service needs to receive a valid Modbus configuration including the following parameters:

Basic steps to use modscan protocol in embedded

Step 1st: You should need to first download modscan 32 software

official modscan 32 website

Step 2d: Modscan interface look like this

The following function codes are implemented for Modbus Protocol Device protocol:

  1. 01 (0x01) readCoils(int unitAddr, int dataAddress, int count)
  2. 02 (0x02) readDiscreteInputs(int unitAddr, int dataAddress, int count).
  3. 03 (0x03) readHoldingRegisters(int unitAddr, int dataAddress, int count)
  4. 04 (0x04) readInputRegisters(int unitAddr, int dataAddress, int count)
  5. 05 (0x05) writeSingleCoil(int unitAddr, int dataAddress, boolean data)
  6. 06 (0x06) writeSingleRegister(int unitAddr, int dataAddress, int data)
  7. 15 (0x0F) writeMultipleCoils(int unitAddr, int dataAddress, boolean[ ] data)
  8. 16 (0x10) writeMultipleRegister(int unitAddr, int dataAddress, int[ ] data)
How to connect modscan step by step
How to connect modscan step by step

Highlight box show you message (Device Not Connected ). If device is not connected to modscan then msg appear like this.

Step 3rd: If we need to connect device to modscan then follow below steps:

  1. Select connection , in this case we select TCP/IP connection if you want to connect device directly or you connect device directly using COM Port then select specific COM Port.
  2. Select Baud rate in my case i select 19200 baud rate . Note that basically we defined baud rate on the basic of communication distance i.e. for short distance 19200 and for long distance 9600.
  3. Select parity Even/ Odd/ None
  4. Stop bit must be 1
connection of tcp in modscan
connection of tcp in modscan

Step 4th: Below windows show flat steps in modbus communication

  1. Address is one of the most important parameter in communication it depends on modbus communication types
  2. In Master slave combination . ID FR MASTER IS 1
  3. Length is basically depends on user How much length want to read
  4. Modbus point types 01: Coil Register 02: Input register 03: Holding Register 04: Input register
Important steps in modbus communication
Important steps in modbus communication

Modbus protocol mode –

There are two modbus protocol mode which is mostly used

  1. RTU or ASCII (only RTU mode for Ethernet connections).
  2. TCP/IP mode

Timeout parameter – sets the timeout in order to detect or disconnected device.

  • For serial line connection following valid point required
  • port name
  • baudrate
  • bits
  • stops
  • parity
  • similar for ethernet
  • Ethernet
  • ip address
  • port number

Exceptions in Modbus protocol



In this article we saw How to use modbus protocol in embedded system so about this article you have any query then free to ask me.

Also read: Modbus vs can protocol

How to use modbus protocol in embedded

To use Modbus in an embedded system, you will need to follow these steps:
1. Choose a Modbus library or implementation that is suitable for your embedded platform. There are many different Modbus libraries available for different programming languages and platforms. Some popular options include libmodbus, pymodbus, and modbus-tk.
2. Configure your embedded system to communicate over a serial connection using the Modbus protocol. This will typically involve setting up a serial port, configuring the baud rate and other communication parameters, and establishing a connection to the Modbus device or devices that you want to communicate with.
3. Implement the Modbus function codes that you need to use in your application. Modbus has a set of predefined function codes that define the types of actions that can be performed over the Modbus connection, such as reading and writing data from registers, controlling output devices, and requesting diagnostic information. You will need to implement the appropriate function codes in your application to communicate with your Modbus devices.
4. Test and debug your Modbus implementation. You may need to use a tool like Modscan or a Modbus simulator to test and debug your Modbus communication. This will help you ensure that your implementation is working correctly and that you are able to communicate with your Modbus devices as expected.

What is modbus protocol ?

Modbus is a serial communication protocol that was originally developed for use with programmable logic controllers (PLCs). It is a master-slave protocol, meaning that one device (the master) initiates communication and the other devices (the slaves) respond to the master’s requests. Modbus is commonly used in building automation, industrial control, and other applications where devices need to communicate with a central controller.
Modbus uses a simple request-response format for communication between devices. The master device sends a request to a slave device, and the slave device responds with the requested data. Modbus supports a variety of data types, including binary values, integer values, and floating point values.

sachin Pagar

I am Mr. Sachin pagar Embedded software engineer, the founder of Sach Educational Support(Pythonslearning), a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Leave a Reply