How to conduct polling communication between multiple Siemens serial communication modules via ASCII driver protocol

Siemens SIMATIC S7 series serial communication modules, such as CP340, CP341, CP440-1, CP441-1/2, CPU313C/314C-2PtP, and ET200S 1SI 3964/ASCII, support the ASCII driver protocol. These modules can be used for point-to-point communication with instruments, devices, and systems that support third-party ASCII protocols. They are known for their ease of use, flexibility, and reliability in various industrial applications.

This section provides a practical example of how multiple Siemens serial communication modules (CP340/CP341) can communicate using the ASCII driver protocol. The specific implementation method and polling principle discussed here offer valuable guidance for developers working on serial communication between Siemens modules and other ASCII-compatible devices or systems.

System Composition

The system consists of three SIMATIC S7-300 stations, where one acts as the master station responsible for polling data from two slave stations via the ASCII protocol. The master station and the first slave station are equipped with CP341 modules (model 6ES7341-1CH01-0AE0), which have an RS422/485 interface. The second slave station uses a CP340 module (model 6ES7340-1AH02-0AE0) with an RS232C interface. To connect the RS232C interface to the network, a Siemens PC/PPI cable (model 6ES7901-3CB30-0XA0) is used to convert it to an RS485 interface.

2. Cable and Hardware Connection

Detailed hardware connection setup is shown below:

3. Master Station Configuration

Ø CP341 module start address: 256, ASCII protocol mode;

Ø End of message frame standard: 4ms character delay;

Ø Baud rate: 9600bps, 8 data bits, 1 stop bit, no parity;

Ø Interface type: RS485 half-duplex;

Ø Other settings use default values.

4. Slave Station Configuration

The parameter settings for the slave stations (CP341/CP340) must match those of the master station, especially the baud rate, data bits, stop bits, and parity settings. Consistency is crucial for successful communication.

5. Polling Principle

Unlike MODBUS, which uses unique addresses for each device, the ASCII protocol requires manual identification of each station. When the master sends a request, it includes a specific identifier so that the correct slave responds. This approach ensures accurate communication across multiple devices.

Key considerations during multi-station polling include:

Ø Basic mode: Master initiates requests, slaves respond accordingly;

Ø Data frame: Include site identifiers in both sending and receiving frames;

Ø Implementation: Use timed polling, either immediately or after a delay;

Ø Error handling: Implement CRC checks, retries, and timeouts.

6. Polling Mechanism

1. Data Frame Format

To distinguish between the first and second slave stations, a one-word address identifier is added to the message frame. The master sends different frames based on the address, allowing the slaves to determine if the message is intended for them. The response also includes the address identifier so the master knows which slave sent the data. The frame format is as follows:

2. Timing Diagram

3. Flow Chart

Initialization Process: The master station initializes the CP module, resets the receive buffer, and generates the transmit data frame based on the polling counter.

Main Station Polling Process: After initialization, the master manually starts the first poll. It sends a query to the first slave, waits for a response, and then proceeds to the next slave. If no response is received within the timeout period, it skips the station and continues.

Slave Response Process: The slave receives the message, checks the address identifier, and responds only if the message is intended for it. Otherwise, it discards the data without a response.

7. Master Program

1. Initialization

A polling counter is used to switch between different slave stations. In this example, MW2 is defined as the counter, and the program starts by setting it to 1, corresponding to the first slave.

During execution, the counter is updated, and the address identifier in the transmitted data block is modified accordingly. For example, DB13 is used as the transmission data block, and DB13.DBW0 is the address identifier word.

2. Start Sending

After initialization, the send function is triggered manually. FB8 (P_SND_RK) is called to send data to the slave. Once the first transmission is complete, the automatic polling flag is activated.

The status of the transmission is returned through FB8. If an error occurs, the function is restarted.

Upon completion, the receive job is initiated, and a timeout timer (T11) is started. If no data is received within the time limit, the system moves to the next station.

3. Receive Slave Data

Once the transmission is done, the receive function is started. The received data is stored in the receive buffer (DB14).

4. Receiving Completed

After receiving, the system checks for errors or timeouts. If an issue occurs, the current station is skipped.

The address identifier in the received data determines the source station. The data is moved to the designated storage area, and the receive buffer is cleared.

The receive flag is reset, the polling counter is updated, and a delay timer is started before moving to the next station.

8. Slave Program

The slave program is simpler than the master’s. For example, the second slave station uses FB2 (P_RCV) to receive data from the network. If the data matches its address, it processes the data and sends a response back to the master.

If the data does not match the address, it is simply discarded.

9. Experimental Results

After setting up the network and downloading the programs to the respective CPUs, the system can be started by activating the manual polling flag M30.0. Monitoring the variable table shows that the master station continuously communicates with both slaves, sending and receiving data cyclically.

The Fiber Optic Test Equipment

fiber stripper,fiber cleaver,layer 3 epon olt,smart Optical Power Meter,Visual Fault Locator

Shenzhen Runtop Technology Co.LTD , https://www.runtoptech.com