1. Overview
The Siemens CP 340 and CP 341 communication processors are point-to-point (PtP) modules used in S7-300 stations to exchange serial data with field devices such as barcode scanners, weigh scales, RFID readers, printers, and radio data terminals. Both modules support the ASCII driver, a transparent character-oriented transmission scheme suitable for any partner device that streams printable characters terminated by a user-defined end delimiter.
Unlike 3964(R), the ASCII driver does not implement any handshake or block-checking protocol of its own. It is therefore ideal for simple unidirectional or half-duplex links where the partner device is the bus master and the CP module responds on request. This article walks through the entire configuration chain — from selecting the correct hardware variant to commissioning a working ASCII link in STEP 7 — and finishes with a troubleshooting matrix and a multi-station polling note referenced from Siemens' official knowledge base.
0D0A carriage return + line feed) as a message terminator. Confirm with the partner device which delimiter, character set, and (if any) flow-control lines it expects.2. CP 340 vs. CP 341 — Hardware Selection
Before configuration, identify which module is installed. Both share the same physical footprint and STEP 7 integration, but they differ in protocol flexibility:
| Feature | CP 340 | CP 341 |
|---|---|---|
| ASCII driver | Yes (firmware-loaded) | Yes (loadable driver) |
| 3964 / 3964R driver | Yes (fixed) | Yes (loadable) |
| Modbus master/slave (loadable) | No | Yes (optional) |
| User-defined protocols | No | Yes (free ASCII / RK512 via loadable driver) |
| Typical MLFB (RS-232C) | 6ES7 340-1AH02-0AE0 | 6ES7 341-1AH02-0AE0 |
| Typical MLFB (RS-422/485) | 6ES7 340-1BH02-0AE0 | 6ES7 341-1BH02-0AE0 |
The two physical interfaces matter for wiring:
- RS-232C (AH variant): point-to-point only, full-duplex, max. 19.2 kbit/s (CP 340) or 115.2 kbit/s (CP 341). Handshake lines RTS/CTS, DTR/DSR, DCD available.
- RS-422/485 (BH variant): two-wire or four-wire, half- or full-duplex. RS-485 supports multi-drop networks when used with multi-station polling (see CP340/CP341 multi-station polling based on ASCII driver protocol).
3. Prerequisites
- STEP 7 V5.x (SP2 or later recommended) — the CP 340/341 is configured via HW Config and parameterised with the supplied CP PtP library. TIA Portal supports both modules through HSPs but the workflow is essentially identical.
- CP PtP parameter assignment tool — installed as part of STEP 7 (or the TIA Portal "PtP" option package). The tool generates the parameter data block and exports the FBs P_SEND, P_RCV, P_PRINT, and (CP 341) P_INIT.
- Partner device protocol description — baud rate, parity, data bits, stop bits, end-of-frame delimiter, and any flow-control expectations. Without this, ASCII frames cannot be parsed correctly.
- Wiring hardware — shielded serial cable, correct pinout for the CP variant, and a termination resistor (220 Ω) if the bus is RS-485.
- Firmware order numbers for the loadable drivers if using a CP 341 with the Modbus RTU driver; for the ASCII driver alone, no licence is required.
4. Understanding the ASCII Driver
The ASCII driver is intentionally minimal. It performs four functions:
- Framing — every byte received or transmitted is treated as a printable 7- or 8-bit character. No STX/ETX, length field, or CRC is inserted by the CP.
-
End-of-frame detection — a user-defined one- or two-character sequence marks the end of a message. Default is
CR(0D); typical with PCs and barcode scanners isCR+LF(0D0A). The CP strips the end code on reception (option) and appends it on transmission. - Buffering — the CP contains an internal ring buffer (up to 1024 bytes depending on firmware). The user program reads or fills this buffer through the FBs.
-
Flow control (optional) — XON/XOFF (
11/13) or hardware handshake using RTS/CTS. Either is selectable in HW Config.
Because the driver is unframed, the application program is fully responsible for parsing message structure (address, command, data, checksum) if any is required. For RFID/RDT, scale, or scanner applications this is rarely an issue: the partner device produces a self-delimited ASCII string per transaction.
5. Hardware Configuration in STEP 7
- Open the S7-300 station in HW Config and slot the CP 340/341 into a free slot (typical slot 4 for the first CP). The module is found under SIMATIC 300 > CP-300 > PtP.
- Double-click the module to open Properties — CP 340/341.
- In the Addresses tab, note the I/O address range. The default diagnostic address is
FFFF(no diagnostics); recommended is to assign a real address such as272and enable Diagnostics interrupt. - Switch to the Basic Parameters tab and select ASCII driver as the protocol. (Selecting 3964 or 3964R disables ASCII — only one protocol is active per CP.)
- Open the Protocol Parameters sub-dialog. The fields are described in the next section.
- Save and compile the station. STEP 7 will then prompt you to call the CP PtP parameter assignment tool — do this immediately.
6. Parameter Assignment for the ASCII Driver
Open the CP PtP parameter assignment tool. It generates a DB (e.g. DB100 "CP340_DB") containing the runtime parameters. Edit the following values:
| Parameter | Typical value | Notes |
|---|---|---|
| Baud rate | 9600 / 19200 / 38400 / 57600 / 115200 bit/s | Must match the partner device. CP 340 max 19200; CP 341 max 115200. |
| Data bits | 8 | 7 only if partner is hardware-mandated to 7-bit ASCII. |
| Stop bits | 1 | 2 used for legacy 110/300 bit/s devices. |
| Parity | None / Even / Odd | "None" is most common for modern terminals. |
| End-of-frame on send |
0D (CR) or 0D0A (CR+LF) |
Appended by the CP automatically. Disable only if the partner adds its own terminator. |
| End-of-frame on receive | Same code as above | Defines when the CP marks a message as "complete" and signals the FB. |
| Wait time for end code | 200 ms (default 4 s) | Maximum time the CP waits for the end code after the first character. |
| Flow control | None / XON-XOFF / RTS-CTS | Use RTS-CTS for RS-232C where the partner drives CTS. |
| Strip end code on receive | Yes / No | "Yes" simplifies parsing; "No" preserves the delimiter for verification. |
7. Communication Function Blocks (P_SEND / P_RCV)
After saving the parameter DB, the CP PtP tool links the standard PtP library into your S7 program. The relevant blocks for ASCII transmission are:
| Block | Function | Typical instance DB |
|---|---|---|
| P_SEND (FB3) | Transmits a buffer from the user program to the CP. Returns DONE, ERROR, STATUS. | DB3, DB4, ... per call |
| P_RCV (FB2 / FB4) | Receives a completed frame from the CP. Returns DONE, ERROR, STATUS, LEN. | DB2, DB5, ... per call |
| P_PRINT (FB5) | Sends formatted print jobs to a serial printer (ASCII only). | DB6 ... |
| P_INIT (FB10, CP 341 only) | Re-loads parameters from the parameter DB at runtime. | DB10 ... |
All blocks use a background DB (the instance DB) that the CP PtP tool pre-wires to the CP's logical address. The block interfaces are standardised across CP 340 and CP 341.
8. Data Block Design
User data is held in a normal global DB, structured as a STRING or an ARRAY of BYTE. The STRING form is preferred for ASCII data because STEP 7 automatically manages the length byte:
DATA_BLOCK "DB_ASCII_MSG"
STRUCT
sOut : STRING[80]; // "STATUS:READY\r\n"
sIn : STRING[80]; // populated by P_RCV
iLen : INT; // actual received length
END_STRUCT
END_DATA_BLOCK
When passing sOut to P_SEND, supply the address as P#DB_ASCII_MSG.sOut with length DB_ASCII_MSG.sOut.LEN. Avoid passing the maximum declared length (80) — that fills the bus with trailing 00 bytes. Always send only the populated portion.
9. Sample ST / LAD Code
ST — send a command on a positive edge of a push-button:
IF "START_SEND" THEN
"DB_ASCII_MSG".sOut := 'ACK';
"DB_ASCII_MSG".sOut.LEN := 3; // important: update length
"P_SEND_DB"(REQ := TRUE,
LADDR := 272,
DB_NO := 100, // parameter DB
DBNO := W#16#0, // not used in ASCII
LEN := "DB_ASCII_MSG".sOut.LEN,
BUFFER:= P#"DB_ASCII_MSG".sOut,
DONE := "sDONE",
ERROR := "sERR",
STATUS:= "sSTAT");
"START_SEND" := FALSE;
END_IF;
LAD equivalent (cyclic call in OB1):
- Place a normally-open contact labelled
Send_Trigger. - On the rung, drop the P_SEND instance. Wire
REQto the contact,LADDRto the CP address,BUFFERandLENto the data block, and wire the status outputs to flag words. - Use the
DONEoutput to reset the trigger and theERRORoutput to drive a fault indicator. - Drop a separate P_RCV call in OB1 with a fixed
EN_R := TRUE. The FB will setDONE := TRUEand write the received length toLENonce a complete frame arrives.
10. Multi-Station Polling (CP 341 / RS-485)
When several ASCII devices share an RS-485 bus, the CP can be configured to poll each station in turn. Siemens' official application example walks through parameter assignment for the multi-station polling scheme:
"This document gives a specific example to introduce polling communication between multiple Siemens serial communication modules (CP340/CP341)."
CP340/CP341 multi-station polling based on ASCII driver protocol
For an RDT (radio data terminal) used as a single peer, multi-station polling is unnecessary and adds complexity. Use it only when the partner device expects a polled address byte and reply window.
11. Commissioning and Verification
-
Loop-back test: before connecting the partner, place a wire jumper between TX and RX on the CP side (pins 2–3 on a DB-9 for RS-232C; A ↔ A', B ↔ B' loop on RS-485). Run a
P_SENDwith a known string and confirmP_RCVreturns the same string. This isolates the CP from the partner. - Diagnostic buffer check: open PLC > Diagnostic Buffer on the online station. Any CP startup or frame error will be recorded with a hex OB82 / OB1 entry (e.g. Communication error to module).
- Frame monitor: enable the CP's trace in the parameter tool. The trace logs the last 256 bytes transmitted and received with timestamps.
- Partner test: connect the field device and trigger a scan. Verify in the trace that the request matches the documented format and that the reply terminates with the configured delimiter.
-
Status word: if
P_SEND.STATUSreturns0x0001the request is in progress;0x0000DONE;0x80xxparameter or sequence error. Cross-reference the CP 340 manual Appendix A for the full STATUS list.
12. Troubleshooting Matrix
| Symptom | Likely cause | Corrective action |
|---|---|---|
| P_SEND never sets DONE; STATUS = 0x0001 | Handshake line not asserted (RTS/CTS) | Switch to XON/XOFF or "no flow control"; verify wiring of CTS at partner. |
| P_RCV returns DONE with LEN = 0 | End code mismatched | Confirm the actual frame terminator with a scope or terminal emulator; re-enter in HW Config. |
| SF LED on CP; diagnostic buffer shows "parameter error" | Parameter DB was modified in the user program | Reload DB from the CP PtP tool; do not edit the parameter DB at runtime unless using P_INIT. |
| Characters received are garbled (e.g. "St?tu?Rdy") | Baud rate, parity, or data bits mismatch | Verify against partner manual; try 7-E-1 if 8-N-1 fails. |
| CP not detected in HW Config | Wrong GSD / missing HSP | Install the latest CP340/341 HSP for your STEP 7 version; restart HW Config. |
| Every other character dropped on RS-485 | Missing or wrong termination | Install 220 Ω at both bus ends; confirm A/B polarity (Siemens convention: A = DATA+, B = DATA-). |
| Send works, receive returns ERROR 0x8321 | Receive buffer overflow in CP | Reduce poll rate on partner side or call P_RCV more frequently in OB1 (≤ 50 ms cycle). |
Does the CP 340/341 convert integers to ASCII automatically?
No. The ASCII driver is byte-transparent; the application program must build the character string (for example with the IEC INT_TO_STRING function in STEP 7) before passing it to P_SEND. The CP then transmits the bytes verbatim and appends the configured end code.
Which data block stores the ASCII message?
Any user-defined global DB of type STRING or ARRAY OF BYTE. The CP's own parameter DB (for example DB100) is generated by the PtP tool and should not be used to hold application payload — keep the parameter DB and the data DB separate for clarity and to allow online reload of parameters.
Can the CP 340 communicate with a Modbus RTU device in ASCII mode?
Not reliably. Modbus RTU uses binary frames with silent intervals and a CRC, which the ASCII driver does not implement. For Modbus RTU on a CP 341, install the loadable "Modbus Master" or "Modbus Slave" driver instead. Use the ASCII driver only for truly character-oriented partners (scanners, scales, RDTs, legacy printers).
What is the maximum cable length for RS-232C ASCII communication?
RS-232C is rated for 15 m at 19.2 kbit/s. If the RDT is further away, switch to the RS-422/485 CP variant (BH MLFB) which supports up to 1200 m at lower baud rates. Note that RS-422/485 requires an additional receiver hardware handshake strategy unless XON/XOFF is acceptable.
How do I reset the CP 341 parameters at runtime?
Call the P_INIT FB (FB10) with the parameter DB number and the new SSNR (station number). P_INIT re-loads the entire parameter set from the DB into the CP's volatile memory. The CP returns STATUS = 0x0000 on success. This is useful when the same CP is reused for different partner profiles without re-downloading HW Config.