Problem Statement: Receive Buffer Overflow on CJ1W-SCU21
A CJ-series Serial Communications Unit, most commonly the CJ1W-SCU21-V1, is configured in No Protocol mode and is connected to a device that streams more than 255 bytes per record. The first 10 bytes contain the payload of interest; the remainder of the record is irrelevant to the application but must not stall the receive path. Because the SCU21 will continue accepting bytes after the payload arrives, the operator observes a receive counter that climbs beyond the message size and eventually triggers either a reception overflow flag or a stuck Reception Completed bit.
The engineering question is: how do you flush the residual bytes from the SCU's internal ring buffer without resetting the entire module? A module reset would also reset the second port (typically a barcode scanner), losing in-flight scans. The required behaviour is a per-port buffer reset that leaves the other port and the PLC scan uninterrupted.
This article walks through the three field-proven approaches for a CJ1W-SCU21-V1:
- Execute an
RXDUinstruction with the byte-count operand set to 0 (N = &0) to clear the buffer in No Protocol mode without disturbing the other port. - Switch to Protocol Macro (PMCR) mode, where the receive buffer is 1000 bytes and the macro can match only the start-code/CR-LF delimited record of interest.
- Migrate to CJ1W-SCU22 / SCU32 / SCU42 and use
DRXDU/DTXDUimmediate-execution instructions on a CJ2M or CJ2H CPU for the same effect with higher throughput.
Hardware Identification: CJ1W-SCU21-V1 and Family
The CJ1W-SCU21-V1 is a two-port RS-232C Serial Communications Unit for the CJ-series PLC rack. It occupies one slot of the CJ expansion rack and exchanges data with the CPU over the high-speed bus using DM/EM CIO areas. The unit has reached end-of-life as of the April 2022 discontinuation notice, with the CJ1W-SCU22 (RS-232C), CJ1W-SCU32 (RS-422A/485), and CJ1W-SCU42 (RS-232C + RS-422A/485) listed as replacements.
| Catalog Number | Ports | Interface | No Protocol Buffer | Protocol Macro Buffer | Replacement Status |
|---|---|---|---|---|---|
| CJ1W-SCU21-V1 | 2 | RS-232C | 255 bytes | 1000 bytes | Discontinued (April 2022) |
| CJ1W-SCU22 | 2 | RS-232C | 255 bytes | 1000 bytes | Active replacement |
| CJ1W-SCU31-V1 | 2 | RS-422A/485 | 255 bytes | 1000 bytes | Discontinued (April 2022) |
| CJ1W-SCU32 | 2 | RS-422A/485 | 255 bytes | 1000 bytes | Active replacement |
| CJ1W-SCU41-V1 | 2 | RS-232C + RS-422A/485 | 255 bytes | 1000 bytes | Discontinued (April 2022) |
| CJ1W-SCU42 | 2 | RS-232C + RS-422A/485 | 255 bytes | 1000 bytes | Active replacement |
Source: CJ1W-SCU CJ-series Serial Communications Units specifications and the 2022 product discontinuation notice (PDN 2022-041).
For datasheet reference of the legacy unit, see the CJ1W-SCU21-V1 Mouser product page and the DigiKey listing. The authoritative operation manual is the W336 CS1/CJ1 Serial Communications Boards Operation Manual (EN).
Root Cause: No Protocol Mode Buffer Limits
In No Protocol mode the SCU acts as a transparent RS-232C / RS-422A gateway that terminates a frame on a configurable end-code character. Two physical limits apply:
- Receive buffer ceiling: 255 bytes per port, regardless of end-code.
- Reception completed flag: Set when the end-code is received AND the byte count is below 255.
When a remote device transmits a record longer than 255 bytes, the SCU21 will accept up to 255 bytes and then stop accepting further data on that port. The remainder of the frame remains in the line and will be received on the next SCU service interval if the remote device keeps the line asserted. If the end-code (<CR><LF> in this application) never falls inside the first 255 bytes, the Reception Completed Flag is never set, the Reception Counter reads 255, and subsequent RXDU reads return the stale payload plus a buffer state that does not refresh.
n+10 for Port 1 or n+20 for Port 2 (where n = 1500 × unit number). A reception counter that is stuck at 255 (0x00FF) or a Reception Overflow Flag bit that remains ON is the textbook symptom of an oversized frame in No Protocol mode.SCU Buffer Architecture and Status Words
The SCU publishes its state in the CPU's CIO area. For an SCU mounted as unit number m (1 through 3 for CJ-series, addressable up to 95), the base word n = 1500 × m gives the following layout:
| Word | Function | Notes |
|---|---|---|
| n + 9 | Port 1 / Port 2 error flags | Bit-level: overrun, framing, parity |
| n + 10 | Port 1 Reception Counter | Bytes currently waiting in the SCU buffer |
| n + 11 | Port 1 Reception Status | Reception Completed, Overflow, End-code received |
| n + 12 | Port 1 Send/Receive Complete Code | Result of last protocol macro step |
| n + 19 | Port 2 error flags | Mirror of n + 9 for port 2 |
| n + 20 | Port 2 Reception Counter | Bytes currently waiting in the SCU buffer |
| n + 21 | Port 2 Reception Status | Mirror of n + 11 for port 2 |
| n + 22 | Port 2 Send/Receive Complete Code | Mirror of n + 12 for port 2 |
Reception Status bit mapping (per W336):
- Bit 06: Reception Completed Flag (set when end-code received and bytes < 255).
- Bit 07: Reception Overflow Flag (set when the buffer would have exceeded 255 bytes).
-
Bit 14: Reception Counter 0 (cleared by
RXDU N=0).
These words give the application a polled view of the SCU buffer. A reception counter greater than 0 with the Reception Completed Flag OFF means bytes are still arriving; a reception counter stuck at 255 with the Overflow Flag ON confirms the No Protocol ceiling.
Solution 1: RXDU with N = 0 to Clear the Buffer
The RXDU (Receive via Serial Communications Unit) instruction reads bytes from the SCU's receive buffer into a destination word range and, optionally, clears the buffer state. The instruction format is:
RXDU(261) S C N D
S = Source Unit Address (1500 + 1500 × unit number)
C = Control word
Bit 00: 0 = port 1, 1 = port 2
Bit 15: 0 = store bytes in D, 1 = clear only (do not store)
N = Number of bytes to read (0000 to 0255 in No Protocol mode)
D = First destination word
Key behaviour: When N is set to 0, the SCU does not transfer any bytes to the destination area. Instead, it:
- Turns the Reception Completed Flag OFF.
- Turns the Reception Overflow Flag OFF.
- Resets the Reception Counter (word n + 10 / n + 20) to 0.
This makes RXDU N = &0 the textbook flush instruction. The other port is not touched, the SCU is not reset, and the PLC scan continues normally.
Typical implementation in a CJ1M-CPU13 ladder:
|--[ P_FirstCycle ]-- RXDU(261) 1500 &0100 &0 D0 |--
Here S = 1500 selects unit 1; the control word &0100 (binary 0000 0001 0000 0000) selects port 2 and the "clear only" bit; N = &0 requests the flush; D = D0 is a placeholder required by the instruction but is not written because N = 0.
For a polling flush driven by the Reception Overflow Flag:
|--[ CIO(n+11).07 = 1 ]-- RXDU(261) 1500 &0000 &0 D0 |--
Edge-trigger this with a DIFU if you want exactly one flush per overflow event.
Solution 2: Protocol Macro (PMCR) Mode with Matrix Search
Protocol Macro mode offloads the receive framing logic to the SCU. The receive buffer expands from 255 bytes to 1000 bytes, and the macro can be configured to search for a specific start-code, capture only the bytes between the start-code and the terminator, and ignore everything else. This is the cleanest solution for the application in the source: a record that begins with a capital T, is 13 bytes long, and ends with <CR><LF>, embedded inside a much longer broadcast.
The PLC triggers the macro with the PMCR(260) instruction:
PMCR(260) C1 C2 S N D
C1 = Control word 1 (bit 15 set = clear receive buffer on completion)
C2 = Control word 2 (port select and unit number)
S = First source word (step / sequence parameters)
N = Number of words of source data
D = First destination word (where macro writes step results)
The macro itself is built in CX-Protocol (part of CX-One) and downloaded to the SCU's flash. A typical three-step macro for the SCU21 looks like:
| Step | Type | TX Action | RX Action | Notes |
|---|---|---|---|---|
| 000 | TX_RX_Step1 | Send 12345<CR><LF>
|
Read 7 bytes into DM0000, terminate on <CR><LF> | Handshake poll |
| 001 | TX_RX_Step2, P | Send DM0010 contents followed by ,P<CR><LF>
|
Read 13 bytes between T and <CR><LF> into DM0030 |
Positive path, Matrix search |
| 002 | TX_RX_Step2, F | Send DM0020 contents followed by ,F<CR><LF>
|
Read 13 bytes between T and <CR><LF> into DM0040 |
Fault path, Matrix search |
To capture only the 13-byte record of interest inside an oversized broadcast, configure the RX condition as a Matrix search:
- Set the RX end-code to
<CR>with a length of 1 byte. - Add a secondary terminator
<LF>as the next character after <CR>. - Set the RX start condition to receive 'T' followed by 12 more bytes. The SCU discards every byte that arrives before
Tand stops accepting bytes after <LF>. - Enable "Data Discard" in the macro attributes so that bytes between macros are flushed automatically.
The relevant CX-Protocol attributes on the macro link:
| Attribute | Recommended Value | Effect |
|---|---|---|
| RX buffer size | 1000 | Maximum legal value for SCU21/22/32/42 |
| RX end-code | 0x0D 0x0A | Matches <CR><LF> from the remote device |
| Data Discard | Enabled | Flushes bytes that arrive between macro triggers |
| Error Processing | Clear buffer | Drops partial frames on overrun / timeout |
With these settings, the 255-byte-overflow problem disappears. The SCU never signals overflow because the buffer holds up to 1000 bytes, and only the 13-byte record that matches the matrix pattern is copied to the PLC's DM area.
Solution 3: Migration to CJ1W-SCU22 / SCU32 / SCU42
For greenfield or refurbishment projects on CJ2M-CPU3x or CJ2H-CPU6x CPUs, the recommended path is one of the active SCU replacements plus the new DRXDU / DTXDU immediate-execution instructions. The CJ2 CPU adds a parallel-execution engine for serial communications, so the receive handshake is no longer tied to the I/O refresh.
The DRXDU(261) instruction behaves like RXDU but executes as an immediate instruction in the same scan, regardless of end-code. The N = 0 flush behaviour is identical:
- Reception Completed Flag OFF.
- Reception Overflow Flag OFF.
- Reception Counter cleared to 0.
Key differences between SCU generations:
| Feature | CJ1W-SCU21-V1 (legacy) | CJ1W-SCU22 / SCU32 / SCU42 |
|---|---|---|
| Compatible CPUs | CJ1M, CJ1H, CJ2M, CJ2H | CJ2M, CJ2H recommended |
| No Protocol RX buffer | 255 bytes | 255 bytes (same) |
| Protocol Macro RX buffer | 1000 bytes | 1000 bytes (same) |
| RXDU instruction | Yes (refresh-synchronized) | Yes |
| DRXDU / DTXDU | No | Yes (immediate, CJ2 only) |
| Throughput | Standard | Higher (parallel engine on CJ2) |
| Lifecycle | Discontinued (April 2022) | Active |
If you must remain on a CJ1M-CPU1x, the new SCU22/32/42 units are still physically compatible, but the immediate-execution benefits only materialise on a CJ2-class CPU.
DM-m+52 and DM-m+53 pair used by DRXDU / DTXDU. Existing ladder code that calls RXDU against n = 1500 continues to work without change.Implementation: Setting Up Protocol Macro on the SCU21
The following procedure configures the CJ1W-SCU21-V1 port 1 in Protocol Macro mode at 9600,N,8,1. The settings are written from CX-Programmer or via the DM allocation area in the CPU.
- In CX-Programmer, expand I/O Table and confirm the SCU21 is recognised as unit number m (the default for a slot 0 expansion is m = 1).
- Open PLC > Edit > IO Table and Unit Setup and navigate to the SCU21's Port 1 Settings.
- Set the following fields:
- Port Mode: Protocol Macro
- Baud rate: 9600
- Data bits: 8
- Parity: None
- Stop bits: 1
- End code:
0x0D 0x0A(CR LF)
- Transfer the setup to the PLC and cycle power to the SCU slot so the new mode takes effect.
- Open CX-Protocol, create a new project bound to the SCU21, and build the three-step macro described in the previous section.
- Save the protocol macro project as a
.pswfile and transfer it to the SCU's flash via Protocol > Transfer To Unit. - Verify the macro is active by reading CIO
n + 12(Port 1 Send/Receive Complete Code). A value of 0x0000 means idle and ready.
The PLC ladder to invoke the macro on demand:
|--[ W0.00 ]-- PMCR(260)
C1 = &0001 ; clear RX buffer on completion
C2 = &0100 ; port 1, unit 1
S = D100 ; first parameter word
N = &3 ; three parameter words
D = D200 ; destination for macro result |
Word D100 selects the macro step (000, 001, 002). D200 receives the Reception Counter and D201 the Reception Status returned by the SCU. A Reception Counter of 13 with the Reception Completed Flag set confirms that only the matrix-matched record was captured.
Wiring and Port Configuration Checklist
Whether you stay in No Protocol mode with RXDU N = 0 or migrate to Protocol Macro, the physical layer must be sound. Use the W336 manual as the source of truth.
| Check | SCU21-V1 Expected Value | Verification Method |
|---|---|---|
| Port 1 RS-232C pin 2 (RD) | Data into SCU | Trace with scope, expect idle HIGH |
| Port 1 RS-232C pin 3 (SD) | Data out of SCU | Force a TX, confirm waveform |
| Port 1 RS-232C pin 5 (SG) | Signal ground | Continuity to remote SG |
| Port 1 RS-232C pin 4 (CTS) | High to enable TX | If remote does not drive CTS, loop RTS to CTS or strap high |
| Port 2 (barcode scanner) | Independent, shared ground only | Confirm traffic on scope while port 1 flush executes |
Pinouts and electrical limits (RS-232C driver output ≥ ±5 V into 3 kΩ, receiver threshold ±3 V) are documented in section 2 of the W336 manual.
Verification and Commissioning Procedure
Run the following checks after applying either solution:
-
Static check: With the remote device disconnected, read CIO
n + 10/n + 20. Both counters must read 0. - Trigger test: Send a 10-byte record from the remote device. The Reception Completed Flag must set within one SCU service interval (typically 10 to 50 ms depending on baud).
- Oversize test: Send a 300-byte record with the 13-byte matrix record embedded at the start. Confirm the Reception Counter reads 13 (not 300) and the Reception Overflow Flag stays OFF.
-
Flush test: In No Protocol mode, execute
RXDU N = &0. Confirm CIOn + 10returns to 0 within one scan and the Reception Completed / Overflow flags clear. - Cross-port test: Trigger a barcode scan on port 2 during a port 1 flush. Confirm the scan completes without error.
-
Soak test: Run the application for the production cycle time (60 seconds per the source application) and verify CIO
n + 12/n + 22do not show a non-zero error code.
Troubleshooting Matrix
| Symptom | Likely Cause | Fix |
|---|---|---|
| Reception Counter stuck at 255 | Frame exceeds 255 bytes in No Protocol mode | Switch to Protocol Macro or apply RXDU N=0
|
| Reception Overflow Flag stays ON | Flush instruction not executed | Edge-trigger RXDU N=0 on the flag's rising edge |
| Port 2 barcode scans lost during port 1 flush | Module reset executed instead of RXDU | Replace any RESET to the SCU with RXDU N=0
|
| Macro returns Complete Code 0x0C01 | Matrix start-code not found within 1000 bytes | Verify the remote device transmits 'T' before the 1000-byte buffer ceiling |
| Data truncated to 255 bytes in PMCR | CX-Protocol RX length field mis-configured | Set RX length to "Variable, end-code" rather than a fixed count |
| Reception Completed Flag never sets | End-code configured for port 2 only | Verify n+11 / n+21 end-code register matches the wire byte |
| Buffer clear returns counter to 0 but data still appears in DM | Previous RXDU wrote to D area first |
Execute RXDU N=0 as a separate rung before any read-with-store RXDU
|
| CTS forced low, no TX from SCU | Hardware handshake engaged and remote not driving CTS | Disable CTS/RTS in Port Settings, or loop pins 4-5 on the SCU side |
What is the maximum receive buffer size on the CJ1W-SCU21-V1?
In No Protocol mode the SCU21-V1 buffer is 255 bytes per port. In Protocol Macro mode the buffer extends to 1000 bytes per port. The ceiling is enforced by the SCU firmware regardless of how the end-code is configured.
Can I clear the SCU21 receive buffer without resetting the module?
Yes. Execute RXDU(261) with the byte-count operand set to 0 (N = &0) against the affected port. The Reception Completed Flag, the Reception Overflow Flag, and the Reception Counter all clear without touching the other port or the SCU module itself.
Which CIO words hold the SCU21 reception status?
For unit number m, the Reception Counter for port 1 is CIO n + 10 and for port 2 is CIO n + 20, where n = 1500 × m. Reception Status flags are at n + 11 and n + 21 respectively. Bit 06 is Reception Completed, Bit 07 is Reception Overflow.
Is Protocol Macro mode required to handle messages longer than 255 bytes?
For the CJ1W-SCU21-V1, Protocol Macro mode is the recommended path because the buffer ceiling rises to 1000 bytes and the macro can matrix-search for the start-code-terminated record of interest. Alternatively, RXDU N = 0 with a per-port flush and a handshaking delay achieves the same effect in No Protocol mode without changing the mode setting.
What replaces the discontinued CJ1W-SCU21-V1?
Omron's April 2022 discontinuation notice lists the CJ1W-SCU22 (RS-232C x2), CJ1W-SCU32 (RS-422A/485 x2), and CJ1W-SCU42 (RS-232C + RS-422A/485) as replacements. On a CJ2M or CJ2H CPU, these units gain immediate-execution DRXDU / DTXDU instructions and higher serial throughput.