0% found this document useful (0 votes)
1K views8 pages

Notes On Setting Up Modbus RTU in Tia Portal and S7 - V5.7

Settimg up Modbus in Tia Portal and S7

Uploaded by

Luka Perković
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views8 pages

Notes On Setting Up Modbus RTU in Tia Portal and S7 - V5.7

Settimg up Modbus in Tia Portal and S7

Uploaded by

Luka Perković
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Modbus RTU in Tia portal

Setting up hardware
1. Set up your hardware, if you have it ready and connected to your programming
computer you can add an “Unspecified CPU” and autodetect everything on the bus.

2. In the device view. go to:


a. General -> Protection and security -> Connection mechanisms

3. Here you should check the box marked “Allow access with PUT/GET communication
for remote partner”

4. This step is not necessary but good practice:


a. Go to “System and clock memory” and enable the use of both the system
memory byte and the clock memory byte.
They are useful when programming and if they are active you will not
accidentally overwrite them.

Programming

“Modbus_Comm_Load” Block

1. First locate the “Communication” menu under the instructions.

2. From “Modbus (RTU) add a “Modbus_Comm_Load” block to the second network. I


will explain why later. This block will be run once to set up the modbus instance.
Basically initialising all the communication parameters and functions.

3. In the third network, add a “Modbus_Master” block. This will run continuously and
update all the values to and from the modbus slaves each iteration.
4. NOTE: Depending on the firmware version of your CM or CB module (If it is less than
2.1) you Will need to use the legacy blocks “MB_Comm_Load” and “MB_Master”
otherwise it will not work.

5. Add a new data block to store status info about the Modbus communication. This is
useful later for troubleshooting and displaying current status.
6. Set the parameter “Modbus_Comm_Load_DB”.MODE so it matches the hardware
config of the Communication module. 4 Means half duplex

7. The “REQ” input of the “Modbus_Comm_Load'' block must be high until it reports
done or errors out. To achieve this I used the DONE signal from the
“Modbus_Comm_Load'' DB so the “REQ” input goes low when the communication
block is finished.

8. Add your port, that is the hardware sub-module. The actual RS485 communication
card attached to your system. In my case it is a CM1241 module.
9. Your baud rate should match whatever unit you are trying to communicate with,
standard is usually 9600 baud but you might need to consult your hardware manual.
The same is true for the Parity bit.

10. The “MB_DB” input on the “Comm_Load'' block should be attached to a parameter in
the instance data block of the “Modbus_Master_DB” that was created previously. Use
the parameter named “MB_DB”. See below image.

“Modbus_Master” Block
1. The “MB_ADDR” input should match the address of your modbus slave (or server). If
you have several slaves you can set up code to loop through all the addresses on
this input.
2. The “MODE”, “DATA_ADDR” and “DATA_LEN” inputs are to set up what modbus
register and how many bits/bytes to read or write. Check the I/O manual of your
modbus slave and the siemens help/manual (click on the “Modbus_Master” block
and press F1 to bring up the integrated help manual.) Reading data is generally
mode 0 and writing is mode 1 or 2 depending on the data.

3. Create a data block to store the read data from your modbus slave. The way modbus
works is a bit old fashioned. You will read an amount of data from a slave and that
data will be placed in consecutive words in your data block. To enable this you need
to disable “Optimised block access” in your data block. Right click on your data block,
go to Properties -> Attributes and disable it.

4. In the following image you can see my data block with an array of 10 elements
named “Slave_1” and again, this array or the entire data block should match the data
you get from your slave. If the slave doesn’t send data that can be placed in a single
array you might need to make a custom data block for each slave with different data
types.
5. Connect your array to the “DATA_PTR” input of the “Modbus_Master” block.
Do not point to an individual element of the array, only the array itself. Like I said
previously the data will be placed in consecutive positions in the array.
S7 V5.7 S7-300/400 Addition
● Must add FB611, FB612, FB614, and FB617 to the CPU if they are not already
loaded to the CPU even if they are not addressed in the code.
● UDT580 RECIEVE_Conditions need to be added for some reasons
● The PORT (HW Identifier) on the COMM_LOAD block is the first number in the “I
Address” field int HW config converted to hexadecimal i.e 256 DEC = 100, HEX 264
DEC = 108 HEX i.e: W#16#0108
● It is a good idea to add OB121 and 122 to allow the CPU to go to run mode even
though there are programming errors
● You have to set both the “MODE” parameter and the LINE_PRE parameter of the
Comm_Load Instance DB.
● In OB100 or using a “First_Scan” bit you need to set a bit to trigger the “REQ” input
on the “Comm_Load” FB as well as two bits to trigger the “COM_RST” input of both
the “Comm_Load” FB and the “Modbus_Master/Slave” FB. See M10.3 in the image

● As with S7-1200/1500 the “REQ” input of the “Comm_Load” block must be kept high
until the “Done” parameter is set or it errors out.
● If everything looks correct but you still won’t get the “Comm_Load” block to report
“DONE” and you get area length errors from the CPU diagnostics. Check the
instance DB’s of FB640 and FB641, the “Comm_Load” and “Modbus_Master” blocks.
For some reason they were corrupt/had no data structure associated with them the
first time I created them.
It might have been me that did something wrong or it might just have been a fluke.
But since more people than me have issues using the ET200SP CM PtP module with
the S7-300/400 CPU’s I am leaning towards some type of bug in Siemens
implementation of them. Especially using the Modbus RTU instructions.

You might also like