Implementing Modbus ASCII Communication with S7-1200 PLC

David Krause17 min read
ModbusSiemensTechnical Reference
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

Overview

The challenge described in the source material — a Siemens S7-1200 CPU trying to read and write a third-party device (a PRO2 Valley irrigation control panel) that only exposes Modbus ASCII on an RS-232 port — is one of the most common Siemens Industrial Online Support requests for serial instrumentation. The S7-1200 Modbus instruction library (MB_MASTER, MB_SLAVE, FB 1100, FB 1101) is hard-coded for Modbus RTU and rejects ASCII frames because the character framing is fundamentally incompatible (7 data bits, LRC checksum, framed by : and CRLF characters vs. 8 data bits, CRC16, framed by 3.5-character silent intervals). Four viable hardware / firmware paths exist:

  1. Replace the head CPU with an ET200S IM151-8 PN/DP and add a 1SI Modbus ASCII module (the cleanest no-code-change solution).
  2. Add an external CP340 / CP341 behind a S7-300 or S7-400 with the loadable Modbus ASCII driver.
  3. Use a third-party Modbus ASCII ↔ Modbus RTU / TCP gateway (Anybus X-gateway, HMS Communicator) so the S7-1200 can speak RTU.
  4. Keep the S7-1200 in place but drive its RS-232 CM 1241 in Freeport mode with custom user code that assembles the LRC, ':' and CRLF characters manually using Send_P2P/Receive_P2P.

This reference compares the four options side-by-side, gives the frame-by-frame differences engineers must respect, lists concrete catalog numbers and configuration values, and provides a commissioning checklist that works for a PRO2 Valley panel or any similar Modbus ASCII only device.

Modbus ASCII vs Modbus RTU — Fundamental Differences

Modbus is a single-master multi-drop application-layer protocol defined by Modicon in 1979 and still actively published as Modbus Organization reference material and on the Modbus Protocol specification pages. The difference between ASCII mode and RTU mode is purely a transmission choice; the PDU (function code, register space, coils, input registers) is identical, which is why a transparent protocol converter works.

Attribute Modbus ASCII Modbus RTU (what S7-1200 ships)
Encoding Hex-encoded ASCII characters 0–9, A–F Raw 8-bit binary
Data bits per character 7 8
Default parity Even (also supports None) None
Stop bits 1 (with parity) or 2 (no parity) 1 (no parity)
Frame start delimiter 0x3A (':') 3.5-character silent interval
Frame end delimiter 0x0D 0x0A (CR LF) 3.5-character silent interval
Error check LRC (8-bit, two's complement) CRC-16 (Modbus polynomial 0xA001)
Maximum packet size 2 × (253 registers) + 9 ASCII bytes 256 bytes raw
Throughput at 9600 baud Lower (2 chars per byte) Higher
Readability on a scope Human-readable on terminal Not human-readable

An RTU-only Modbus master will simply fail to interpret the leading : of an ASCII frame: the MB_MASTER instruction in TIA Portal measures inter-character timeouts relative to one byte at 8 bits, so a 7-bit ASCII slave will silently drop or jam the bus.

Critical field note: Modbus ASCII over RS-232 is point-to-point only; multi-drop RS-485 multi-drop addressing is technically defined but rare. Confirm with the panel manufacturer whether the device is addressed 1 always, or accepts the standard 1–247 range.

Why the S7-1200 Instruction Library Cannot Handle Modbus ASCII

The S7-1200 Modbus library shipped from firmware V1.0 of the CM 1241 / CB 1241 modules is the S7-1200 Modbus Master/Slave library exposed in TIA Portal under Instructions > Communication > Communication Processor > Modbus. The instructions physically force the CM 1241 port into 8-bit data mode and manage the RTU silent interval timers. No TIA Portal option exposes a 7-bit ASCII variant. The library calls are:

  • MB_MASTER (FB 1100 / earlier MB_MASTER_v2_v3_v4) — issues function codes 01, 02, 03, 04, 05, 06, 15, 16.
  • MB_SLAVE (FB 1101) — Passive server mode for the S7-1200 side.
  • MB_CLIENT / MB_SERVER — Open user communication on the CPU's PROFINET port for Modbus TCP.

None of these blocks generate LRC, none accept a : start byte, and none of the CM 1241 hardware parameters in the device configuration allow selection of 7E1 framing. This is a documented constraint in the S7-1200 System Manual. Therefore any Modbus ASCII master strategy requires either a different Siemens hardware (ET200S 1SI, CP341) or a third-party conversion layer.

Solution Path A — ET200S IM151-8 PN/DP plus 1SI ASCII Module (Recommended)

Hardware

  • IM 151-8 PN/DP CPU — Siemens catalog number 6ES7151-8AB00-0AB0 or 6ES7151-8FB00-0AB0 (later revision). Acts as a PROFINET I/O device under the S7-1200 (as a PROFINET IO controller), so it appears in TIA Portal just like a remote rack. The program inside the IM 151-8 still controls the 1SI directly.
  • ET200S 1SI Modbus / USS ASCII module — Catalog 6ES7138-4DF01-0AB0 (older 6ES7138-4DF00-0AB0 also works). The 1SI can be configured as Modbus Master or Modbus Slave in either ASCII or RTU; what the application needs is Modbus ASCII Master.
  • Terminal module6ES7193-4CA00-0AA0 (screw) or 6ES7193-4CA10-0AA0 (spring) for the 1SI.

Configuration in TIA Portal

  1. Insert the IM151-8 from the catalog under Other Controllers > ET200S as a PROFINET device on the S7-1200 network.
  2. Slot 1: 1SI 9.6 KBd Modbus/USS ASCII — slot configured in device view.
  3. Open the 1SI properties > Protocol: select Modbus master (not USS).
  4. Open Interface: set Frame = 7E1 for PRO2-class devices; if the panel demands 7N2 see its manual.
  5. Open Addresses for the input data. The 1SI places receive register 4 words above the start in the IM151-8 I area.

Function Blocks Shipped With the 1SI

The 1SI Modbus/USS ASCII ships with its own step-7-compatible FB library downloadable from Siemens support. The principal blocks are:

  • S_SI (FB 200 standard) or S_MODB (FB 202) — Send Modbus frame / initiate request.
  • R_SI / R_MODB — Receive response.
  • S_USS / R_USS — For the USS parameter channel on inverter drives (does NOT apply here).

Example SCL call for Holding Register 40001 read of PRO2 panel

// FB R_MODB call from cyclically triggered OB1
// Slave = 1, Function Code = 03 (Read Holding Register)
// StartAddress = 0 (PRO2 maps 40001 = offset 0)
// Qty = 8 (8 registers = one telemetry block)

#Status      := 16#0000;      // initial state machine
#Req         := TRUE;         // one-shot per OB cycle
#Unit        := 1;            // 1SI slot number (rack position)
#Slave       := 1;            // PRO2 Modbus address
#Function    := 3;            // Read Holding Register
#DataPtr     := P#DB100.DBX 0.0 BYTE 16; // 8 words destination
#DataLen     := 16;
#Start_Addr  := 0;

// R_MODB also returns:
// .Done  BOOL  -> one-shot success
// .Error BOOL  -> check StatusWord
// .Rd_DB / .Rd_Adr / .Rd_Len show where the response buffer lives

Acceptance / verification

In online > monitor R_MODB, .Error=0 and .Status=16#0700 (or whatever codes the Siemens FB returns for "request finished with no error") indicates a live bus. Place a Watch table on the data DB; values must update every cycle at the configured polling rate.

Solution Path B — S7-300 / S7-400 with CP341 and Loadable Modbus ASCII Driver

Hardware

  • CP 341: order numbers 6ES7341-1AH01-0AE0 (RS-232C/RS-422, ASCII driver applicable), 6ES7341-1CH01-0AE0 (RS-422/RS-485), or 6ES7341-1BH01-0AE0 (20 mA current loop).
  • Loadable driver: 6ES7870-1AC01-0YA0 ("Modbus ASCII Master, 16-bit") or the matching Slave version. The license is hardware-bound to the CPU serial number of the CP341.
  • RS-232 null-modem cable from CP341 port to PRO2 DB9 (see cabling section below).

Project integration

  1. Open the CP341 in HW Config > Properties > Protocol; load the MODB_MAST.EXP driver via the supplied Parameterization Tool (the PT runs in standalone mode and writes the database back into HW Config as a system data block).
  2. The parameter tool forces 7E1 framing and sets the slave number prefix.
  3. From STEP 7, call FB 80 P_SEND / FB 81 P_RCV to drive the raw channel, or the Modbus-specific wrapper FBs FB 82 MODBMA4 / FB 83 MODBSLA that the driver library supplies.

Typical master request through FB 82

Input Value
SLAVE 1 (PRO2)
FC 3 (Read Holding Reg.)
START_ADDRESS 0 (= 40001)
QUANTITY 1–125
DATAPTR Pointer to any DB
DONE / ERROR One-shot success / one-shot error code

Any non-zero STATUS value is documented in the CP341 manual appendix. Common values: 0x8001 slave timed out, 0x8101 LRC mismatch, 0x8103 framing error on the wire.

WARNING: FB 80/81/82/83 are SIMATIC STEP 7 V5 blocks. They run on S7-300/400 and were carried forward to TIA Portal in early V13/V14 projects; newer TIA projects may have to import them via the SIMATIC Modbus CP341 library package from the Siemens support portal.

Solution Path C — Modbus ASCII to Modbus RTU Gateway (Anybus Communicator)

A protocol converter sits on the RS-232 side, parses the ASCII frames, and re-emits them as Modbus RTU on a chosen downstream interface (RTU over RS-485 or Modbus TCP). The S7-1200 then talks to the gateway over its native CM 1241 RS-485 with MB_MASTER.

Hardware Candidates

  • Anybus X-gateway Modbus TCP / EtherNet/IP with a free serial sub-port (e.g., ABC3012 RS-232 sub-port).
  • HMS Anybus Communicator family — configurable as Modbus ASCII Master on the serial port, Modbus TCP/RTU on the network port. The standard PN, EtherNet/IP, Modbus TCP variants are listed on the Anybus Communicator product page.

Configuration Workflow

  1. Install Anybus Configuration Manager X on a Windows PC.
  2. Select Sub-network > Modbus RTU (Master) on the network port facing the S7-1200, and Modbus ASCII (Master/Slave) on the serial port facing the PRO2.
  3. Import a Modbus map: for every register the PRO2 exposes, define a node > register > mapping line (target node / register).
  4. Set serial framing: 9600 / 19200 baud to match the PRO2, 7E1.
  5. Set cycle time and request order for cyclical reads.
  6. Download the configuration to the gateway and power-cycle it.

S7-1200 Side Configuration

The gateway will appear either as a Modbus TCP node (port 502) or as a Modbus RTU node on RS-485. Configure MB_MASTER on the S7-1200 to poll the gateway with function codes 03 (holding), 04 (input), 02 (input status), or 01 (coil) depending on the PRO2 map you built on the gateway. Coils and discrete inputs are essentially ignored because the PRO2 panel exposes simulation but the field wires connect only to registers; keep the gateway map unidirectional for register read/write.

Critical field note: ASCII and RTU both use the same logical register space, but the data order is identical (big-endian, low word first). Some gateways swap words; verify in Configuration Manager that the byte order is "Status/Value word low first" to match the S7-1200 byte order.

Solution Path D — S7-1200 CM 1241 in Freeport Mode (Custom ASCII Implementation)

If the goal is to keep the CPU as S7-1200 only (no ET200S, no extra CP), the CM 1241 can be operated in Freeport (point-to-point) mode via the user library S7-1200 Basic Controller Communication — PtP. This is the path taken on factory automation lines where the control panel is more than 20m away and you already have a Freeport-capable CM 1241.

Steps

  1. Insert a CM 1241 RS-232 (order 6ES7241-1AH32-0XB0) into the S7-1200 rack and configure its device properties: Protocol = Freeport, Baudrate = 9600 (or whatever the panel requires), Parity = Even, Data bits = 7, Stop bits = 1.
  2. Add the instruction RCV_PTP for receiving, and SEND_PTP for transmitting. Both are in the PtP instruction tree in TIA Portal.
  3. Implement in SCL an LRC calculation function: take all bytes between : and CR LF, cast to bytes, modulo-256 two's complement.
  4. Build the transmit buffer as ASCII. Example for "Read Holding Register 0, 8 words, slave 1":
// ASCII-frame buffer (all hex nibbles as ASCII)
// Request bytes (after the leading colon ':', before LRC):
// 01 03 0000 0008
// So the full hex character stream the wire must carry is:
// 3A 30 31 30 33 30 30 30 30 30 30 30 38 LRC_HI LRC_LO 0D 0A
// where LRC is the two's-complement modulo 256 of the SUM of bytes 0..12.

// Pseudo-code
FUNCTION_BLOCK FB_BuildModbusAscii
VAR
    txBuf  : ARRAY[0..16] OF BYTE := (
        16#3A,  // ':'
        16#30, 16#31,  // '0','1'  = slave 1
        16#30, 16#33,  // '0','3'  = function 03
        16#30, 16#30, 16#30, 16#30,  // '0','0','0','0' = address 0
        16#30, 16#30, 16#30, 16#38,  // '0','0','0','8' = qty 8
        16#??, 16#??,  // LRC ASCII HI/LO nibbles
        16#0D, 16#0A); // CR LF
END_VAR
  1. Calculate LRC: LRC = (256 - ((SUM of all bytes) MOD 256)) MOD 256; convert the LRC byte to two ASCII hex characters and append before CRLF.
  2. Use SEND_PTP(REQ:=TRUE, BUFFER:=#txBuf, LEN:=17, PORT:=...) when Ready.
  3. Configure RCV_PTP with a start condition of 0x3A and end condition of 0x0D 0x0A so the receive instruction times the silent interval to the LF byte.
  4. Verify LRC of incoming frames and check function code byte to drop exception responses (FC | 0x80).

Drawbacks: every project must re-write the same LRC and frame builder, status/error code coverage is worse than the Siemens libraries, and performance is lower because Freeport lacks DMA buffering. For one-off PRO2 integration this is acceptable; for production cells it is not.

Modbus ASCII Frame Anatomy (Reference for Verification)

Position Field Value (Read Holding Reg 0, slave 1, qty 8) Notes
1 Start char 0x3A ':' 1 ASCII byte on wire
2-3 Slave address 0x30 0x31 '01' Two ASCII hex chars
4-5 Function code 0x30 0x33 '03' Read Holding Register
6-9 Starting address high/low 0x30 0x30 0x30 0x30 '0000' 4 ASCII hex chars
10-13 Quantity of registers high/low 0x30 0x30 0x30 0x38 '0008' 4 ASCII hex chars
14-15 LRC high/low ASCII computed 2 ASCII hex chars
16-17 Frame end 0x0D 0x0A CR LF 2 ASCII control chars

An oscilloscope trace on the TX line will show 17 bytes of traffic (assuming a 4+nibble data length) with regular tiny gaps between ASCII characters; a bus analyzer (Accutek, Pitekom) will de-multiplex the LRC and confirm it. Modbus tools such as the Modbus Master / Modbus Poll toolkit can also log ASCII frames directly for debugging from a PC during commissioning.

RS-232 Cabling Between PRO2 and Master (DB9 Wiring)

The PRO2 Valley panel presents an RS-232 DB9 male DTE connector. Pin mapping standard for DTE-like device:

DB9 Pin Signal Direction at panel
2 RX Panel RX (input)
3 TX Panel TX (output)
5 GND
7 RTS Out (panel asserts hand-shake)
8 CTS In (panel expects host clear)

To connect to a CP341 RS-232 (DTE), wire a null-modem cable: TX-to-RX crossed, RX-to-TX crossed, RTS-to-CTS crossed, DTR/DSR crossed, GND-to-GND straight. On an ET200S 1SI (which uses Phoenix screw terminals labeled A+ A- / TX RX), the same logic applies: cross the directions.

Field tip: Start with no hardware handshake (drive RTS high at the master side, ignore CTS at the slave side) until you prove byte-level traffic. Handshake offloads can otherwise mask framing errors as silent timeouts.

Implementation Comparison Matrix

Criterion ET200S IM151-8 + 1SI S7-300/400 + CP341 + Driver Anybus Gateway S7-1200 + Freeport
Siemens part number(s) 6ES7151-8AB00-0AB0 + 6ES7138-4DF01-0AB0 6ES7341-1AH01-0AE0 + 6ES7870-1AC01-0YA0 External HMS gateway 6ES7241-1AH32-0XB0
Code complexity Low (Siemens library FB call) Medium (FB 82 call) None on PLC (config on PC tool) High (custom SCL, manual LRC)
Total hardware cost (relative) High High Medium Low (already present)
7-bit ASCII support Yes (native) Yes (driver enabled) Yes (configurable serial port) Yes (Freeport 7E1)
Modbus functions supported 01, 02, 03, 04, 05, 06, 15, 16 01, 02, 03, 04, 05, 06, 15, 16 Any (full map translation) Anything you implement
RT side data integrity LRC verified by Siemens FB LRC verified by Siemens FB LRC verified in gateway You must implement
Suitable for production cells Yes Yes Yes Not recommended
Suitable for retrofit/one-off Yes Yes Yes (preferred) Yes (if S7-1200 is fixed)
Field support / docs Siemens support portals Siemens support portals HMS support In-house only
Diagnostic depth Status word, error word Status word, error word Diagnostics via Config Mgr Whatever you code

Engineering Recommendation Order

  1. If the S7-1200 was selected only because of its CPU price and is otherwise an ET200S-friendly PROFINET controller, deploy the ET200S IM151-8 + 1SI. This is the lowest-risk option from a Siemens-vendor standpoint and reuses the same TIA Portal project.
  2. If the system already has a free S7-300 or S7-400 slot, the CP341 + Modbus ASCII driver is the standard solution; documentation exists for both the Master and Slave variants.
  3. If the S7-1200 is fixed and the panel is more than a few meters away, deploy an Anybus ASCII-to-RTU gateway on the panel side and standard RTU on the S7-1200 side. This avoids any custom code.
  4. Use the S7-1200 Freeport option only when there is one panel and zero willingness to buy hardware; document the LRC function so other engineers can read it.

Verification and Commissioning Procedure

1. Static checks

  • Confirm DB9 pin mapping with a multi-meter (continuity between chassis GND and pin 5).
  • Confirm the baud rate selection on the PRO2 (typically 9600/19200 set via the panel keypad). Match the master.
  • Confirm the panel is in Modbus ASCII mode (not Modbus RTU, not ECLink/VLan); there is usually a menu item.
  • Confirm the slave ID the PRO2 responds to (default 1, but consult the Valley PRO2 manual page on Communication).

2. Dynamic checks

  1. Connect the previously-tested MODSCAN32 (already proven by the source user) to the same RS-232 port; read holding register 0 and confirm it changes when you press keys on the panel. This confirms the panel side is alive.
  2. Swap the cable to the chosen master (1SI/CP341/CM 1241) and observe status LEDs or status words.
  3. Drive a single read (function 03, address 0, qty 1) and check the returned register value matches what MODSCAN reported.
  4. Drive a single write (function 06, register 0 to a known value) and verify the panel screen or MODSCAN reflects the change.

3. Stress checks

  • Sustained continuous read for at least 1 hour at a 100-ms cycle. Look for rising LRC error rates, an indication of electrical noise from VFD cables — add ferrite cores if so.
  • Reboot the panel mid-polling; confirm the master recovers without operator intervention.
  • Disable and re-enable the polling DB to confirm the master re-establishes cleanly.

Common Fault Code Mapping

Symptom Likely Cause Recommended Action
FB returns "slave timeout" Wrong baud rate / parity / data bits Re-verify 7E1 vs the panel manual default; cycle power on both devices
FB returns "LRC mismatch" Wrong number of data bits (8 instead of 7) — RX interprets ASCII letters as extended codes Force 7E1 in port configuration
FB returns "framing error" Ground potential difference, length > 15 m on RS-232 Use RS-422/RS-485 or fit an isolator
Slave replies with FC=83 (0x83 exception) Illegal function or illegal register address for the PRO2 Consult PRO2 holding-register map; some are read-only
Characters appear on scope, no response TX/RX not crossed — null-modem missing Re-wire or swap cable
Garbage characters / intermittent timeout Modbus RTU firmware still loaded on master Load Modbus ASCII driver on CP341, or use a true ASCII-capable module

FAQ

Does any firmware version of S7-1200 natively support Modbus ASCII?

No. Every S7-1200 CPU firmware (V1.0 to V4.6 currently) ships with the MB_MASTER / MB_SLAVE library for Modbus RTU only. There is no public Siemens option to switch the 7E1 character framing or generate LRC on a CM 1241; the library forces 8-bit framing and CRC. Modbus ASCII therefore requires external hardware or a freeport user program.

Can the CM 1241 in Freeport mode completely replace the ET200S 1SI?

Functionally yes; the Freeport instructions SEND_PTP and RCV_PTP support 7E1, and you can compute LRC and assemble/disassemble frames in SCL. However you assume responsibility for every status code, every exception response, every inter-character timeout, and every cyclic scan. For a one-off PRO2 panel it's acceptable; for a long-term production line prefer the ET200S 1SI or a gateway.

What is the practical difference between the CP341 and the ET200S 1SI module?

The CP341 is a central module for an S7-300/400 rack and needs the loadable Modbus ASCII master driver (6ES7870-1AC01-0YA0). The ET200S 1SI is a small modular device that plugs into a distributed rack addressed by an S7-1200 (or any PROFINET controller). Both expose similar Modbus master function codes; pick based on what host CPU you already have. The 1SI typically pulls slightly less panel space.

Does an Anybus gateway preserve the Modbus function codes 01/02/03/04/05/06/15/16 transparently?

Yes. The Anybus Communicator maps each transaction from a configurable serial sub-network onto a Modbus RTU/TCP register set on the network port. Function codes 03 (read holding) and 06/16 (write single/multiple) are passed through bit-for-bit. Only the LRC ↔ CRC translation and 7-bit ↔ 8-bit framing change; the data content (register addresses, values) remains identical on both sides.

What baud rate and parity should I configure for a PRO2 Valley control panel?

Valley PRO2 panels by default run Modbus ASCII at 19200 baud with even parity and 1 stop bit (7E1), but always confirm against the panel setup menu and the Valley PRO2 Service Manual before commissioning. Some operators set the panel to 9600/7E1 for longer cable runs.

Back to blog