Following the previous practice, today we are going to configure the S7-200 as a Master in a Modbus-RTU network. For this, we will need two more functions from the Modbus library, starting from our project in Microwin and inserting the following functions from the library depending on the port to be used in the CPU.
The function MBUS_CRTL is used to initialize, enable, or disable Modbus communication. If executed correctly, the Done bit will be set to 1, which I use to enable message transfer.

Baud and Parity must be equal to the speed configured in the network and in the slaves.
Slave, the address of the Slave for reading/writing depending on RW, 1 for writing and 0 for reading. Addr is the address where we want to write in Modbus, in this example, they are the outputs starting from Q0.0 = 0001 and so on correlatively the value of Count. DataPtr is a pointer to the first memory address we want to write.
As previously done, a memory area V must be reserved for the use of Modbus functions, in the program block -> Assign memory to library.

In this case, when we propose an address, it starts from V0, this is because we have not used any addressing in the memory area.

We start the Modbus Slave, and by default, it appears configured for slave number 1 and the register area 4, but the first thing we need to do is configure the connection, for this we go to Connection, and define the parameters.


And as in our program function, we have set that we are going to write in the output area, we configure it the same way in Slave Definition, and automatically when connecting, the first register is set to 1. This was the output we configured with the Done bit when initializing and activating Modbus communication, and it is written in the slave because the input I0.0 has been activated, since when Firts is activated, the function MBUS_MGS is executed. Perhaps a more practical example would be to activate a drive with the corresponding programming logic, send it the setpoint, etc...


December 30, 2012