Overview
The SIMATIC S7-1200 PLC integrates Modbus RTU master and slave capability through the MODBUS_RTU library distributed with STEP 7 (TIA Portal). This guide consolidates the documented procedure for establishing Modbus RTU communication between an S7-1200 CPU and one or more third-party AC drives (VFDs), including the CM 1241 RS485 communication module, the RS485 communications board (CB 1241), the MB_COMM_LOAD and MB_MASTER instructions, data block layout, and a deterministic sequential polling pattern.
The MODBUS-RTU reference project (entry ID 47756141) is the canonical Siemens example for this topology. The same description PDF documents the maximum hardware expansion: up to three CM 1241 communication modules plus one CB 1241 RS485 communications board per S7-1200 CPU.
Prerequisites
| Component | Specification |
|---|---|
| CPU | S7-1200 (any current generation supporting TIA Portal V11+) |
| Firmware | CPU firmware 4.2 or higher recommended (see firmware section below) |
| Communication module | CM 1241 RS485 (6ES7241-1CH30-0XB0) or CM 1241 RS232 (6ES7241-1AH30-0XB0) |
| Communications board (optional) | CB 1241 RS485 (6ES7241-1CH30-1XB0) — plug-in board on CPU left side |
| Engineering software | STEP 7 (TIA Portal) V11 SP2 or later for original Modbus RTU library; V13+ recommended for current libraries |
| Library | MODBUS_RTU (V1.x for TIA V11; V2.x/V3.x for later releases) |
| Drive(s) | Any Modbus RTU slave device with documented register map (function codes 03, 06, 16) |
Hardware Configuration and Topology
The S7-1200 supports Modbus RTU on two physical interfaces: the plug-in CB 1241 RS485 board mounted directly to the CPU, and one or more CM 1241 RS485 communication modules on the left-side bus. Each physical port requires a single instance of MB_COMM_LOAD to configure baud rate, parity, data bits, stop bits, and flow control, and a single instance of MB_MASTER to issue transactions. The hardware identifier assigned by TIA Portal to the CM/CB port must be supplied to the HW_ID input of MB_COMM_LOAD — this is the most common configuration error on first-time setup.
RS485 bus topology for Modbus RTU:
- Two-wire (half-duplex) daisy chain with termination resistors (typically 120 Ω) enabled at both physical ends of the trunk.
- Shielded twisted pair, shield grounded at one end only.
- Maximum of 32 unit loads per segment without repeater; most modern VFDs present 1/8 unit load.
- CM 1241 RS485 ships with a termination resistor that can be engaged via the on-board slide switch.
Firmware Considerations
S7-1200 CPUs shipped with early production firmware (notably the Starter Kit CPUs with firmware 1.0.0) exhibited documented communication issues affecting both Modbus TCP and RS485-based protocols. The relevant fix points were:
| CPU Firmware | Observed Behavior |
|---|---|
| 1.0.0 | Modbus TCP and RS485 communication failures; library calls return non-zero status without data exchange |
| 1.0.1 | Partial improvement — typically one of the two paths (TCP or RS485) becomes functional |
| 1.0.2 | Both Modbus TCP and RS485 paths operate as documented |
For any production deployment or new commissioning, use the latest firmware available for the specific CPU order number. Firmware updates are performed via TIA Portal using a SIMATIC Memory Card or via the Web Server (where supported). Always back up the project before performing a firmware update.
Installing the Modbus RTU Library
- Open the TIA Portal project and switch to the project library view (right pane: Libraries tab).
- Import the MODBUS_RTU library shipped with STEP 7. In TIA Portal V11/V12 the library is named
MODBUS_RTU(version 1.x). In TIA Portal V13 and later the successor libraryModbus_Com_Load/Modbus_Masteris provided as a global library. - Drag the master folder (
MB_MASTER,MB_COMM_LOAD, and associated data types) into the project tree under Program Blocks > System Blocks. - Confirm the block versions are compatible with the target CPU firmware. TIA Portal flags version mismatches during compilation.
MB_COMM_LOAD — Port Initialization
MB_COMM_LOAD is called once (or once per port change) to set the serial parameters and arm the port. It is edge-triggered on REQ and writes a DONE, ERROR, and STATUS back to the instance DB. The block must finish successfully before MB_MASTER transactions will be accepted by the port.
| Input | Data Type | Typical Value | Description |
|---|---|---|---|
| REQ | BOOL | Rising edge | Trigger to (re)load port configuration |
| PORT | HW_IO | CM 1241 RS485 hardware identifier | Identifies physical port |
| BAUD | DINT | 9600 / 19200 | Baud rate in bits/s |
| PARITY | UINT | 0 = None, 1 = Odd, 2 = Even | Parity setting |
| FLOW_CTRL | UINT | 0 = None, 1 = HW flow (RS422), 2 = SW flow (XON/XOFF) | Flow control |
| RTS_ON_DLY | UINT | 0 | RTS-on delay (ms) |
| RTS_OFF_DLY | UINT | 0 | RTS-off delay (ms) |
| RESP_TO | UINT | 1000 | Response timeout in ms |
For typical VFD integration, set RESP_TO to 1000 ms minimum and increase to 2000–3000 ms if the drive is slow to respond on heavy bus loading.
MB_MASTER — Transaction Engine
MB_MASTER is the workhorse instruction. It is also edge-triggered on REQ and arbitrates access to the port configured by MB_COMM_LOAD. A single MB_MASTER instance is sufficient for polling multiple slaves, because the block itself is sequential: each call completes (or times out) before the next call should be issued.
| Input | Data Type | Description |
|---|---|---|
| REQ | BOOL | Rising edge triggers one Modbus transaction |
| MB_ADDR | UINT | Modbus slave address (1–247) |
| MODE | USINT | 0 = Read, 1 = Write, 2 = Diagnostic |
| DATA_ADDR | UINT | Starting Modbus register address (per MODE) |
| DATA_LEN | UINT | Number of registers/words to read or write |
| DATA_PTR | VARIANT | Pointer to DB or tag area for payload |
| DONE | BOOL | Transaction complete, no error |
| BUSY | BOOL | Transaction in progress |
| ERROR | BOOL | Transaction error |
| STATUS | UINT | Error / status code |
For reading drive parameters, MODE = 0 (read holding registers, function code 03) is the most common. For writing a single control word or frequency reference, MODE = 1 with function code 06 is typical. For multi-register writes (e.g., 16-bit control plus 16-bit reference packed into a 32-bit word), function code 16 is used and the data area must be set up as a 2-element array.
Data Block and Array Layout
Each MB_MASTER call writes the returned registers into a buffer pointed to by DATA_PTR. The cleanest pattern is a global DB containing one or more ARRAY [0..n] OF WORD regions — one per drive or per parameter group.
DATA_BLOCK "DriveData"
STRUCT
Drive1_Read : ARRAY[0..9] OF WORD; // 10 holding registers from slave 1
Drive1_Write : ARRAY[0..1] OF WORD; // 2-word write buffer (control + reference)
Drive2_Read : ARRAY[0..9] OF WORD; // 10 holding registers from slave 2
Drive2_Write : ARRAY[0..1] OF WORD;
FaultWord : WORD; // Status / fault mapping
END_STRUCT;
END_DATA_BLOCK
The example project referenced in entry 47756141 uses an array structure similar to the above; the networks that copy the active slice into a per-drive workspace DB are the "shift register" pattern observed in the field report.
Sequential Polling — Shift Register Pattern
A single MB_MASTER can poll any number of slaves, but only one transaction at a time. The standard pattern uses a counter or step index to sequence transactions. The example project sequences 4 networks (4, 5, 7, 8 in the original listing) that each:
- Load slave address and register pointer for a specific drive.
- Set (latch) the request to
MB_MASTER.REQ. - Wait for
DONEorERROR. - Reset the request, increment the step counter, and continue.
A compact ladder equivalent:
// Step sequencer (simplified ST)
IF MB_MASTER_1.DONE OR MB_MASTER_1.ERROR THEN
MB_MASTER_1.REQ := FALSE;
step := (step + 1) MOD NUM_STEPS;
END_IF;
CASE step OF
0: // Read Drive 1 status
MB_MASTER_1.MB_ADDR := 1;
MB_MASTER_1.MODE := 0;
MB_MASTER_1.DATA_ADDR := 0;
MB_MASTER_1.DATA_LEN := 10;
MB_MASTER_1.DATA_PTR := "DriveData".Drive1_Read;
MB_MASTER_1.REQ := TRUE;
1: // Write Drive 1 control word + reference
MB_MASTER_1.MB_ADDR := 1;
MB_MASTER_1.MODE := 1;
MB_MASTER_1.DATA_ADDR := 0;
MB_MASTER_1.DATA_LEN := 2;
MB_MASTER_1.DATA_PTR := "DriveData".Drive1_Write;
MB_MASTER_1.REQ := TRUE;
2: // Read Drive 2 status
...
3: // Write Drive 2 control word + reference
...
END_CASE;
The shift register / sequencer is preferable to multiple parallel MB_MASTER instances on the same port, because the Modbus RTU library arbitrates port access internally and parallel calls will queue or collide. A common cause of intermittent timeouts is exactly this: several MB_MASTER blocks driven from different OB1 scan cycles.
Wiring to Third-Party AC Drives
Most modern VFDs expose Modbus RTU on a two-wire RS485 terminal block, frequently labeled D+/D- or A+/B-. Polarity conventions vary by manufacturer; consult the drive manual before commissioning. Typical termination:
- CM 1241 RS485:
T/R+(pin 3) → driveD+/A;T/R-(pin 8) → driveD-/B. - Common (GND_REF) at pin 5 of the CM 1241 should be connected to the drive's logic ground where the drive manual permits; this reduces common-mode noise.
- Enable the on-board 120 Ω termination at the S7-1200 end (DIP switch on CM 1241) and at the last physical drive in the daisy chain. Disable termination on intermediate drives.
STATUS Code Reference
Both MB_COMM_LOAD and MB_MASTER return a 16-bit STATUS word. The high byte is the function class and the low byte is the detail. Common values encountered in commissioning:
| STATUS (hex) | Meaning | Likely Cause |
|---|---|---|
| 0x0000 | No error | — |
| 0x8180 | Invalid port ID |
HW_ID does not match the CM/CB hardware identifier |
| 0x8181 | Invalid baud / parameter | One of BAUD, PARITY, FLOW_CTRL outside range |
| 0x8182 | DATA_PTR invalid | Pointer not a DB or of wrong element type |
| 0x8183 | DATA_LEN > buffer size | Length exceeds the array pointed to |
| 0x8184 | Parity / framing error on port | Wiring, baud, or parity mismatch |
| 0x8185 | Timeout — no response | Drive address wrong, wiring reversed, termination missing |
| 0x8186 | CRC error in reply | Electrical noise, incorrect baud, multi-master collision |
| 0x8188 | Modbus exception 02 (illegal data address) | Register not supported by drive |
| 0x8189 | Modbus exception 03 (illegal data value) | Write value out of drive's allowed range |
Commissioning Verification
-
Watch table test. Create a watch table on the drive data DB. Manually write a value to
Drive1_Write[0], triggerMB_MASTERwithREQ = TRUEfrom a test OB, and confirm the drive's response register changes via the drive's keypad or its own Modbus master tool. -
Loopback test. Disconnect the field cable and connect
T/R+toT/R-on the CM 1241 with a 120 Ω resistor across the pair. A read of the local echo confirms the port and library are functional independent of the drive. - Single-drive sanity. Connect only the first drive. Verify baud, parity, slave address. Confirm a holding register read returns the expected default value (often 0 or a status word).
- Sequential polling test. Add the second drive. Watch the step counter and confirm transitions are clean and timeouts are absent. Add a 50 ms post-DONE delay if slave response is borderline.
-
Long-run test. Log
ERRORandSTATUSover 24 hours. A non-zero error count above ~0.1% of transactions typically indicates electrical noise, termination, or insufficient inter-character delay.
Troubleshooting Matrix
| Symptom | First-look Cause | Corrective Action |
|---|---|---|
MB_MASTER never sets DONE, BUSY stays TRUE |
MB_COMM_LOAD not executed or errored |
Verify DONE on MB_COMM_LOAD; check hardware identifier |
| STATUS 0x8184 (parity/frame error) | Baud or parity mismatch with drive | Verify drive's serial settings; ensure 8E1 or 8N1 matches both sides |
| STATUS 0x8185 (timeout) | No response from drive | Check A/B polarity, slave address, termination resistors, common ground |
| STATUS 0x8186 (CRC) | Electrical noise | Check shield termination, segregation from VFD power cables, add line termination |
| Communication works with 1 drive, fails with 2 | Sequencer driving multiple MB_MASTER instances |
Use a single MB_MASTER with a step counter; verify only one REQ at a time |
| Random periodic timeouts on otherwise healthy bus | Insufficient inter-frame delay | Increase RESP_TO to 2000+ ms; ensure 3.5 character silence between frames |
| Drive receives command but does not act | Control word mapping wrong | Cross-check drive parameter group (e.g., P0, P1, P2 in many VFDs) against MODBUS register map in drive manual |
| CPU goes to SF / BF after firmware update | Library version mismatch | Re-import matching version of MODBUS_RTU; recompile; check block family |
FAQ
How many Modbus RTU slaves can one S7-1200 poll?
The CPU supports up to three CM 1241 communication modules plus one CB 1241 RS485 board. Each physical port can poll up to 247 slave addresses (Modbus address range 1–247), but practical limits are set by baud rate, response time, and the required scan time of the application.
Why does MB_MASTER stay BUSY and never complete on a Starter Kit CPU?
Starter Kit CPUs shipped with firmware 1.0.0 have documented Modbus TCP and RS485 defects. Upgrade to the latest firmware for the specific CPU order number (1.0.2 or later for early CPUs, 4.x for current CPUs).
Can I use more than one MB_MASTER block on the same RS485 port?
The library internally arbitrates port access, but parallel MB_MASTER instances driven from OB1 typically cause queued or conflicting requests. Use a single MB_MASTER and a step sequencer to poll each slave in turn.
Which TIA Portal version is required?
The original Modbus RTU example (entry 47756141) targets TIA Portal V11. The library remains usable in later TIA Portal versions with the V2.x/V3.x successor libraries. Compile against a CPU firmware that the project device configuration accepts.
What is the correct hardware identifier to use in MB_COMM_LOAD?
The HW_ID is assigned by TIA Portal in the device configuration of the CM 1241 RS485 (or CB 1241). It is visible in the PLC tag table under "System constants" for the module. An incorrect HW_ID returns STATUS 0x8180.