S7-1200 CB 1241 Modbus RTU Keypad Integration: Setup Guide

David Krause12 min read
S7-1200SiemensTutorial / 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

S7-1200 CB 1241 Modbus RTU Keypad Integration: Setup Guide

Overview

This guide documents the field-proven procedure for integrating an industrial numeric/directional keypad — originally wired to a Schneider Electric Modicon PLC — onto a Siemens SIMATIC S7-1200 CPU 1214C using the CB 1241 RS485 communication module and the Modbus RTU master instruction set available in TIA Portal. The procedure focuses on the CB 1241 as the physical RS485 transceiver, the Modbus RTU library blocks (MB_MASTER, MB_COMM_LOAD) for the protocol stack, and the data block sizing rules that govern successful register polling of an unknown slave device.

The reference design was validated against a CPU 1214C DC/DC/DC with firmware V4.x and TIA Portal V16/V17. Where firmware-dependent differences exist, the divergence is called out explicitly.

Critical first step: RS485 is a physical layer, not a protocol. Before any programming is written, confirm whether the keypad actually speaks Modbus RTU, a vendor-proprietary protocol, or a freeport frame. The CB 1241 supports both Modbus RTU (with library) and Freeport (user-defined USS/raw) modes. Choosing the wrong mode produces timeouts that look identical on the surface but have completely different remedies.

Prerequisites

Before commissioning, gather the following:

  • SIMATIC S7-1200 CPU 1214C (or 1211C/1212C/1215C/1217C) with at least one free signal-board slot for the CB 1241. Verify with the CB 1241 RS485 Specifications page that the slot position is supported on your CPU revision.
  • CB 1241 RS485 (6ES7241-1CH30-1XB0) communication module or signal board (6ES7241-1CH32-1XB0).
  • TIA Portal V16 or later with the "S7-1200 Modbus RTU" library installed (part of the standard installation under "Libraries" → "Modbus RTU").
  • A USB-to-RS485 converter (FTDI FT232 or equivalent) plus a serial monitor tool — Hercules SETUP, Modbus Poll, or an industrial protocol analyzer — to capture the keypad's native output if the protocol is unknown.
  • Original keypad documentation or a known-good wiring diagram from the prior Schneider installation. If unavailable, the keypad must be characterized empirically as described in the Protocol Identification section.
  • 24 V DC control power for the keypad supply and termination resistors (typically 120 Ω at each end of the RS485 segment).

CB 1241 RS485 Hardware Specifications

The CB 1241 RS485 module is a 2-wire half-duplex transceiver that meets the EIA-485 (TIA-485) standard. The following table summarizes the electrical limits that govern field wiring decisions; refer to the official CB 1241 RS485 Specifications document for full values.

Parameter Specification
Module type RS485 (2-wire half-duplex)
Connector Removable 6-pin terminal block
Common-mode voltage range -7 V to +12 V, 1 second; 3 V RMS continuous
Transmitter differential output Min 1.5 V across 54 Ω load (per TIA-485)
Receiver input sensitivity ±200 mV differential threshold
Maximum cable length 1,000 m at ≤ 19.2 kbps; derate for higher baud
Supported baud rates 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200 bps
Supported parity None, Even, Odd, Mark, Space (8E1, 8N1, 8O1 typical)
Isolation Functional isolation from logic; no channel-to-channel isolation on a single CB 1241
The common-mode range of -7 V to +12 V is critical when the keypad is mounted on a separate panel with a different ground reference. Exceeding this range (for example, due to a building ground-potential rise) will damage the receiver. In multi-building installations, install an RS485 isolator (e.g., Phoenix Contact MINI MCR or similar) between the keypad and the CB 1241.

RS485 Wiring and Signal Considerations

RS485 relies on a differential pair (Data+ / Data-) with a shared reference ground. The CB 1241 terminal block has the following pinout:

Pin Signal Function
1 TxD+/RxD+ (non-inverting) Data A (often labeled D+ or B depending on vendor convention)
2 TxD-/RxD- (inverting) Data B (often labeled D- or A depending on vendor convention)
3 RTS (TTL-level) Direction control for RS485 transceivers with hardware direction control (not used by default on CB 1241)
4 M Signal ground / reference
5 +5 V Auxiliary 5 V supply for external converter (max 100 mA)
6 Reserved / shield termination point

Vendor labeling mismatch is the single most common wiring fault. Schneider, Siemens, and many keypad vendors all label the non-inverting line differently. Always verify with a multimeter and an oscilloscope before energizing:

  1. Power the keypad and measure the idle-line voltage between the two data lines with no PLC connected. The idle (mark) state should show Data+ more positive than Data- (typical +200 mV to +5 V differential).
  2. Press a key and observe the differential waveform. Confirm the polarity matches the CB 1241 pinout above.
  3. If polarity is reversed, swap the two data conductors at the CB 1241 terminal block only — never at the keypad, because the keypad may share its ground with a shielded cable that is bonded at one end.

Terminate the segment with a 120 Ω resistor between Data+ and Data- at the far end (at the keypad) and optionally at the CB 1241 end, depending on cable capacitance. Never place termination in the middle of the run.

Protocol Identification Strategy

Because the keypad is being migrated from an unknown Schneider configuration, the first engineering task is to determine what protocol the keypad actually emits. Use a USB-to-RS485 converter connected to a PC and a serial monitor to capture raw bytes.

  1. Disconnect the keypad from the CB 1241.
  2. Connect the USB-to-RS485 converter across the keypad's data lines with the same reference ground.
  3. Configure the serial monitor at the most common defaults: 9600, 8N1, no flow control.
  4. Open the port in HEX display mode and press a key on the keypad.
  5. Observe the frame:
    • If the frame begins with 01 03 ... (slave address 1, function code 3 = Read Holding Registers), the device is a Modbus RTU slave and the PLC must be the master.
    • If the frame begins with a vendor-specific header (e.g., 5A A5 or FE FE) and is followed by a fixed-length payload with checksum, the device uses a proprietary protocol and the CB 1241 must be switched to Freeport mode with user-defined send/receive logic.
    • If no frames appear, the keypad may be polled (slave) and only transmit when addressed. In that case, use Modbus Poll (WinTech) as a master simulator to poll common addresses (1, 2, 247) with function codes 01, 02, 03, 04 and observe the response.

Once the protocol is confirmed as Modbus RTU, note the slave address, baud rate, parity, and the register mapping for at least one key. This dataset becomes the basis for the PLC program.

TIA Portal Hardware Configuration

With the keypad confirmed as a Modbus RTU slave, configure the CB 1241 hardware object:

  1. In the TIA Portal project tree, open Devices & Networks and select the S7-1200 CPU.
  2. Locate the signal-board slot on the front of the CPU. Drag the CB 1241 (RS485) into the slot. TIA Portal auto-assigns the module name (e.g., CB_1241_1) and the diagnostic address space.
  3. Open the CB 1241 properties and select Port configuration:
Parameter Value (matches keypad) Notes
Transmission rate 9600 bps (typical) Match exactly to keypad
Parity Even (8E1) typical for Modbus RTU Modbus spec recommends 8E1
Data bits 8 Modbus RTU uses 8 data bits
Stop bits 1 Modbus spec recommends 1 stop bit
Flow control None CB 1241 supports none or XON/XOFF
End time of message 10 ms default (3.5 character times at 9600) Raise to 50 ms if silent intervals are large

Modbus RTU Program Structure

The Modbus RTU library consists of two blocks:

  • MB_COMM_LOAD (FB / background DB) — initializes the port once on startup. Mode 4 = RS485 half-duplex. This block must run once and only once per port transition from STOP to RUN.
  • MB_MASTER (FB / instance DB) — performs individual Modbus transactions. Multiple instances are allowed as long as they share the same port background DB.

The wiring is straightforward: MB_COMM_LOAD writes the port configuration into the CB 1241 hardware identifier, then MB_MASTER issues read/write requests. Each master call uses a request/response pair and increments DONE or ERROR.

Sample MB_MASTER call

The following structured text excerpt shows a polled read of holding registers (function code 03) from slave address 1, register 0, length 19 words, into Slave_data:

// MB_MASTER call - poll keypad holding registers
MB_MASTER_1.DB(REQ := TRUE,                       // Trigger on rising edge
               MB_ADDR := 1,                       // Keypad slave address
               MODE := 0,                          // 0 = Read holding registers (FC 03)
               DATA_ADDR := 0,                     // Starting register (Modbus 0-based)
               DATA_LEN := 19,                     // Number of words to read
               DATA_PTR := "Slave_data".Data);

Note the explicit cast "Slave_data".Data: the DATA_PTR parameter of MB_MASTER requires a ARRAY[0..n] OF WORD or ARRAY[1..m] OF WORD element depending on the block version. TIA Portal V16+ accepts a flexible array; older versions are strict on the lower bound.

Data Block Sizing and Array Structure

This is the point where most first-time integrations fail silently. The Modbus master block uses DATA_PTR as both source and destination. Its element count must exactly equal DATA_LEN, and the array bounds must be valid for the block's lower-bound check.

Create a global DB called Slave_data with the following structure:

DATA_BLOCK "Slave_data"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
  STRUCT
    Data : ARRAY[1..19] OF WORD;   // Must match DATA_LEN in MB_MASTER
    Error : WORD;                  // Last error code from MB_MASTER STATUS
    LastKey : WORD;                // Decoded key value
  END_STRUCT;
END_DATA_BLOCK
Why ARRAY[1..19] and not ARRAY[1..10]: A 10-word array fails when DATA_LEN is set to anything other than 10 because the master block validates the upper bound. Many keypads use a fixed 19-word payload to cover keys, status, and checksum. If the array is undersized, the master call returns STATUS = 0x80C8 ("Invalid pointer or data length"). The corrective action is to size the array to the maximum expected response length.

Once the data lands in Slave_data.Data[1..19], the application logic can decode the pressed key. Most numeric keypads report the digit value in the first word and direction flags in subsequent words. Consult the keypad vendor datasheet for the exact register map.

Verification and Commissioning

After the program compiles and downloads, perform the following checks in order:

  1. Hardware check: With the CPU in STOP, verify the CB 1241 TX and RX LEDs are off. Place the CPU in RUN and confirm the port LED blinks green briefly during MB_COMM_LOAD.
  2. Initialization check: Monitor MB_COMM_LOAD.DONE = TRUE and MB_COMM_LOAD.ERROR = FALSE. If ERROR is true, the configuration parameters are rejected before any Modbus traffic.
  3. Master polling: Trigger MB_MASTER.REQ once per scan or via a periodic timer (50–100 ms typical) and monitor DONE. Pressing a key on the keypad should clear DONE momentarily and set it again on the next poll completion.
  4. Payload verification: Place a watch table on Slave_data and press each numeric key and direction key. Confirm each press updates a unique word or bit pattern in the array. Cross-reference with the captured USB-to-RS485 trace from the Protocol Identification step.
  5. Error recovery: If MB_MASTER.STATUS returns 0x80C8, the array size is wrong. If it returns 0x80C9, the slave address is wrong or the slave is not responding. If it returns 0x80CA, a CRC error was detected — check wiring and termination.

Modbus RTU Error Code Reference

STATUS (hex) Meaning Typical Cause
0x0000 No error
0x80C8 Invalid pointer / data length mismatch DATA_PTR array size ≠ DATA_LEN
0x80C9 Modbus address out of range or no response Wrong slave address or wiring break
0x80CA CRC error Noise on cable, missing termination, wrong parity
0x80CB Invalid function code Keypad uses function code not supported by MB_MASTER
0x80CC Invalid data address Requested register does not exist on slave
0x80CD Invalid data length DATA_LEN exceeds slave register map
0x80CE Slave busy / timeout Slave did not respond within inter-character timeout
0x80CF Memory parity error PLC diagnostic — not a Modbus error

Troubleshooting Matrix

Symptom Likely Root Cause Corrective Action
No RX activity on CB 1241, MB_MASTER ERROR = 0x80C9 Polarity reversal or break in data pair Swap D+/D- at the CB 1241 terminal; verify cable continuity
RX activity present but constant CRC errors (0x80CA) Missing or dual termination; ground loop Install 120 Ω at keypad end only; add RS485 isolator
Reads complete but values are garbage or shifted Wrong byte order (word swap) or wrong register map Cross-check against USB-to-RS485 capture; swap bytes manually
MB_MASTER DONE never sets, REQ stays TRUE Two master instances colliding on the same port Sequentialize requests with a single REQ chain; do not call from OB1 + cyclic OB
First key press appears in TIA, subsequent presses ignored Keypad expects FC 04 (input registers) not FC 03 (holding) Change MODE parameter or expand to poll FC 01/02/04
Works in lab, fails on shop floor EMI from VFD on adjacent cable tray Re-route cable, use shielded twisted pair with shield grounded at one end

Frequently Asked Questions

What firmware version of the S7-1200 is required for Modbus RTU master on CB 1241?

Firmware V4.0 or later is required. The Modbus RTU library blocks were restructured between V3 and V4; projects written for V3 will need to be regenerated against the V4 library before downloading to a V4 CPU.

Can the CB 1241 act as a Modbus RTU slave instead of master for a keypad?

Yes — the library provides an MB_SLAVE block. However, if the keypad is the device that initiates transmission (i.e., the keypad is the master), the CB 1241 must be configured as the master. Determine the master/slave relationship from the protocol identification step before choosing the block.

Why does an array of 10 words fail when DATA_LEN is 19?

The MB_MASTER block performs a runtime bound check on DATA_PTR. If the upper bound of the array is less than DATA_LEN, the block rejects the request with STATUS 0x80C8. Resize the array to ARRAY[1..19] OF WORD to match the polling length.

How do I confirm the keypad speaks Modbus RTU without the original Schneider program?

Capture the keypad's transmit frame with a USB-to-RS485 converter and a serial monitor set to HEX display. A Modbus RTU frame begins with the slave address byte (1–247) followed by a function code in the range 1–127. If the frame begins with a vendor-specific header or does not respond to address polling from Modbus Poll, the device uses a proprietary protocol and must be handled via Freeport.

What is the maximum polling rate for CB 1241 Modbus RTU at 9600 baud?

A 19-word read at 9600 baud takes approximately 35 ms end-to-end (8 ms transmit + 8 ms silent interval + ~19 ms slave response). Set the master trigger to 50 ms or longer to avoid queue collisions and to leave CPU bandwidth for the application. At 19200 baud, the same transaction takes about 18 ms and can be polled at 25 ms.

Back to blog