CANopen not working with Codesys [Solved]

Topics about the Software of Revolution Pi
Post Reply
Doctor.No
Posts: 2
Joined: 31 Mar 2021, 09:55

CANopen not working with Codesys [Solved]

Post by Doctor.No »

IMPORTANT: I think, I found a suitable way to do it, I will post my workflow in the following days!


We did everything exactly as described in the tutorial, however CANopen in Codesys won’t run on our RevPi Connect / Con CAN Configuration (and it seems we’re not the only one having this kind of trouble, see here and here ).

We followed the official tutorial as well as the tutorial for the new package from Mr. Amar.

We are using
  • RevPi Connect Plus
  • RevPi Con Can
  • Connect Bridge
  • Codesys Development System V. 3.5 SP16 Patch 4
  • CODESYS Control for Raspberry PI V 4.0.1.0
  • Revolution Pi Bridge V1.0.1.99 Package in Codesys

Our Workflow was the following:
1.) We checked our RevPi Version in PuTTy using “uname -a”

Code: Select all

pi@fftmantonsteuerung:~ $ uname -a
Linux fftmantonsteuerung 4.19.95-rt38-v7 #1 SMP PREEMPT RT Fri, 26 Mar 2021 13:57:12 +0100 armv7l GNU/Linux
The command “sudo apt-get update” yields:

Code: Select all

pi@fftmantonsteuerung:~ $ sudo apt-get update
OK:1 http://archive.raspberrypi.org/debian stretch InRelease
Holen:2 http://raspbian.raspberrypi.org/raspbian stretch InRelease [15,0 kB]
OK:3 http://repository.teamviewer.com/deb stable InRelease
OK:4 http://packages.revolutionpi.de stretch InRelease
OK:5 http://packages.revolutionpi.de stretch-backports InRelease
Es wurden 15,0 kB in 2 s geholt (5.162 B/s).
Paketlisten werden gelesen... Fertig

2.) configured Connect and Con Can module to Right side in Codesys IDE
Configured Connect and Con Can module to Right side in Codesys IDE
Configured Connect and Con Can module to Right side in Codesys IDE
2.jpg (27.91 KiB) Viewed 6603 times
3.) configure the script for setting baud rate:

Code: Select all

sudo nano /var/opt/codesys/rts_set_baud.sh

#!/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

sudo chmod +x /var/opt/codesys/rts_set_baud.sh

4.) Enabled RevPi Con CAN using following command

Code: Select all

pi@fftmantonsteuerung:~ $ sudo revpi-config enable revpi-con-can
* Failed to apply overlay '0_revpi-con-can' (kernel)
1

Important: Unit now, the command “ip -det -statistics link show can0” yields zero errors:

Code: Select all

pi@fftmantonsteuerung:~ $ ip -det -statistics link show can0
5: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0
    can state STOPPED (berr-counter tx 0 rx 0) restart-ms 0
          hi3110: tseg1 2..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
          clock 16000000
          re-started bus-errors arbit-lost error-warn error-pass bus-off
          0          0          0          0          0          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
    RX: bytes  packets  errors  dropped overrun mcast
    0          0        0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    0          0        0       0       0       0
5.) Download the Codesys Program (without starting it)
Download the Codesys Program (without starting it)
Download the Codesys Program (without starting it)
6.jpg (79.37 KiB) Viewed 6603 times
6.) Rebooted Target using the "Tools --> Update Raspberry Pi" Tab in Codesys

Note: until now, the Command “piTest -d” yields

Code: Select all

pi@fftmantonsteuerung:~ $ piTest -d
Found 2 devices:

Address: 0 module type: 105 (0x69) RevPi Connect V1.0
Module is present
     input offset: 0 length: 6
    output offset: 6 length: 5

Address: 32 module type: 109 (0x6d) RevPi CON CAN V0.0
Module is present
     input offset: 0 length: 0
    output offset: 0 length: 0
7.) After I reboot the target, nothing works anymore on the CAN-Bus:
CAN-Bus not working after reboot
CAN-Bus not working after reboot
8.jpg (81.28 KiB) Viewed 6603 times
And the command “ip -det -statistics link show can0” yield an error-passive state for my device.

Code: Select all

pi@fftmantonsteuerung:~ $ ip -det -statistics link show can0
5: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0
    can state ERROR-PASSIVE (berr-counter tx 128 rx 0) restart-ms 0
          bitrate 1000000 sample-point 0.750
          tq 62 prop-seg 5 phase-seg1 6 phase-seg2 4 sjw 1
          hi3110: tseg1 2..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
          clock 16000000
          re-started bus-errors arbit-lost error-warn error-pass bus-off
          0          0          0          1          1          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
    RX: bytes  packets  errors  dropped overrun mcast
    0          0        0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    0          0        0       0       0       0
Having performed all the steps exactly as described in the official tutorials, I have not the slightest idea what to do. Any help is much appreciated!

Note: For some reason, Codesys and Con CAN seem to work, if the "CAN-Bus" and the "CANopen Manager" was NOT inserted in the Codesys Project (All "circles" are green in online mode).
Last edited by Doctor.No on 26 Apr 2021, 10:20, edited 1 time in total.
Doctor.No
Posts: 2
Joined: 31 Mar 2021, 09:55

Re: CANopen not working with Codesys

Post by Doctor.No »

There are some important step one has to consider, otherwise the above-mentioned workflow won't run the RevPI / Con CAN configuration!

Check if you've performed the following steps:

1.) Make sure, that your device (Con CAN) is not the only active device on the network! Otherwise, you'll receive an "error passive" status! If you're using the CON CAN as a Slave Device, start the CANopen Master Device first and connect both devices to the CAN network!

2.) Pay attention at the baudrate! If you want a baudrate of 250000 , your the code in your script has to be

Code: Select all

BITRATE=`expr $2 \\* 1000`
and NOT

Code: Select all

BITRATE=`expr $2 \\* 250`
(For the full code, see post above)

Having performed these steps, the CANopen Slave (RevPI / Con CAN) configuration was working in codesys!
Thanks again @RevPi Team for your help!
asekar18
Posts: 2
Joined: 27 Aug 2021, 05:34

Re: CANopen not working with Codesys [Solved]

Post by asekar18 »

Hi guys

Did you add these lines in /etc/CODESYSControl_User.cfg?

[CmpSocketCanDrv]
ScriptPath=/opt/codesys/scripts/
ScriptName=rts_set_baud.sh
Post Reply