IMDHMIControls LibraryShop main store

Troubleshooting

Why CODESYS CANopen goes error-passive on a RevPi CAN bus

Industrial networks Published 7 min read

Short answer

A RevPi Con CAN node reports ERROR-PASSIVE with a transmit error counter of 128 when no other active node acknowledges its frames. Keep a second powered node at the matching bitrate, start the external master first when the RevPi is the slave, and keep the multiply-by-1000 conversion in the bitrate script. The counter pattern tells you which of these is missing.

On this page
  1. The counter behind ERROR-PASSIVE
  2. Read the two snapshots correctly
  3. Why the green circles prove nothing
  4. Bring the bus up in the right order
  5. Check the bitrate script and where the driver looks
  6. Counting the unacknowledged frames that made can0 passive
  7. The decision for each case
  8. Questions asked

A RevPi Con CAN that comes up ERROR-PASSIVE with a transmit error counter of 128 and a receive counter of 0 is transmitting onto a bus where nothing answers. CAN counts a frame as sent only when another active controller fills its acknowledge slot, and sixteen unacknowledged attempts are enough to push a node into the passive state. The correction is on the bus, not in the CANopen objects: keep a second powered node at the matching bitrate, start the external master first when the RevPi is the slave, and keep the multiply-by-1000 conversion in the bitrate script. Here is how to read the snapshot, which fix belongs to which reading, and how to prove the result.

The counter behind ERROR-PASSIVE #

ISO 11898-1 gives every CAN controller a transmit error counter and a receive error counter. A transmitter that detects an error — an acknowledge slot left empty is one — adds 8 to its transmit counter, and a frame that completes subtracts 1. Below 128 the node is error-active; at 128 it becomes error-passive; a transmit counter that keeps climbing ends in bus-off.

A lone node therefore walks itself passive with perfect wiring: the cable is fine, there is simply nobody to answer. An unpowered peer, a transceiver that was never enabled, a node at a different bitrate, or an interface in listen-only mode all fail to acknowledge the same way. This sits below CANopen, which is why the manager never reports it; the reading has to come from the controller state on can0.

The readings here come from a RevPi Connect Plus with a Con CAN module on the bridge, running CODESYS Development System 3.5 SP16 Patch 4, CODESYS Control for Raspberry Pi 4.0.1.0 and Revolution Pi Bridge package 1.0.1.99 on kernel 4.19.95-rt38-v7. The error-confinement arithmetic belongs to the standard and holds on any CAN controller; the script and configuration names belong to that runtime.

Read the two snapshots correctly #

One command answers both questions, whether the interface is up and why it went passive: ip -det -statistics link show can0, run before the application runs and again after the bus misbehaves.

Before the runtime enabled the interface, this case showed the link down, CAN state STOPPED, and both error counters at zero: an idle controller, which says nothing about the health of the bus. After the reboot it showed the link flags UP and LOWER_UP, CAN state ERROR-PASSIVE with the transmit counter at the passive threshold and the receive side at zero, a bitrate of 1000000 bit/s, and zero RX and TX packets.

Reading on can0 What it tells you What to do next
Link down, CAN state STOPPED, both counters zero The controller is inactive; nothing has been attempted Enable the interface and start the runtime, then re-read
Flags UP and LOWER_UP Linux enabled the link Proves nothing about the wire; read the CAN state and the counters
CAN state ERROR-PASSIVE, berr-counter tx at the threshold, rx 0 The transmitter ran out of acknowledgement Supply an active peer; then check bitrate, wiring and termination
RX and TX packet counts stuck at zero No frame has completed in either direction Re-read during intended traffic and compare

Why the green circles prove nothing #

Delete the CAN-Bus and CANopen Manager objects from the project and every circle in online mode turns green. That proves the runtime enumerates the configured devices across the bridge — nothing more, because nothing now transmits on can0. Use the stripped project once, to separate a runtime or bridge problem from a bus problem, then put the CAN objects back; acceptance needs the full path. If the real destination for this data is an S7-1500 rather than a CANopen network, the gateway route in why a RevPi Connect S needs a PROFINET gateway for an S7-1500 avoids the CAN bus altogether.

Bring the bus up in the right order #

Each step below closes one of the causes behind why a RevPi CAN Con shows can0 but receives no data, in the order you should test them.

  • Seat and wire the module. Con CAN sits in the right-side bridge position as configured in the IDE, with CAN_H and CAN_L checked against each device's terminal documentation. A nominal 120 Ω terminator belongs at each physical end of the bus, about 60 Ω measured across the pair — and take that resistance reading only with the network de-energized.
  • Enable it on the Pi side. Run sudo revpi-config enable revpi-con-can, reboot, and confirm the module is present with piTest -d.
  • Power the peer and match the rate. Enable the second node's CAN interface at the bitrate can0 actually reports, not the number typed into the project — the same check described for reading the SocketCAN bitrate from the active interface.
  • Start in role order. With the RevPi as the CANopen slave, start and run the external master and connect it to the bus before the slave application sends its first frame; the master's presence supplies both the acknowledge and the CANopen boot-up traffic.
  • Verify with counters, not flags. While traffic runs, re-read the link statistics: the CAN state should return to ERROR-ACTIVE, the transmit counter should fall as frames complete, and the RX and TX packet counts should climb. Only those movements prove the path.

Check the bitrate script and where the driver looks #

The runtime hands a script an interface name and a bitrate in kilobits and expects it to convert and apply the rate. The script that worked in this case:

#!/bin/sh
BITRATE=`expr $2 \* 1000`
ifconfig $1 down
echo ip link set $1 type can bitrate $BITRATE
ip link set $1 type can bitrate $BITRATE
ifconfig $1 up

The conversion factor is 1000 because the second argument arrives in kilobits per second. An argument of 250 stands for 250 kbit/s and must come out as 250000 bit/s; a script that multiplies by 250 instead produces 62500 bit/s, a rate no peer was configured for. The interface accepts whatever rate it is given, so the fault surfaces on can0: in this case the link reported 1000000 bit/s after the reboot, a rate the project never asked for. Read the rate from the interface and compare it with the peer before any CANopen testing; bringing the interface down and up for the change interrupts traffic, so do it in a commissioning window. The user-space side of that change is covered in configuring SocketCAN bitrate changes from user space.

Finding the script is the other half: the runtime's SocketCAN driver reads the [CmpSocketCanDrv] section of /etc/CODESYSControl_User.cfg, and its ScriptPath and ScriptName entries must resolve to the real, executable file — here created as /var/opt/codesys/rts_set_baud.sh. Make the two agree before you blame the conversion factor.

Counting the unacknowledged frames that made can0 passive #

Inputs, each with its source:

  • Transmit error counter before the application ran: 0, from the berr-counter tx field of the STOPPED snapshot.
  • Transmit error counter after the reboot: 128, from the berr-counter tx field of the ERROR-PASSIVE snapshot.
  • Increment per failed transmission: 8 per attempt, fixed by ISO 11898-1 error confinement; an empty acknowledge slot counts as a transmit error.
  • Frames completed: none — RX and TX packet counts were both zero, so nothing was ever subtracted back.

The rule in words: every attempt that receives no acknowledge raises the transmit counter by the standard's increment, and nothing comes off until a frame completes, so the counter climbs in equal steps until it reaches the passive threshold.

The arithmetic: (128 − 0) ÷ 8 per attempt = 16 attempts.

Result: sixteen frames left the Con CAN controller and not one was acknowledged.

Decision: a transmit counter parked at the threshold, with the receive side silent and zero packets in both directions, is the missing-acknowledge signature — power a second active node at the matching bitrate before you open a single CANopen object. Only a node that stays passive with a confirmed-active, same-bitrate peer sends you on to wiring, termination and transceiver checks.

The decision for each case #

  • RevPi alone on the bus, either role. Add the second active node; no change inside the CODESYS project matters until a frame completes.
  • RevPi as CANopen slave. Start the external master, connect it, then start the slave application; that order supplies both the acknowledge and the boot-up handling.
  • Peer present and powered, still passive. Compare the rate on can0 with the peer's rate; if the project asked for 250 kbit/s and the interface disagrees, correct the script's factor and the driver's script path, then retest.
  • State back to ERROR-ACTIVE with packet counts climbing. The physical path and the bitrate are proven; whatever remains is CANopen configuration, and that is where to look next.
  • Green circles only with the CAN objects removed. The device tree is fine; restore CAN-Bus and CANopen Manager and run the full-path test.

In every branch the proof is the same: a state that reads ERROR-ACTIVE under traffic and packet counters that move.

Questions asked

Is an error-passive node still allowed to communicate?

Yes. Error-passive is a warning state, not a disconnect: the node keeps transmitting, but after each frame it must observe a suspend-transmission pause of 8 bit times, and it flags errors with passive error flags instead of dominant ones. The state that actually silences a node is bus-off, which the transmit counter reaches at 256.

Why do the TX packet counters stay at zero while the error counter climbs?

The packet statistics count completed frames. A transmission aborted on a missing acknowledge never enters the TX totals, and with no peer on the wire there are no RX frames to count either, so a snapshot can look clean while the bus is dead. The berr-counter fields are the ones that move first.

What happens when the driver's script path and the script location disagree?

The script never runs, so can0 keeps whatever rate it had while the runtime believes it configured something else. In this case the file was created under /var/opt/codesys while the driver configuration example pointed at /opt/codesys/scripts; making the ScriptPath and ScriptName entries name the real, executable file is the fix.

Can I test the physical bus before touching the CODESYS project?

Yes. With the peer powered and transmitting, bring can0 up from the shell with the ip link command at the peer's bitrate, then watch the state field of the link statistics. If it reads ERROR-ACTIVE and stays there while the peer transmits, the wiring, termination and transceivers are proven, and any remaining fault is in the project.

Does the same failure occur on other CAN interfaces under CODESYS?

The mechanism is identical on any CAN controller, because error confinement is part of ISO 11898-1: a lone transmitting node walks to error-passive with or without wiring faults. Only the repair details differ; the bitrate script and the configuration file named here belong to CODESYS Control for Raspberry Pi and its SocketCAN driver.

Keep reading

  • How-to

    How to install and run CODESYS fieldbus add-ons in ctrlX

    Install the fieldbus package from Tools → Add-on Installer, add the Ethernet adapter while online to the ctrlX OS target, then set the generated IO task to priority 30 and the service task to 39 before login. Keep PROFINET off eth0, and protect the engineering interface by configuring a second IP address on the controller.

    Industrial networks

  • Troubleshooting

    Why a CANopen coupler boots up but the PLC rejects it

    A CANopen slave that boots but never gets initialized usually fails the controller's first SDO read: object 1000:0, the device type. Trace power, CAN wiring, bit rate and node ID first, then capture the 1000:0 exchange on the wire; only a mismatch between the returned value and the EDS justifies touching the EDS.

    Industrial networks

  • Troubleshooting

    Why CODESYS EtherCAT master xError stays false on cable pull

    `EtherCAT_Master.xError` stays FALSE because the master does not latch slave loss into the application variables when restart handling is off; the engineering tool reads device state directly, so it still shows the error. Tick `Automatically restart slaves` on the master and `Enable Diagnosis for Devices` for the extended instance, then pull-test: the loss reaches the program and the slave rejoins when the cable returns.

    Industrial networks