Overview
Using a SIMATIC S7-300 CPU317 with a CM PtP communication module (order number 6ES7137-6AA00-0BA0 / SIPLUS 6AG1137-6AA00-0BA0) as a Modbus RTU master over RS485 is a common requirement when distributed ET 200S stations must poll third-party devices (inverters, energy meters, RTUs, IEDs) but the application still has to run on a classic S7-300 controller programmed with STEP 7 V5.5. The CM PtP does not natively implement the Modbus protocol; Modbus is delivered as a ready-made function block library (FB640 "MB_MASTER" and FB641 "MB_SLAVE") which the user calls from the application and which drives the CM PtP through the standard point-to-point system functions.
The most common cause of an apparently "non-working" configuration is the mismatch between the library target platform and the actual project platform. The example project published on the Siemens support site for "Modbus Master for S7-1500" cannot be imported into STEP 7 V5.5, and the S7-1500 FB blocks are not downward compatible. This article documents the STEP 7 V5.5 path specifically, with the correct library, parameterization, hardware setup, and verification steps.
Module Identification and Variants
The CM PtP used here is the SIMATIC ET 200S serial interface module, not a slot module that plugs into the S7-300 rack. It is installed in an ET 200S head station (IM151-1 with PROFIBUS or PROFINET interface) and addressed from the S7-300 CPU as distributed I/O. The relevant catalog numbers are:
| Order Number | Description | Interface | Use |
|---|---|---|---|
| 6ES7137-6AA00-0BA0 | SIMATIC DP, ET 200S CM PtP | RS232 / RS422 / RS485 selectable | Standard variant |
| 6AG1137-6AA00-0BA0 | SIPLUS ET 200S CM PtP | RS232 / RS422 / RS485 selectable | Extended temperature / conformal coating |
| 6ES7151-1AA05-0AB0 | IM151-1 STANDARD (PROFIBUS) | PROFIBUS DP slave | ET 200S head station (typical) |
| 6ES7151-1BA02-0AB0 | IM151-1 HIGH FEATURE (PROFINET) | PROFINET IO device | ET 200S head station (PROFINET) |
| 6ES7392-1AJ00-0AA0 | Front connector (20 pin) | — | Required for wiring |
The two-channel variant 6ES7137-6BD00-0BA0 is also available if a second independent serial port is required, but the FB library interface and configuration procedure described here apply identically.
Prerequisites
- STEP 7 V5.5 with SP4 or later (SPx) installed, including the optional package "Modbus_Master_PtP" or "SIMATIC Modbus/USS Communication". This package is included on the STEP 7 DVD as an add-on library and is also available in the Siemens Knowledge Base as entry ID 75226762.
- SIMATIC S7-300 CPU317-2 DP (or compatible) with sufficient work memory. The MB_MASTER instance DB consumes approximately 1 KB per channel.
-
ET 200S head module (IM151-1) with the CM PtP module plugged in and the correct terminal module (
6ES7193-4CA40-0AA0for the CM PtP slot). - STEP 7 GSD file for the ET 200S head module, imported via HW Config → Options → Install GSD File.
- Front connector and a shielded RS485 cable, terminated at both ends with 120 Ω.
- Modbus slave device with its user manual showing the register map, supported function codes, and default address (typically 1).
Hardware Configuration in HW Config
- Open the S7-300 station in SIMATIC Manager → HW Config.
- Insert the CPU317 onto rack 0, slot 2. Open its properties, set the MPI/PROFIBUS address as required.
- Drag a DP master system from the catalog and place an IM151-1 STANDARD as a DP slave. Set its PROFIBUS address to a free value (for example, 3).
- Open the IM151-1 and add a CM PtP (6ES7137-6AA00-0BA0) into slot 1 of the ET 200S station.
- Double-click the CM PtP icon to open Properties → Parameter Assignment.
On the Protocol tab, set:
-
Protocol selection = Modbus master (RTU) — this is critical; selecting "ASCII" or "RS232 transparent" will cause FB640 to return status
0x0001("wrong protocol") on the first call. -
Character delay = 4 ms (matches a 1-stop-bit, no-parity frame at 19200 baud; recalculate as
(3.5 × bits-per-character) / baudfor other rates).
On the Interface tab, set the physical layer to RS485 two-wire (half-duplex). Match baud rate, parity, data bits, and stop bits to the slave device, for example 19200, 8, E, 1.
Confirm the input/output address assignment — the CM PtP occupies 8 bytes of input and 8 bytes of output area as default; record the I/O start address because the library uses symbolic names that resolve to these addresses.
RS485 Wiring and Termination
The 20-pin front connector of the CM PtP has the following assignments when set to RS485:
| Pin | Signal | Function |
|---|---|---|
| 1 | T/R (A) | Receive/Transmit non-inverting |
| 11 | T/R* (B) | Receive/Transmit inverting |
| 2 | GND | Signal ground (must be connected) |
| 12 | +5V | Pull-up reference (do not use as supply) |
| 3 | Shield | Cable shield clamp, low-impedance bond to PE |
STATUS = 0x0E02 ("no response, CRC error") repeatedly.Use a twisted pair with overall shield (for example Belden 9841 or equivalent), keep the segment under 1200 m at 19200 baud, and bond the shield to PE at the cabinet entry only — do not loop the shield through multiple devices.
Installing the Modbus Master Library
- In SIMATIC Manager, open the Options → Install Library dialog.
- Select the file
Modbus_Master_PtP_Vxx.xx.zip(or the .ax variant) provided with the entry 75226762. The library must be the V5.5-compatible build; the V13/V14 TIA build will not register. - Open the library and copy the following objects into your S7 program under Program blocks:
- FB640 — MB_MASTER (Modbus master, multiple instance capable)
- FB641 — MB_SLAVE (Modbus slave, included for completeness)
- UDT 600 — MB_MASTER_PARAM (data structure for the configuration DB)
- UDT 601 — MB_MASTER_DATA (data structure for the data buffer)
- Create a shared data block (DB640, recommended) of type MB_MASTER_PARAM. This DB holds static parameters such as the configured COM port, the response timeout, and the inter-frame delay.
FB640 "MB_MASTER" Interface
The block signature in STEP 7 V5.5 is:
CALL FB 640, DB_Master
REQ := M0.0 // rising edge triggers a request
MB_ADDR := 1 // Modbus slave address (1…247)
MODE := B#16#03 // function code: 0x03 = Read Holding Regs
DATA_ADDR := W#16#0000 // start address in slave (0-based)
DATA_LEN := B#16#0A // number of registers to read (10)
DATA_PTR := P#DB10.DBX0.0 WORD 10 // pointer to 10-word buffer
DONE := M10.0 // 1 cycle pulse on success
ERROR := M10.1 // 1 = error detected
STATUS := MW12 // extended status / error code
COM_RST := FALSE // set TRUE to re-initialise on first run
Parameter reference:
| I/O | Type | Meaning |
|---|---|---|
| REQ | BOOL | Trigger. The block latches the request on a rising edge and processes it to completion even if REQ falls. |
| MB_ADDR | INT | Modbus slave address, 1 to 247. 0 is the broadcast address and is only valid for write function codes (05, 06, 15, 16). |
| MODE | BYTE | Function code. Supported: 0x01 (coils), 0x02 (inputs), 0x03 (hold regs), 0x04 (input regs), 0x05 (write single coil), 0x06 (write single reg), 0x0F (write multiple coils), 0x10 (write multiple regs). |
| DATA_ADDR | WORD | Starting register/coil address in the slave. Slave manuals list this as 1-based; the block subtracts 1 internally if the configuration bit "Address base 0" is set in DB640. |
| DATA_LEN | BYTE | Number of objects (1…125 words, 1…2000 coils). |
| DATA_PTR | ANY | Pointer to the local data buffer. Must be a DB of WORD or BOOL type and large enough to hold DATA_LEN elements. |
| DONE | BOOL | Set for one cycle when the transaction completes successfully. |
| ERROR | BOOL | Latched error flag. Reset only by a new REQ rising edge or COM_RST. |
| STATUS | WORD | Detailed status. 0x0000 = OK. See "Diagnostics" below. |
| COM_RST | BOOL | Set TRUE on the first cycle (or after a re-configuration) to re-initialise the port. Resets automatically after one cycle. |
Calling the Master in OB1
Place the call in OB1 (cyclic, free-running) or in a time-of-day OB. Do not call it in OB35 at 100 ms if the slave response timeout is shorter, because the block needs to service the next character within the character delay window. The reference call is:
// OB1 - Cyclic
U "StartPoll"; // boolean from HMI or sequencer
FP "HelpFlag"; // edge memory
= M 0.0; // REQ trigger for FB640
CALL "MB_MASTER", "Inst_Master_DB"
REQ :=M0.0
MB_ADDR :=1
MODE :=B#16#3
DATA_ADDR:=L#0
DATA_LEN :=B#16#10
DATA_PTR :=P#DB20.DBX0.0 BYTE 32
DONE :=M100.0
ERROR :=M100.1
STATUS :=MW102
COM_RST :=FALSE
DB20 must be created first with at least 32 bytes (16 words) and named, for example, Slave_1_Input_Regs. The block copies the slave response into DB20 starting at byte 0; the application can then SCALE or process the registers as engineering units.
Multiple Slaves and Polling Sequence
Use one instance DB of FB640 per channel (not per slave). For multiple slaves, sequence the calls in OB1 by latching REQ of the next call on the DONE pulse of the previous one. A typical pattern for three slaves is:
// Slave 1 - 16 holding registers
A "Go_Slave1"
FP "E_S1"
= M 0.0
CALL "MB_MASTER", "Inst_M1" ...
A M 100.0 // DONE of slave 1
S "Go_Slave2" // arm next call
// Slave 2 - 8 input registers
A "Go_Slave2"
FP "E_S2"
= M 0.1
CALL "MB_MASTER", "Inst_M2" ...
A M 101.0
S "Go_Slave3"
Diagnostics and STATUS Codes
The STATUS word of FB640 is the primary diagnostic channel. The most common values returned by the STEP 7 V5.5 build of the Modbus_Master_PtP library are:
| STATUS (hex) | Meaning | Remedial Action |
|---|---|---|
| 0x0000 | No error | — |
| 0x0001 | Protocol not configured as Modbus in HW Config | Re-open the CM PtP properties and select "Modbus master (RTU)" as the protocol. |
| 0x0002 | Address error (MB_ADDR out of range, broadcast on read) | Restrict MB_ADDR to 1…247 for reads. |
| 0x0003 | Invalid MODE / function code | Use only the codes listed above. |
| 0x0004 | DATA_PTR not a valid DB pointer or wrong length | Re-declare the pointer; it must be P#DBxx.DBXy.0 BYTE n where n ≥ DATA_LEN * 2. |
| 0x0006 | Busy — previous request still in progress | Wait for DONE; do not retrigger. |
| 0x0E00 | CM PtP diagnostic interrupt — check SF LED | Inspect the diagnostic buffer of the ET 200S head module. |
| 0x0E01 | Parity / framing error from CM PtP | Verify baud rate / parity / stop bits match the slave. |
| 0x0E02 | CRC error or timeout (no response within response_timeout) | Check cable, termination, slave address, slave power. |
| 0x0E03 | Modbus exception code received (see MB exception code in MB10) | Slave returned an exception; consult the slave manual for the cause (illegal address, illegal data value, etc.). |
| 0x0E04 | Inter-character timeout during frame reception | Increase character delay or check for EMI on the cable. |
| 0x0E05 | Buffer overflow (DATA_LEN too large for pointer) | Increase the target DB or reduce DATA_LEN. |
| 0x0FFF | Internal error — report with serial number | Contact Siemens support with the project archive. |
Additionally the block stores the last Modbus exception code (the value the slave returns in the response) in the byte at offset 10 of the instance DB. Common slave exceptions are 0x01 (illegal function), 0x02 (illegal data address), 0x03 (illegal data value), and 0x06 (slave device busy).
Configuration DB (DB640 / MB_MASTER_PARAM)
The static parameters of the CM PtP channel are kept in a shared DB of type UDT 600. The default values for a 19200/8/E/1 master are:
| Offset | Name | Type | Default | Meaning |
|---|---|---|---|---|
| 0.0 | baud | DWORD | 19200 | Baud rate |
| 4.0 | parity | BYTE | 2 (Even) | 0=none, 1=odd, 2=even |
| 5.0 | data_bits | BYTE | 8 | 7 or 8 |
| 6.0 | stop_bits | BYTE | 1 | 1 or 2 |
| 7.0 | flow_control | BYTE | 0 (off) | RS232 only; ignore for RS485 |
| 8.0 | resp_timeout | TIME | T#1s | Time the master waits for the first response character |
| 12.0 | char_delay | TIME | T#4ms | Inter-character gap used to delimit frames |
| 16.0 | retries | BYTE | 2 | Retransmissions on CRC or timeout |
STATUS = 0x0001 on the first call. The HW Config settings are the source of truth; keep DB640 in sync by editing both, or set DB640 values via HMI so that the operator can change them at runtime and the block re-initialises on COM_RST.Verification and Commissioning Checklist
- Compile the S7 program and download to the CPU317. After download, set the CPU to RUN.
- Open Monitor/Modify on the MB_MASTER instance DB and confirm that the static parameters match HW Config.
- Force a rising edge on REQ and observe STATUS. The expected sequence is:
- T+0: REQ = 1, STATUS = 0x0006 ("busy")
- T+5..30 ms: STATUS = 0x0006 with DONE = 0
- T+50..80 ms: DONE = 1 for one cycle, STATUS = 0x0000
- Open the data DB in the Monitor view; the response data should appear at the pointer address.
- Disconnect the slave cable to verify error path: STATUS should become 0x0E02 after the response timeout.
- Reverse A and B at the master terminal to verify exception handling: STATUS should become 0x0E01 (framing error) or 0x0E02 (CRC error).
- Check the SF LED on the CM PtP and on the IM151-1 head module. With the configuration correct, both SF LEDs should be off during normal operation.
- Read the diagnostic buffer of the ET 200S head module: PLC → Module Information → Diagnostic Buffer. There should be no entries during healthy operation.
Troubleshooting Matrix
| Symptom | Likely Cause | Action |
|---|---|---|
| FB640 returns STATUS 0x0001 immediately | HW Config protocol is not "Modbus master" | Open CM PtP properties, select "Modbus master (RTU)", re-download HW Config. |
| STATUS 0x0E02 (timeout) on every call | Wrong slave address, A/B reversed, no termination, or slave not powered | Verify slave address with a Modbus poll tool, swap A/B at the master, check terminator, check supply. |
| STATUS 0x0E02 occasionally | EMI on cable, slave too slow, character delay too short | Use shielded cable, increase resp_timeout to T#2s, raise char_delay to T#5ms. |
| STATUS 0x0E01 (framing error) | Mismatched baud / parity / stop bits | Re-check the slave documentation and align all four parameters exactly. |
| STATUS 0x0003 (invalid MODE) | Function code not supported by the slave | Query the slave for the list of supported function codes; some slaves do not implement 0x0F / 0x10. |
| STATUS 0x0E03 (exception code) with code 02 in instance DB | Reading/writing an address outside the slave map | Cross-check DATA_ADDR with the slave's register map; subtract 1 if the manual is 1-based and "Address base 0" is enabled. |
| DONE never goes high, STATUS 0x0006 forever | REQ retriggered before the previous call finished | Gate the next REQ with the DONE pulse of the previous call. |
| SF LED on CM PtP steady on | Configuration mismatch between DB640 and HW Config | Set COM_RST := TRUE for one cycle, then re-load HW Config and software together. |
| No communication, but STATUS is 0x0000 | DATA_PTR points to a DB that is optimised (S7-300 blocks are not optimised, but instance pointer may be wrong) | Re-declare the pointer in STL and confirm it is byte-addressed with sufficient length. |
| Project compiled for TIA Portal library will not open in STEP 7 V5.5 | Wrong library version | Re-install the STEP 7 V5.5 build of "Modbus_Master_PtP" from the Siemens Knowledge Base entry 75226762. |
Limitations and Edge Cases
- Number of slaves per channel: FB640 can address up to 247 slaves sequentially, but the ET 200S CM PtP only supports one logical channel — polling many slaves means round-robin scheduling in the user program.
- Broadcast writes: MB_ADDR = 0 is supported only for function codes 0x05, 0x06, 0x0F, 0x10. The block returns 0x0002 if a read is attempted with address 0.
- Word/byte swap: Modbus registers are big-endian (MSB first). The MB_MASTER block does not swap; if the S7-300 application expects little-endian, swap each word in the application (for example by reading DB20.DBW0 with the two bytes reversed manually before SCALE).
- Concurrent calls: Calling the same instance DB of FB640 from OB1 and OB35 simultaneously is undefined and will corrupt the internal state. Use either a single call site or two separate instance DBs each with their own channel.
- CPU run/stop behaviour: A pending transaction is aborted on CPU STOP. The slave will not see a clean close; if the slave uses timeout-based error recovery, allow at least 5 seconds before restart.
- Hot-swapping the ET 200S: Re-inserting the CM PtP triggers a station failure. The MB_MASTER instance DB must be re-initialised by setting COM_RST := TRUE for one OB1 cycle after the ET 200S returns to RUN.
Standards and Conformance
The Modbus master implementation conforms to Modbus over Serial Line — Specification and Implementation Guide V1.02 (Modbus Organization, December 2006) for the RTU transmission mode. The CRC polynomial is 0xA001 reflected (CRC-16/MODBUS). Frame timing uses the standard 3.5 character inter-frame silence marker. The library does not support Modbus TCP (port 502); that requires a CP343-1 or an S7-1500 module with the dedicated Modbus TCP library, which is a different KB entry.
FAQ
Can the same CM PtP library used for S7-1500 be used with S7-300 in STEP 7 V5.5?
No. The S7-1500 Modbus master library is built for TIA Portal V13+ and uses a different block interface (symbolic I/O, optimised access, separate instance DB handling). For S7-300 with STEP 7 V5.5 use the Modbus_Master_PtP library with FB640/FB641, available from Siemens support entry 75226762.
Why does FB640 return STATUS 0x0E02 (timeout) even though the slave responds when polled by a PC tool?
Three possibilities: (1) the A and B lines are reversed at the CM PtP connector; (2) the bus is not terminated with 120 Ω at both ends; (3) the response timeout in DB640 is too short (raise resp_timeout to T#2s and re-test). Verify by reducing baud rate to 9600 and increasing the inter-frame delay to 10 ms — if it now works, the problem was timing/EMI.
How do I address a holding register that the slave manual lists as 40001?
Set DATA_ADDR to 0 (or 1 if the manual numbers from 1 and you do not enable "Address base 0" in DB640). The Modbus convention is that address 0 in the protocol corresponds to register 40001 in the four-digit notation used by most slave manuals. If the block still returns exception code 02, increment DATA_ADDR by 1 and retry.
Can I use the CM PtP simultaneously as a Modbus master and a Modbus slave on the same port?
No. The protocol selection in HW Config is exclusive per channel. If the application needs both roles, use two CM PtP modules on the same ET 200S station (for example, the 2-channel variant 6ES7137-6BD00-0BA0) with one channel configured as master and the other as slave, each with its own FB640/FB641 instance DB.
Is a software licence required to use FB640/FB641?
No runtime licence is required. The blocks are royalty-free when used with a CM PtP purchased from Siemens. The library itself is a regular STEP 7 add-on shipped on the STEP 7 DVD or downloadable from the Siemens Knowledge Base. The CPU317 does not need any additional authorisation for the Modbus functionality.