Home >Industrial IoT>Industrial IoT
Serial IO series and Siemens PLC S7-200smart Modbus RTU Connection Routine

I. Case Introduction

This case mainly explains the Modbus RTU parameter configuration connection routine of the serial IO series device (this time as a slave device) and the Siemens PLC S7-200smart (hereinafter referred to as Siemens PLC, this time as the host device). This case takes the serial IO series MA01-AACX2220 as an example.

Related article:

Why does the remote serial port I/O module have analog signals and switch signals?

2. Hardware preparation

One MA01-AACX2220 serial port IO device;
One Siemens PLC S7-200smart;
Two 24V power supplies;
Several communication cables;
One computer;

3. Software preparation

STEP 7-MicroWIN SMART software, which can be downloaded from the Siemens official website;
Ebyte IO module configuration test tool, which can be downloaded from the corresponding location of the Ebyte official website https://www.cdebyte.com;



图片.png

4. PLC program preparation

 S7-200 Smart instruction library

1. Siemens has integrated the Modbus RTU master station protocol library (Siemens standard library instructions) in STEP 7-Micro/WIN SMART. Using the Modbus RTU master station instruction library, you can read and write the digital quantity, analog quantity I/O and holding registers of the Modbus RTU slave station.

图片1.png

2. The Modbus RTU master station instruction library can be applied to the CPU integrated RS 485 communication port and CMO1 signal board at the same time. At this time, the integrated RS 485 port uses the instructions in Modbus RTU, Master (v2.0), and the CM01 signal board uses the instructions in Modbus RTU Master2 (v2.0). If there is only one master station, no distinction is made, so we first select MBUS_CTRL here, as shown in the figure:
图片2.png

3. Explanation of the meaning of each parameter of MBUS_CTRL:
EN: Enable switch; must ensure that each scan cycle is enabled (using SM0.0)
Mode: Mode; when it is 1, enable the Modbus protocol function; when it is 0, it returns to the system PPI protocol. When using the modbus protocol, this parameter should be configured to 1.
Baud: Baud rate; the supported communication baud rates are 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200; this parameter should be configured to be consistent with the baud rate configuration of MA01-AACX2220, and the baud rate we configure here is 9600.
Parity: Check mode selection; 0 = no check, 1 = odd check, 2 = even check; this parameter should be configured to be consistent with the check mode configuration of MA01-AACX2220, and the check mode we configure here is 0 (no check).
Port: Port number selection; 0 = RS 485 communication port integrated in CPU, 1 = optional CM 01 signal board; here we configure 0, which represents the RS485 communication port integrated in PLC.
Timeout: Communication timeout setting; the time the master waits for the slave to respond, in milliseconds. The typical setting value is 1000 milliseconds (1 second), and the allowed setting range is 1 - 32767. It should be noted that: This value must be set large enough to ensure that the slave has time to respond. We configure it to 1000 here, and it is generally recommended to be more than 200ms.
Done: Completion bit; when initialization is completed, this bit will automatically set to 1.
Error: Error code; Initialization error code (valid only when Done bit is 1): 0 = No error; 1 = Illegal check selection; 2 = Illegal baud rate selection; 3 = Invalid timeout; 4 = Illegal mode selection; 9 = Invalid port; 10 = Signal board port 1 is missing or not configured;

图片3.png

4. Then we call a Modbus RTU master station read and write subroutine MBUS_MSG, as shown in the figure:

图片4.png

5. Explanation of the meaning of important parameters of MBUS_MSG:
EN: Enable switch; Only one read and write function (ie MBUS_MSG) can be enabled at the same time. Note: It is recommended that each read and write function (ie MBUS_MSG) be activated with the Done completion bit of the previous MBUS_MSG instruction to ensure that all read and write instructions are cycled
First: Read and write request bit; Each new read and write request must be triggered by a pulse
Slave: Slave address: Selectable range 1 - 247, this parameter should be configured to be consistent with the modbus address of MA01-AACX2220. Here we configure the address to be 1
RW: Read and write request; 0 = read, 1 = write Note: 1. Digital output and holding registers support read and write functions 2. Digital input and analog input only support read function;
Addr: Data address of read and write slave;
Select the data type of read and write:
00001 to 0xxxx - Digital output → corresponds to the DO point of MA01-AACX2220 device IO
10001 to 1xxxx - Digital input → corresponds to the DI point of MA01-AACX2220 device IO
30001 to 3xxxx - Analog input → corresponds to the AI point of MA01-AACX2220 device IO
40001 to 4xxxx - Holding register → generally corresponds to the AO point of the device IO. MA01-AACX2220 has no AO point. Count: the number of data; the number of communication data. If it is set to 2 here, it means that 2 registers are used. 


1. DI digital input connection parameters: According to the serial port IO product manual, the DI digital input register is as follows: 

图片.png


Fill in 10001 at the program Address (after conversion to decimal, the register start address needs to be +1 operation), and fill in 2 at Count. PLC program: 

图片5.png


Configure 2 DIs for data communication with MA01-AACX2220
2. AI analog input connection parameters: 


Fill in 30101 at the program Address (after conversion to decimal, the register start address needs to be +1 operation), and fill in 2 at Count. PLC program:

图片.png

Configure 2 AIs for data communication with MA01-AACX2220
3. DO digital output connection parameters:
From the MA01-AACX2220 product manual, we know that the DO digital output registers are as follows:

图片.png

Fill in 1 at the program Address (after conversion to decimal, the register start address needs to be +1), and fill in 2 at Count.
PLC program:

图片7.png


Configure 2 DOs for data communication with MA01-AACX2220

V. Serial IO MA01-AACX2220 parameter configuration preparation
1. You can use the Ebyte IO module configuration test tool to configure the basic parameters and network parameters of MA01-AACX2220. This time, the default parameters of the device are used: Modbus address: 1, baud rate: 9600, data bit: 8, check bit: none, stop bit: 1; (If you need to change to other parameters, you can operate through the advanced settings page, or check the register address in the manual, directly operate the register, and send modbus instructions to operate), as shown in the figure:

图片8.png

At this moment, we have successfully completed the parameter configuration of Siemens PLC and serial IO MA01-AACX2220, and are ready for the Modbus RTU connection communication between the two.