Configuring Modbus RTU Master on Siemens S7-1200 for Optidrive

David Krause16 min read
ModbusSiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Configuring Modbus RTU Master on a Siemens S7-1200 for Invertek Optidrive VFDs

This reference walks through a complete Modbus RTU master implementation on a SIMATIC S7-1200 CPU driving one or more Invertek Optidrive variable frequency drives. The guide covers hardware selection, RS-485 wiring, TIA Portal device and port configuration, the MB_MASTER instruction, the Optidrive parameter map (registers 40001–40008), the positive-edge polling pattern recommended in Siemens application examples, and field-proven remedies for the most common commissioning fault: the request staying BUSY without ever returning DONE.

1. System Architecture and Topology

For an installation with one PLC and three drives, the S7-1200 acts as the Modbus RTU master on a single RS-485 multi-drop bus. Each Optidrive is a slave with a unique 8-bit address (1–247). Daisy-chain the drives from the PLC's RS-485 port; do not star or branch beyond the recommended stub length.

S7-1200 CPU 1214C DC/DC/DC + CM1241 RS485 Optidrive #1 Addr 1 Optidrive #2 Addr 2 Optidrive #3 Addr 3 RS-485 bus: D+ (A), D- (B), GND — terminated 120 Ω at both ends
Bus topology rule: RS-485 is a bus, not a star. Each drive should be on its own short drop (under ~1 m total stub length in noisy industrial panels). Place termination resistors only at the two physical ends of the trunk — typically the PLC port and the last drive.

2. Prerequisites

Item Specification
S7-1200 CPU CPU 1211C, 1212C, 1214C, 1215C, or 1217C with firmware V4.0 or later. Modbus RTU master requires the "Modbus RTU Master" library or the MB_MASTER instruction included with the S7-1200 program instructions (firmware V4.1+ integrates this directly into TIA Portal instructions palette).
RS-485 interface CM1241 RS485 (6ES7241-1CH30-0XB0) communication module, or CB1241 RS485 (6ES7241-1CH30-1XB0) communication board for compact CPUs. CB 1241 is limited to one port.
TIA Portal V13 SP1 or later for CM1241; V15 or later recommended for FB/instance-style MB_MASTER. Use V16+ for the latest firmware libraries.
Invertek Optidrive Any model supporting the Invertek Modbus RTU register map — Optidrive E3 (ODV-3), Optidrive P2 (ODP-2), or Optidrive Coolvert. Set parameter P-36 = 1 to enable Modbus control.
Reference docs S7-1200 System Manual (entry ID 109751325), CM1241 module manual (entry ID 58830508), Invertek Optidrive user guide for the specific drive family.

3. RS-485 Wiring and Physical Layer

The CM1241 RS485 exposes a removable 6-pin terminal block with three relevant signals: T/R+ (A, D+), T/R- (B, D-), and GND. Many field wiring mistakes trace back to swapping A and B or floating the common reference.

  1. Wire T/R+ from the CM1241 to the drive's Modbus D+ (or A) terminal on every drive.
  2. Wire T/R- from the CM1241 to the drive's Modbus D- (or B) terminal on every drive.
  3. Connect GND between PLC and drives to equalize reference potentials — essential for longer runs and panels fed from different supplies.
  4. Install a 120 Ω termination resistor between D+ and D- at each end of the bus. Many Optidrive terminals expose a switch or jumper labeled "RT" — enable on the last drive only; the PLC port has no internal termination on the CM1241, so add an external 120 Ω across D+/D- at the PLC terminal block if it is the end of the run.
  5. Set the unique slave address on each drive through its keypad parameter (Invertek P-36 = slave address).
Shielding: Use twisted-pair shielded cable (Belden 3106A or equivalent). Ground the shield at one end only — typically at the panel ground bar near the PLC — to prevent ground loops.

4. TIA Portal Project Configuration

4.1 Add the Communication Module

From the hardware catalog, drag the CM1241 RS485 (6ES7241-1CH30-0XB0) onto the PLC's left-side bus. Address it in a free slot. TIA Portal automatically creates the module in the device configuration and reserves the diagnostic interrupt OB.

4.2 Port Parameters

Open the CM1241 properties and configure the port to match the drives:

Parameter Recommended Notes
Baud rate 19200 (start here); 38400 if all drives support it All slaves on the bus must match
Parity Even (8E1) Optidrive default is 8E1
Data bits / Stop bits 8 / 1 Implied by 8E1
Flow control None RS-485 is half-duplex; no RTS/CTS
Receive line initial state Active (default) Hold the receiver enabled

For CPU 1217C or any CPU with an onboard RS-485 port, the same parameter set applies under "Properties > Communication interfaces > RS-485".

5. The MB_MASTER Instruction

The MB_MASTER instruction (in TIA Portal V15+: under "Communication > Modbus RTU") encapsulates a single Modbus request. It returns a DONE bit on success, ERROR with STATUS on failure, and stays BUSY while the request is outstanding.

5.1 Instruction Block Parameters

Pin Type Description
REQ BOOL Edge-triggered start. Must be a positive edge; do not hold high.
MB_ADDR UINT Slave address 1–247 (0 reserved for broadcast on write).
MODE USINT 0 = read holding registers (FC 03), 1 = write single register (FC 06), 2 = write multiple registers (FC 16), see firmware-dependent variants.
DATA_ADDR UINT Starting Modbus register address. For 40001 enter 1; for 40010 enter 10. Siemens convention is zero-based.
DATA_LEN UINT Number of 16-bit words (1–123 for FC03, 1–123 for FC16, must be 1 for FC06).
DATA_PTR VARIANT Pointer to a word array, DB, or marker area. Must be aligned to a word boundary; bit-level access is not supported.
DONE BOOL One-cycle TRUE on success.
BUSY BOOL TRUE while the request is in flight.
ERROR BOOL TRUE on failure with STATUS populated.
STATUS WORD Error code (see Section 10).

The official Siemens application example for establishing Modbus RTU communication on S7-1200 — entry ID 47756141 in the Siemens Industry Online Support — walks through this instruction step by step and is the canonical reference for first-time setup.

5.2 Calling the Block

Place MB_MASTER in a cyclic OB (typically OB1). For each request, instance a separate background DB or use multi-instance capability with a single FB that contains the request logic. The DATA_PTR can reference:

  • A global DB of ARRAY[0..n] OF WORD
  • A marker area, e.g. P#M500.0 WORD 100
  • A local static area inside a wrapping FB
Bit/byte access is invalid: if DATA_PTR points to P#M500.0 BYTE 100 or any non-word-aligned buffer, MB_MASTER returns STATUS 16#8188 ("Invalid pointer"). Always specify WORD and an even number of bytes.

6. Invertek Optidrive Modbus Register Map

The Optidrive exposes the standard Invertek parameter set through Modbus holding registers. The most commonly used registers are:

Reg (1-based) Internal addr Access Name Notes
40001 0 R/W Control word 0x0001 = Run forward, 0x0002 = Run reverse, 0x0000 = Stop, 0x0007 = Fault reset
40002 1 R/W Frequency setpoint Value = Hz × 100 (e.g. 50.00 Hz → 5000 → 16#1388)
40003 2 R/W Reserved / drive-specific Refer to drive manual
40004 3 R Status word Bit 0 = drive healthy, Bit 1 = running, Bit 2 = direction, etc.
40005 4 R Output frequency Hz × 100
40006 5 R Motor current Amps × 10 (0.1 A resolution)
40007 6 R Motor voltage Volts (RMS line-line, drive-dependent)
40008 7 R DC bus voltage Volts DC
40009 8 R Drive temperature °C
40010 9 R/W Parameter access index Used to read/write any P-parameter
Always verify against the manual for your specific Optidrive model: the E3, P2, and Coolvert families use a common core map but may add or rearrange registers. Confirm by reading the user guide for the build you have on the bench, not the family brochure.

7. Step-by-Step Program Build

The pattern below uses one wrapper FB per drive to keep the program organized. Each FB owns its request state machine and presents a clean interface (Start, Stop, SetFreq, HzActual, Amps, Faulted) to OB1.

7.1 Define a Polling FB

Inside FB_DrivePoll, declare:

VAR
  // Configuration
  SlaveAddr  : UINT;     // Modbus address (1..247)
  PollTime   : TIME;     // e.g. T#200ms

  // State machine
  State      : INT;      // 0=idle, 1=read req, 2=write req, 3=wait
  Tmr        : TON_TIME;
  RTrig      : R_TRIG;
  BusyOld    : BOOL;

  // Process data
  CtlWord    : WORD;     // 40001
  SetFreq    : WORD;     // 40002
  StatWord   : WORD;     // 40004
  OutFreq    : WORD;     // 40005
  OutCurr    : WORD;     // 40006
  OutVolt    : WORD;     // 40007
  DcBus      : WORD;     // 40008

  // Error capture
  LastStatus : WORD;
  CommOk     : BOOL;
END_VAR

7.2 Read Status Word and Frequency

// Positive-edge-triggered read of 40004..40008 (5 words)
// DATA_ADDR uses Siemens zero-based: 40004 -> 3
RTrig(REQ := NOT BusyOld AND Tmr.Q, CLK := TRUE);
MB_Master_Read(
  REQ      := RTrig.Q,
  MB_ADDR  := SlaveAddr,
  MODE     := 0,                       // FC 03 read holding
  DATA_ADDR:= 3,                       // register 40004
  DATA_LEN := 5,                       // 5 words
  DATA_PTR := P##StatBuf,
  DONE     => ReadDone,
  BUSY     => BusyRd,
  ERROR    => ErrRd,
  STATUS   => StatRd);
IF ReadDone THEN
  StatWord := StatBuf[0];
  OutFreq  := StatBuf[1];
  OutCurr  := StatBuf[2];
  OutVolt  := StatBuf[3];
  DcBus    := StatBuf[4];
  CommOk   := TRUE;
END_IF;
IF ErrRd THEN
  LastStatus := StatRd;
  CommOk     := FALSE;
END_IF;
Tmr(IN := NOT BusyRd, PT := PollTime);
BusyOld := BusyRd;

7.3 Write Control Word and Setpoint

Use FC 16 (write multiple) to send control word and frequency in one frame, halving the round-trips versus FC 06 single writes:

// Latch new request on positive edge of NewCmd
IF NewCmd THEN
  NewCmd := FALSE;
  WBuf[0] := CtlWord;   // 40001
  WBuf[1] := SetFreq;   // 40002
END_IF;

MB_Master_Write(
  REQ      := WriteReq,
  MB_ADDR  := SlaveAddr,
  MODE     := 2,                       // FC 16 write multiple
  DATA_ADDR:= 0,                       // 40001 zero-based
  DATA_LEN := 2,
  DATA_PTR := P##WBuf,
  DONE     => WDone,
  BUSY     => WBusy,
  ERROR    => WErr,
  STATUS   => WStat);

8. Polling Strategy and Timing

With three drives and a typical read/write cycle of four messages per drive (one read, one write), the bus carries ~12 messages per scan. At 19200 baud each 8-byte read takes roughly 8 ms line time plus inter-frame silence (3.5 character times ≈ 2 ms at 19200/8E1). Plan ~30–50 ms between requests to give the drives time to respond without queuing.

Setting Value Reason
Poll period per drive 200–500 ms VFD process values rarely change faster than 10 Hz; aggressive polling wastes bus bandwidth
Inter-message gap ≥ 50 ms Allows the slave's UART to flush; avoids collision on turnaround
Response timeout 1000 ms default; reduce to 200 ms in stable runs CM1241 hardware default is conservative
Use a positive edge on REQ. Siemens' own TIA Portal help example for MB_MASTER edges the REQ input with R_TRIG. Holding REQ high continuously causes back-to-back transmissions and may produce STATUS 16#818B ("Request rejected because previous request still active") or leave BUSY latched forever.

9. Addressing and DATA_PTR Pitfalls

The most frequent beginner error is mismatching DATA_ADDR to the slave's documented 1-based register number. Siemens interprets DATA_ADDR as zero-based:

You want Enter in DATA_ADDR
40001 (control word) 0
40002 (frequency) 1
40004 (status word) 3
40010 (parameter index) 9

A second common pitfall is the buffer declaration. DATA_PTR must point to a contiguous WORD buffer. The following are equivalent and all valid:

  • DataBlock.ReadBuf[0] where ReadBuf is ARRAY[0..9] OF WORD in a global DB
  • P#M500.0 WORD 100 — 100-word marker area starting at MW500
  • P#DB10.DBX0.0 WORD 20 — 20-word slice of DB10

Invalid (returns STATUS 16#8188):

  • P#M500.0 BYTE 100 — wrong element type
  • P#M501.0 WORD 100 — odd byte address, not word-aligned
  • A DB element declared as BOOL or INT (not 16-bit word)

10. Troubleshooting: BUSY With No DONE — Root Causes and Fixes

The most reported commissioning symptom — "TX flashes, RX flashes briefly, BUSY stays on, DONE never sets, no ERROR" — has a small number of recurring causes.

10.1 Wiring Polarity

Symptoms: BUSY latches indefinitely, no ERROR, no response from the drive.

Check the D+/D- polarity. Some Optidrive terminals mark the bus as "A/B" rather than "D+/D-" and the mapping is:

PLC (CM1241) Drive (Optidrive)
T/R+ D+ (or A)
T/R- D- (or B)
GND GND / 0V reference

Swap at one end only if polarity is reversed. Confirm with a continuity check on the disconnected cable before powering up.

10.2 Slave Address Mismatch

Symptoms: TX/RX activity present, but the drive ignores the frame.

Verify the Optidrive's Modbus address in parameter P-36 (or equivalent in the specific model). The default on many Optidrive units is 1, but if the drive was previously addressed through a different tool, it may be different. Read back the address by polling Modbus address 1 with a Modbus scanner (Modbus Poll from WinTech or an equivalent) and confirm a response.

10.3 Parity / Baud Mismatch

Symptoms: TX/RX activity but persistent BUSY, no DONE, STATUS 16#8189 (hardware fault) or no error at all if the noise is severe.

Optidrive Modbus defaults to 19200 / 8E1. The CM1241 must match exactly. Many engineers set the PLC to 19200 / 8N1 by accident; the resulting framing error passes the line check on some drives and silently corrupts on others. Force both ends to 19200/8E1, restart the PLC, and retry.

10.4 Termination

Symptoms: works at 19200 with one drive, fails with three; or works at 2400 but fails at 19200.

Enable 120 Ω termination only at the two physical bus ends. A mid-bus termination absorbs signal energy and produces reflections that read as framing errors at higher baud rates.

10.5 Continuous REQ

Symptoms: BUSY stays true, no DONE, no ERROR, no TX/RX activity.

If REQ is held high, MB_MASTER rejects repeated calls with STATUS 16#818B until BUSY drops. Insert an R_TRIG ahead of REQ, or trigger the request from a timer that fires once per poll cycle. Hold REQ for one OB1 cycle at most.

10.6 Insufficient Inter-Frame Delay

Symptoms: intermittent success then BUSY locks up.

The CM1241 enforces a minimum silent period before allowing a new master transmission. If back-to-back MB_MASTER calls are placed in the same cycle, the second call sees BUSY from the first. Sequence the calls with separate flags and a small wait between edges.

10.7 Modbus STATUS Code Reference

STATUS Meaning Action
16#0000 No error
16#8180 Invalid slave address MB_ADDR outside 0–247
16#8181 Invalid pointer DATA_PTR not aligned, wrong type, or null
16#8182 Invalid data length DATA_LEN = 0 or exceeds FC limit
16#8183 Invalid MODE MODE not in the supported set
16#8188 Pointer alignment / type error Use WORD, even byte offset
16#8189 Hardware / framing fault Check baud, parity, cable
16#818A Slave returned exception 01 (illegal function) Drive doesn't support that FC at that register
16#818B Request rejected, prior request still active Edge the REQ, do not hold
16#818C Slave address mismatch / no response Verify P-36, check termination
16#80D0 / 16#80D1 Diagnostic / hardware fault Recompile project, reseat CM1241
Always capture STATUS into a marker or DB word on every ERROR edge. Without that latch, the code is unrecoverable at commissioning time because the value is only valid for one OB1 cycle. The Siemens TIA Portal example for entry ID 47756141 stores the status into a retentive DB for later HMI display.

11. Verification and Commissioning Checklist

  1. Open Modbus Poll (or equivalent) on a laptop with a USB-to-RS-485 adapter and verify the drive responds to a holding-register read at address 1, registers 40004–40008. Confirm the values move when the drive runs.
  2. Confirm the same scan responds at 19200/8E1 with no error frames. If Modbus Poll shows errors, the wiring is suspect before the PLC is even connected.
  3. Load the S7-1200 program and go online. Watch the BUSY and DONE tags in the watch table. With correct setup you should see BUSY pulse and DONE set within ~20–40 ms of REQ.
  4. Monitor LastStatus in the watch table. Confirm it stays at 16#0000 across successful polls.
  5. Issue a Run command (CtlWord = 16#0001) and a frequency setpoint of 16#0BB8 (30.00 Hz). Verify OutFreq follows within 200 ms.
  6. Issue a Stop (CtlWord = 16#0000) and verify StatWord bit 1 (running) clears.
  7. Disconnect the bus mid-run and verify the program surfaces a communication-loss fault (e.g. CommOk clears within the response timeout, not after a watchdog).
  8. Verify that a drive trip (e.g. overcurrent) is reflected in StatWord on the next read. The Optidrive may also require a fault-reset edge (CtlWord = 16#0007) before it will re-run.

12. Performance and Safety Notes

  • Determinism: Modbus RTU is best-effort, not a safety-rated protocol. A safety stop must use a hardwired STO input on the drive, not a Modbus command. The CM1241 and MB_MASTER cannot deliver a guaranteed response time under all field conditions.
  • Watchdog: Implement a watchdog in user code that declares the drive "stale" if no successful poll has completed within a defined window (e.g. 1 s). Drive the application to a safe state on stale inputs.
  • EMI: Inverter output cables can corrupt the RS-485 bus if they share a tray. Separate the bus cable from motor cables by at least 200 mm and cross only at right angles.
  • Address planning: Reserve 1, 2, 3 for the three drives on this bus. If you add a fourth device later (HMI panel, energy meter), keep addressing sequential to simplify scan lists.

13. Extending the Pattern

When you outgrow the single-CM1241 topology, two common extensions are supported by S7-1200:

  • Add a second CM1241 in a free slot to split drives across two physical buses. Each module runs its own MB_MASTER instance.
  • Move the bus to a CM 1243-5 PROFIBUS master and add a PROFIBUS-to-Modbus gateway at each drive, when the application requires faster cycle times or longer distances. This trades the simple RS-485 wiring for additional gateway cost and configuration.

For drives beyond Modbus RTU, the S7-1200 also supports PROFINET via the PN port or a CP 1243-1, and ET 200SP frequency inverters can be controlled directly over PROFINET without a gateway.

14. FAQ

How do I enable Modbus control on an Invertek Optidrive?

Set parameter P-36 to the desired slave address (1–247) and confirm the drive's control source parameters (typically P-12 for reference, P-15 for run/stop logic) are set to allow Modbus commands. Consult the specific Optidrive user guide for the build you have on the bench — the parameter indices differ between E3, P2, and Coolvert families.

Why does my MB_MASTER stay BUSY without ever setting DONE or ERROR?

Five causes account for nearly every case: (1) D+/D- polarity reversed, (2) baud or parity mismatch between PLC and drive, (3) slave address not set or wrong on the drive, (4) REQ being held continuously high instead of pulsed on a positive edge, or (5) the DATA_PTR pointing to a non-word-aligned buffer. Capture STATUS into a retentive word on every error edge to diagnose quickly.

Is DATA_ADDR 1-based or 0-based on MB_MASTER?

0-based. To read register 40001 on the slave, set DATA_ADDR = 0. To read 40004, set DATA_ADDR = 3. Mismatching the convention is one of the most common first-day commissioning errors and produces a "no response" symptom because no real register exists at the requested offset.

Can I use MB_MASTER with the onboard RS-485 of the CPU 1217C?

Yes. The onboard port is configured identically to a CM1241 under "Properties > Communication interfaces > RS-485." The same MB_MASTER instruction drives both. CB 1241 communication boards behave the same way for compact CPUs that lack the onboard port.

What baud rate should I start with for an Optidrive Modbus link?

19200 baud with 8E1 framing is the Invertek default and a reliable starting point. Move to 38400 once the link is stable if you need faster cycle times; keep 19200 if the bus runs through a noisy panel or a long cable run. Always run all slaves on the bus at the same baud and parity.

How do I simulate Modbus devices during bench commissioning?

Use a Modbus master simulator (Modbus Poll) on a laptop with a USB-to-RS-485 adapter to verify the wiring and slave addresses before connecting the PLC. A Modbus slave simulator (Modbus Slave from the same vendor) lets you exercise the S7-1200 program against a known device without energizing the drives.

Back to blog