[?]: S7-200 and Modbus

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
moat_asa
Posts: 6
Joined: Sat Sep 06, 2008 6:57 am
Location: Saudi Arabia

[?]: S7-200 and Modbus

Post by moat_asa »

Hi all,

I have aproject which requires my S7-200 to communicate with the PDMS through Modbus communcation.

I must send some data to the PDMS, and recieve other control signals from the PDMS.

As I understand from the S7-200 manual, the PLC can act as a master (sending Data), and a slave (Recieving data), Can the PLC work as both sending and recieving data at the same time, or its a totally different concept.

I must send the PDMS the folloing points:

Inputs f the PLC (total of 55 inputs).
Outputs of the PLC (total of 40 outputs).
Memory locations (regesters I use them in my control and I must inform the PDMS about them).

I must recieve from the PDMS about 10 control points.

Any one can help me with that,

Does any one have sample programs using the modbus can share it.

I found a tool here in the forums for testing the modbus communications, but its for **OPEN MODBUS / TCP Communication via CP343-1 and CP443-1**, is it adifferent protocol, can I use it with S7-200 CPU 224xp.

if this tool cant be used with CPU 224xp, is there any tool to do that.

Thanks.
serhan
Posts: 18
Joined: Mon Jun 11, 2007 9:15 pm
Location: Europe

Re: [?]: S7-200 and Modbus

Post by serhan »

A modbus communication can send and receive signals.
If you select your S7200 as master , then you can read the signals from PDMS and you can write the signals to PDMS.
moat_asa
Posts: 6
Joined: Sat Sep 06, 2008 6:57 am
Location: Saudi Arabia

Post by moat_asa »

A modbus communication can send and receive signals.
If you select your S7200 as master , then you can read the signals from PDMS and you can write the signals to PDMS.
yes I think I was miss understanding the functions of the master and the slave, after I have checked the help file in step7-micro I get the same thing your talking about serhan.

here is what i find

the subject is Using the Modbus Slave Instructions:
To use the Modbus slave instructions in your S7-200 program, follow these steps:

1. Insert the MBUS_INIT instruction in your program and execute the MBUS_INIT instruction for one scan only. You can use the MBUS_INIT instruction either to initiate or to change the Modbus communications parameters.

When you insert the MBUS_INIT instruction, several hidden subroutines and interrupt routines are automatically added to your program.

2. Use the Library Memory command to assign a starting address for the V memory required for Modbus Slave Protocol instructions.

3. Place only one MBUS_SLAVE instruction in your program. This instruction is called every scan to service any requests that have been received.

4. Connect the communications cable between Port 0 on the S7-200 and the Modbus master device.

CAUTIONInterconnecting equipment with different reference potentials can cause unwanted currents to flow through the interconnecting cable. These unwanted currents can cause communications errors or damage equipment.Ensure that all equipment that is connected with a communications cable either shares a common circuit reference or is isolated to prevent unwanted current flows.
The accumulators (AC0, AC1, AC2, AC3) are utilized by the Modbus slave instructions and appear in the Cross Reference listing. Prior to execution, the values in the accumulators of a Modbus Slave instruction are saved and restored to the accumulators before the Modbus Slave instruction is complete, ensuring that all user data in the accumulators is preserved while executing a Modbus Slave instruction.
The Modbus Slave Protocol instructions support the Modbus RTU protocol. These instructions utilize the Freeport utilities of the S7-200 to support the most common Modbus functions. The following Modbus functions are supported:

Function Description
1 Read single/multiple coil (discrete output) status. Function 1 returns the on/off status of any number of output points (Qs).
2 Read single/multiple contact (discrete input) status. Function 2 returns the on/off status of any number of input points (Is).
3 Read single/multiple holding registers. Function 3 returns the contents of V memory. Holding registers are word values under Modbus and allow you to read up to 120 words in one request.
4 Read single/multiple input registers. Function 4 returns Analog Input values.
5 Write single coil (discrete output). Function 5 sets a discrete output point to the specified value. The point is not forced and the program can overwrite the value written by the Modbus request.
6 Write single holding register. Function 6 writes a single holding register value to the V memory of the S7-200.
15 Write multiple coils (discrete outputs). Function 15 writes the discrete output values to the Q image register of the S7-200. The starting output point must begin on a byte boundary (for example, Q0.0 or Q2.0) and the number of outputs written must be a multiple of eight. This is a restriction for the Modbus Slave Protocol instructions. The points are not forced and the program can overwrite the values written by the Modbus request.
16 Write multiple holding registers. Function 16 writes multiple holding registers to the V memory of the S7-200. There can be up to 120 words written in one request.
I was a little bit confused, does these functions used by the master device how it can be used.

please, Any one can help?
serhan
Posts: 18
Joined: Mon Jun 11, 2007 9:15 pm
Location: Europe

Post by serhan »

Requests can only done by master device.
Slaves wait for requests and don't do anything if there is no request from a master device.
So if you configure you S7200 as master , you can use these functions to read/write on PDMS.
Also PDMS must be configured as slave device and must be write enabled for the signals you want to write to PDMS registers.
Or PDMS can be master and do the same things to S7200 but this time S7200 must be slave and write enabled for signals you want to read from PDMS registers.

I don't have examples for S7200 modbus configuration or program.
This info I wrote above is a standart modbus master-slave knowledge.
I hope it can be useful for you.
Best Regards.
moat_asa
Posts: 6
Joined: Sat Sep 06, 2008 6:57 am
Location: Saudi Arabia

Post by moat_asa »

Yes sarahan that was very helpful thanks.

At this point my question would be regarding the points that the PDMS (Master) can access it.

for example I want the PDMS to control Q0.4 and Q0.5 only, as I understand from the [MBUS_INIT Instruction (Initialize Slave)] I can control the maximum inputs and outputs that the Master can access, in my case it would be 2, but when I set the value MaxIQ to 2 does that means any 2 inputs or outputs are accessible by the Master or does it means only inputs with the addresses 1001,1002 are accessible from the master and only outputs 0001,0002 are accessible from the master,

Please guys explain more.

Please take a look at the help topic below:
The MBUS_INIT instruction is used to enable and initialize, or to disable Modbus communications. Before the MBUS_SLAVE instruction can be used, the MBUS_INIT instruction must be executed without errors. The instruction completes and the Done bit is set immediately, before continuing to the next instruction. The instruction is executed on each scan when the EN input is on.The MBUS_INIT instruction should be executed exactly once for each change in communications state. Therefore, the EN input should be pulsed on through an edge detection element, or executed only on the first scan.The value for the Mode input selects the communications protocol: an input value of 1 assigns port 0 to Modbus protocol and enables the protocol, and an input value of 0 assigns port 0 to PPI and disables Modbus protocol. The parameter Baud sets the baud rate at 1200, 2400, 4800, 9600, 19200, 38400, 57600, or 115200.The parameter Addr sets the address at inclusive values between 1 and 247.
The parameter Parity is set to match the parity of the Modbus master. The accepted values are:

0-no parity
1-odd parity
2-even parity

The parameter Delay extends the standard Modbus end-of-message timeout condition by adding the specified number of milliseconds to the standard Modbus message timeout. The typical value for this parameter should be 0 on a wired network. If you are using modems with error correction, set the delay to a value of 50 to 100 milliseconds. If you are using spread spectrum radios, set the delay to a value of 10 to 100 milliseconds. The Delay value can be 0 to 32767 milliseconds.

The parameter MaxIQ sets the number of I and Q points available to Modbus addresses 0xxxx and 1xxxx at values of 0 to 128. A value of 0 disables all reads and writes to the inputs and outputs. The suggested value for MaxIQ is 128, which allows access to all I and Q points in the S7-200.
The parameter MaxAI sets the number of word input (AI) registers available to Modbus address 3xxxx at values of 0 to 32. A value of 0 disables reads of the analog inputs. The suggested value for MaxAI to allow access to all of the S7-200 analog inputs is as follows:

0 for CPU 221
16 for CPU 222
32 for CPU 224, 224XP, 226, and 226XM

The parameter MaxHold sets the number of word holding registers in V memory available to Modbus address 4xxxx. For example, to allow the master to access the 2000 bytes of V memory, set MaxHold to a value of 1000 words (holding registers).
The parameter HoldStart is the address of the start of the holding registers in V memory. This value is generally set to VB0, so the parameter HoldStart is set to &VB0 (address of VB0). Other V memory addresses can be specified as the starting address for the holding registers to allow VB0 to be used elsewhere in the project. The Modbus master has access to MaxHold number of words of V memory starting at HoldStart.

When the MBUS_INIT instruction completes, the Done output is turned on. The Error output byte contains the result of executing the instruction. See Modbus Slave Protocol Execution Error Codes for the error conditions that could result from executing the instruction.
Thanks.
Coyote
Posts: 41
Joined: Wed Sep 06, 2006 10:07 am
Location: Slovenia

Post by Coyote »

I think that your second answer is right. It always starts with adress 0001 and 1001.