Modbus Protocol Integration in Industrial IoT Systems

Amazeng Technical Team
6 min read
ModbusIoTRS485Industrial Automation

Introduction to Modbus Protocol

Modbus is one of the most widely used protocols in industrial automation systems, developed by Modicon (now Schneider Electric) in 1979 and still going strong today.

Modbus Variants

Modbus RTU

Operates over RS485 or RS232 serial communication. Transmits data in binary format and uses CRC checksum.

Modbus TCP

Works over Ethernet networks via TCP/IP. Faster and more reliable than RTU.

Modbus ASCII

Transmits data using ASCII characters over serial communication. Easier for debugging but slower than RTU.

Modbus RTU Implementation with RS485

RS485-based Modbus implementation used in our ZMA Data Acquisition system:

#define MODBUS_SLAVE_ID 1
#define BAUD_RATE 9600

typedef struct {
    uint8_t slave_id;
    uint8_t function_code;
    uint16_t start_address;
    uint16_t num_registers;
    uint16_t crc;
} modbus_request_t;

uint16_t calculate_crc16(uint8_t *buffer, uint8_t length) {
    uint16_t crc = 0xFFFF;
    for (uint8_t i = 0; i < length; i++) {
        crc ^= buffer[i];
        for (uint8_t j = 0; j < 8; j++) {
            if (crc & 0x0001) {
                crc = (crc >> 1) ^ 0xA001;
            } else {
                crc >>= 1;
            }
        }
    }
    return crc;
}

Function Codes

Most commonly used Modbus function codes:

  • 0x03: Read Holding Registers
  • 0x04: Read Input Registers
  • 0x06: Write Single Register
  • 0x10: Write Multiple Registers

Practical Application Tips

  1. Timeout Management: Set appropriate timeout values for each request
  2. Error Handling: Properly handle exception codes
  3. Bus Termination: Use 120Ω resistors at the beginning and end of RS485 line
  4. Address Planning: Keep slave device addresses organized

Conclusion

Modbus protocol continues to be preferred in industrial systems due to its simplicity and reliability. It can also work with modern systems through bridge solutions in IoT integration.


Our ZMA Data Acquisition system easily integrates into your industrial systems with Modbus RTU support. Contact us for detailed information.