What are the implementation methods of Modbus communication in Siemens PLC?

Jul 23, 2025Leave a message

Modbus is a widely used serial communication protocol in industrial automation, known for its simplicity, reliability, and ease of implementation. As a Siemens PLC supplier, I often encounter customers who are interested in implementing Modbus communication in their Siemens PLC systems. In this blog post, I will discuss the various implementation methods of Modbus communication in Siemens PLCs, including the hardware requirements, software configuration, and programming considerations.

Hardware Requirements

Before implementing Modbus communication in a Siemens PLC, you need to ensure that your PLC has the necessary hardware capabilities. Most modern Siemens PLCs, such as the Siemens PLC S7 200, Siemens PLC S7 1200, and Siemens PLC S7 1500, support Modbus communication either natively or through the use of communication modules.

Siemens PLC S7 2007_

  • Communication Interfaces: The most common communication interfaces used for Modbus communication are RS-232 and RS-485. RS-232 is a single-ended communication interface suitable for short-distance communication, while RS-485 is a differential communication interface that can support longer distances and multiple devices on the same network.
  • Communication Modules: If your PLC does not have a built-in Modbus communication interface, you can use a communication module to add Modbus support. Siemens offers a range of communication modules, such as the CM 1241 RS485 and CM 1542-5, which can be easily integrated into your PLC system.

Software Configuration

Once you have the necessary hardware in place, you need to configure the software settings for Modbus communication in your Siemens PLC. The software configuration process may vary depending on the type of PLC and the programming software you are using.

  • Step 1: Select the Modbus Protocol: In the programming software, you need to select the Modbus protocol you want to use. Siemens PLCs support both Modbus RTU and Modbus TCP protocols. Modbus RTU is a serial communication protocol used for communication over RS-232 or RS-485, while Modbus TCP is an Ethernet-based protocol used for communication over a network.
  • Step 2: Configure the Communication Parameters: You need to configure the communication parameters, such as the baud rate, parity, stop bits, and slave address. These parameters must be the same on both the master and slave devices to ensure successful communication.
  • Step 3: Define the Data Areas: You need to define the data areas in your PLC where the Modbus data will be stored. These data areas can be memory bytes, words, or double words, depending on the type of data you want to exchange.

Programming Considerations

After configuring the software settings, you need to write the programming code to implement Modbus communication in your Siemens PLC. The programming code will depend on the type of Modbus protocol you are using and the specific requirements of your application.

  • Modbus RTU Programming: For Modbus RTU communication, you can use the built-in Modbus functions provided by the Siemens programming software. These functions allow you to read and write data from/to Modbus slave devices. You need to call these functions in your program and pass the appropriate parameters, such as the slave address, function code, and data address.
  • Modbus TCP Programming: For Modbus TCP communication, you can use the TCP/IP communication functions provided by the Siemens programming software. These functions allow you to establish a TCP connection with the Modbus TCP server and exchange data using the Modbus TCP protocol. You need to create a TCP connection, send Modbus requests, and receive Modbus responses in your program.

Example of Modbus RTU Programming in Siemens PLC S7 1200

Here is an example of how to implement Modbus RTU communication in a Siemens PLC S7 1200 using the TIA Portal programming software:

// Define the Modbus RTU communication parameters
VAR
    ModbusRTU : FB_ModbusRTU;
    ModbusConfig : T_ModbusRTUConfig;
    ReadRequest : T_ModbusRTURequest;
    WriteRequest : T_ModbusRTURequest;
    ReadResult : T_ModbusRTUResult;
    WriteResult : T_ModbusRTUResult;
END_VAR

// Configure the Modbus RTU communication
ModbusConfig.BaudRate := 9600;
ModbusConfig.Parity := 'E';
ModbusConfig.StopBits := 1;
ModbusConfig.SlaveAddress := 1;

// Initialize the Modbus RTU function block
ModbusRTU(
    Config := ModbusConfig,
    Request := ReadRequest,
    Result := ReadResult
);

// Read data from a Modbus slave device
ReadRequest.FunctionCode := 3;
ReadRequest.StartAddress := 0;
ReadRequest.NumRegisters := 10;

// Call the Modbus RTU function block to read data
ModbusRTU();

// Check the result of the read operation
IF ReadResult.Status = 0 THEN
    // Data read successfully
    // Process the data
ELSE
    // Error occurred
    // Handle the error
END_IF;

Example of Modbus TCP Programming in Siemens PLC S7 1500

Here is an example of how to implement Modbus TCP communication in a Siemens PLC S7 1500 using the TIA Portal programming software:

// Define the Modbus TCP communication parameters
VAR
    ModbusTCP : FB_ModbusTCP;
    ModbusConfig : T_ModbusTCPConfig;
    ReadRequest : T_ModbusTCPRequest;
    WriteRequest : T_ModbusTCPRequest;
    ReadResult : T_ModbusTCPResult;
    WriteResult : T_ModbusTCPResult;
END_VAR

// Configure the Modbus TCP communication
ModbusConfig.IPAddress := '192.168.0.1';
ModbusConfig.Port := 502;
ModbusConfig.SlaveAddress := 1;

// Initialize the Modbus TCP function block
ModbusTCP(
    Config := ModbusConfig,
    Request := ReadRequest,
    Result := ReadResult
);

// Read data from a Modbus TCP server
ReadRequest.FunctionCode := 3;
ReadRequest.StartAddress := 0;
ReadRequest.NumRegisters := 10;

// Call the Modbus TCP function block to read data
ModbusTCP();

// Check the result of the read operation
IF ReadResult.Status = 0 THEN
    // Data read successfully
    // Process the data
ELSE
    // Error occurred
    // Handle the error
END_IF;

Troubleshooting Modbus Communication Issues

When implementing Modbus communication in Siemens PLCs, you may encounter some issues, such as communication errors, data corruption, or device not responding. Here are some common troubleshooting steps you can take:

  • Check the Hardware Connections: Make sure that all the hardware connections are secure and that the communication cables are properly terminated.
  • Verify the Communication Parameters: Check that the communication parameters, such as the baud rate, parity, stop bits, and slave address, are the same on both the master and slave devices.
  • Check the Modbus Function Codes: Make sure that you are using the correct Modbus function codes for the type of data you want to read or write.
  • Monitor the Communication Traffic: Use a communication analyzer or a Modbus diagnostic tool to monitor the communication traffic and identify any errors or issues.

Conclusion

Implementing Modbus communication in Siemens PLCs is a straightforward process that requires the right hardware, software configuration, and programming skills. By following the steps outlined in this blog post, you can easily implement Modbus communication in your Siemens PLC system and integrate it with other Modbus-compatible devices.

If you are interested in purchasing Siemens PLCs or need further assistance with Modbus communication implementation, feel free to contact us for a consultation. We are a leading Siemens PLC supplier with extensive experience in industrial automation and can provide you with the best solutions for your specific requirements.

References

  • Siemens TIA Portal Documentation
  • Modbus Protocol Specification