Application Note - Modbus Communication
Application Note - Modbus Communication
1. Hardware Configuration:
Open “Hardware Configuration” window from SIMATIC Manager.
Select CP – 341 RS422/485 Module (with the right MLFB No.) from hardware catalog.
Go to Profibus DP ET 200M IM 153 – X CP – 300 Point to Point CP 341
CP 341 RS422/485.
Add these modules in the racks as per requirement or given hardware architecture e.g.
screen shown below.
1.1. Modbus Master:
Go to properties of CP-341 module & do the settings as shown in figures below.
NOTE:
If ‘CP PtP software’ is not installed Parameter Tab will be disabled.
The OB which used for programming, same should be mentioned in ‘Process
Image’ as shown in above figure.
WARNING: Load Drivers only once in CP – 341. It will never change until you load
another driver. If you tried to load same driver again, system will give message that
“Drivers already exist”
NOTE:
If ‘CP PtP software’ is not installed Parameter Tab will be disabled.
The OB which used for programming, same should be mentioned in ‘Process
Image’ as shown in above figure.
NOTE:
During Load Driver your CPU should be in Manual STOP Mode. In case it is not
then it will prompt that “Put your CPU in STOP mode”
WARNING: Load Drivers only once in CP – 341. It will never change until you load
another driver. If you tried to load same driver again, system will give message that
“Drivers already exist”
2. Progrmming:
2.1. Query from Modbus Master:
Modbus Master has to send query to read data from Modbus Slave. The query
format is fixed for the Modbus (RTU) communication i.e.
Slave Address [Byte]: This is the address of the Modbus Slave. You are setting this
address in (Figure 16: ‘Modbus-Slave’ Protocol property of Modbus Slave).
Function Code [Byte]: To read data from Modbus Slave you have to give function
Code as B#16#03 & to write data in Modbus Slave you have to give function Code as
B#16#10.
Start Address [Word]: In most cases it is zero. In our case we are considering starting
address of DB.
Length [Int]: Here we have to give number of byte which Modbus Master going to read
or write. In figure below we are reading 10 bytes from Modbus Slave.
Here we have used DB 35 to send Modbus Master Query. Refer figure below.
NOTE:
Slave DB (e.g. DB 20 in our case) is used for internal data storage of Modbus Slave, so
the bytes which we have to receive in Modbus Master from Modbus Slave should be
mentioned in Slave DB. Also refer figure 19 & 30 for the same.
Figure 29: STL program for Modbus Slave
Thus all the logic part is completed for Modbus Master & Slave. After this you can
continue with your communication part.
3. Modbus Simulators:
There are basically two simulators we are using during testing of Modbus (RTU)
communication when single Modbus module is available. These two are ModSim32 &
ModScan32.
3.1. ModSim32:
It is used to act as a Modbus Slave module, when you have Modbus Master module
in panel. Now to configure Modbus slave in simulator, below procedure need to be
followed.
First start the ModSim32 simulator.
3.1.1. Step 1: Connection to PC COM Port –
Here first select the COM port for the Modbus communication. Refer figure 31
for the same.
After these settings, the communication with Modbus Master gets established
successfully.
Figure 33: Setting in ModSim1 window to communicate with Modbus Master
NOTE:
During Modbus (RTU) communication ModSim32 should be open during whole
communication.
3.2. ModScan32:
It is used to act as a Modbus Master module, when you have Modbus Slave module
in panel. Now to configure Modbus Master in simulator, below procedure need to be
followed.
First start the ModScan32 simulator.
3.2.1. Step 1: Connection to PC COM Port –
To establish connection with PC COM Port, first connect the ModScan32. Refer
figure 35.
After these settings, the communication with Modbus Slave gets established
successfully.
Figure 38: Setting in ModSca1 window to communicate with Modbus Slave
NOTE:
During Modbus (RTU) communication ModScan32 should be open during whole
communication.
4. Troubleshooting:
5. XYZ: