usb pcan fd raspberry pi

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
kubasmyk
Posts: 5
Joined: Sat 17. Jul 2021, 11:02

usb pcan fd raspberry pi

Post by kubasmyk » Sat 17. Jul 2021, 15:02

Greetings i have issue with setting it up properly
I have followed this thread
viewtopic.php?f=59&t=3381

this is the output

Code: Select all

pi@raspberrypi:~ cat /proc/pcan

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20210505_n (8.12.0) Jul 15 2021 12:47:20 --------------
*---------------------------- [mod] [usb] [net] -----------------------------
*--------------------- 1 interfaces @ major 235 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32  usbfd   can0        0 000 0x001c 0000016a 00000000 000000b5 00000000 0x0000
when i try using commands such as

Code: Select all

sudo ip link set can0 up type can bitrate 500000 sample-point 0.875
the adapter starts blinking red

with trial and error i managed to get it work with this

Code: Select all

sudo ip link set can0 up type can tq 125 prop-seg 6  phase-seg1 7 phase-seg2 2 sjw 1
any idea what I'm doing wrong?

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: usb pcan fd raspberry pi

Post by M.Heidemann » Mon 19. Jul 2021, 08:11

Hello,

Can you elaborate on your issue?

What exactly does not work?

Have you actually tested, if the PCAN-USB FD receives/sends messages as intended?

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

kubasmyk
Posts: 5
Joined: Sat 17. Jul 2021, 11:02

Re: usb pcan fd raspberry pi

Post by kubasmyk » Mon 19. Jul 2021, 09:17

Greetings, thank you for response

Code: Select all

sudo ip link set can0 up type can bitrate 500000 sample-point 0.875
This command does't work

The other command works but is very cumbersome to use.
Looks like the up link set has problems setting the adapter registers on its own without manually being told exactly every single register.

Is there a way to make it work less cumbersome?

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: usb pcan fd raspberry pi

Post by M.Heidemann » Mon 19. Jul 2021, 09:40

Hello,

Can you please elaborate how exactly the command:

Code: Select all

sudo ip link set can0 up type can bitrate 500000 sample-point 0.875
does not work?

Do you get any error message?

Do you not see the expected traffic ,for example using candump?
If you use candump, do you have error-frames active (-e paramter)?

Code: Select all

candump can0 -e

How did you test working conditions?

Please report back to us regarding this.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

kubasmyk
Posts: 5
Joined: Sat 17. Jul 2021, 11:02

Re: usb pcan fd raspberry pi

Post by kubasmyk » Mon 19. Jul 2021, 14:29

Hi, thanks for quick responses.

Im in my test set up i have a F28069m Launchpad microprocessor connected to a PCAN FD USB adapter that sends a periodic keep alive signal on the can bus.

I can see the messages fine apearing in windows 10 through a Pcan-View software. Im running 500kbits no problem and no issues.

I required to write some test code for software acknowledge im working on for the microprocessor so through its easy to write it in linux. So i tried installing the driver for my raspberry pi so can get things working.

I used a mcp2515 module in the past with raspberry pi. It was very straight forward to set up, but i dont have that anymore. It was just a case of typing a bitrate and everything was working " right outside the box".

I have tried the basic command with bitrate. I saw some other people in the forum recomended setting the sample point after bitrate so i though it was going to be straight forward. Sadly it didnt work for me. So i tried manually setting the registers so it started to work. But that is low level stuff and its bit complicated for me to use as I dont exactly know how it all works together inside.
This is not working

Code: Select all

pi@raspberrypi:~ $ sudo ip link set can0 up type can bitrate 500000 sample-point 0.875
pi@raspberrypi:~ $ ip -s -d link show can0
45: can0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
          bitrate 500000 sample-point 0.875
          tq 12 prop-seg 69 phase-seg1 70 phase-seg2 20 sjw 1
          pcan: tseg1 1..256 tseg2 1..128 sjw 1..128 brp 1..1024 brp-inc 1
          dbitrate 2000000 dsample-point 0.750
          dtq 12 dprop-seg 14 dphase-seg1 15 dphase-seg2 10 dsjw 1
          pcan: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..1024 dbrp-inc 1
          clock 80000000
          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
this is working

Code: Select all

pi@raspberrypi:~ $ sudo ip link set can0 up type can tq 125 prop-seg 6  phase-seg1 7 phase-seg2 2 sjw 1
pi@raspberrypi:~ $ ip -s -d link show can0
45: can0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
          bitrate 500000 sample-point 0.875
          tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
          pcan: tseg1 1..256 tseg2 1..128 sjw 1..128 brp 1..1024 brp-inc 1
          dbitrate 2000000 dsample-point 0.750
          dtq 12 dprop-seg 14 dphase-seg1 15 dphase-seg2 10 dsjw 1
          pcan: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..1024 dbrp-inc 1
          clock 80000000
          re-started bus-errors arbit-lost error-warn error-pass bus-off
          0          32         0          0          0          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
    RX: bytes  packets  errors  dropped overrun mcast
    256        32       32      0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    0          0        0       0       0       0
I have confirmed this is working with the use of

Code: Select all

candump can0 -td

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: usb pcan fd raspberry pi

Post by M.Heidemann » Mon 19. Jul 2021, 16:04

Hello,

The command itself works as intended, however apparently
the bit-timing used for 500kbit/s .875 does not seem to match whats on the bus.

You could also try .75 and .80 sample-points, as they are quite common.

We do not know what you other Node on the bus uses exactly, please check the docs
or its configuration.

You should also check, if:

Code: Select all

candump -e 
provides usable information on what exactly does not work


Please report back to us.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

kubasmyk
Posts: 5
Joined: Sat 17. Jul 2021, 11:02

Re: usb pcan fd raspberry pi

Post by kubasmyk » Mon 19. Jul 2021, 16:51

0.75 sample works for a bout 3 seconds then halts, it is red even message comes through.

Code: Select all

pi@raspberrypi:~ $ sudo ip link set can0 up type can bitrate 500000 sample-point 0.75
 candump can0 -td
 (000.000000)  can0  005   [1]  01
 (000.993284)  can0  005   [1]  01
 (000.993247)  can0  005   [1]  01
^Cpi@raspberrypi:~ ip -s -d link show can0
46: can0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0
    can state ERROR-PASSIVE (berr-counter tx 0 rx 136) restart-ms 0
          bitrate 500000 sample-point 0.750
          tq 12 prop-seg 59 phase-seg1 60 phase-seg2 40 sjw 1
          pcan: tseg1 1..256 tseg2 1..128 sjw 1..128 brp 1..1024 brp-inc 1
          dbitrate 2000000 dsample-point 0.750
          dtq 12 dprop-seg 14 dphase-seg1 15 dphase-seg2 10 dsjw 1
          pcan: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..1024 dbrp-inc 1
          clock 80000000
          re-started bus-errors arbit-lost error-warn error-pass bus-off
          0          107432911  0          4          4          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
    RX: bytes  packets  errors  dropped overrun mcast
    859463943  107433062 107432915 26      4       0
    TX: bytes  packets  errors  dropped carrier collsns
    0          0        0       0       0       0

0.8 sample doesnt work at all

Code: Select all

pi@raspberrypi:~ $ sudo ip link set can0 down
pi@raspberrypi:~ $ sudo ip link set can0 up type can bitrate 500000 sample-point 0.8
pi@raspberrypi:~ $ candump can0 -td
^Cpi@raspberrypi:~ ip -s -d link show can0
46: can0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0
    can state ERROR-PASSIVE (berr-counter tx 0 rx 136) restart-ms 0
          bitrate 500000 sample-point 0.800
          tq 12 prop-seg 63 phase-seg1 64 phase-seg2 32 sjw 1
          pcan: tseg1 1..256 tseg2 1..128 sjw 1..128 brp 1..1024 brp-inc 1
          dbitrate 2000000 dsample-point 0.750
          dtq 12 dprop-seg 14 dphase-seg1 15 dphase-seg2 10 dsjw 1
          pcan: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..1024 dbrp-inc 1
          clock 80000000
          re-started bus-errors arbit-lost error-warn error-pass bus-off
          0          108003223  0          5          5          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
    RX: bytes  packets  errors  dropped overrun mcast
    864026455  108003376 108003227 30      4       0
    TX: bytes  packets  errors  dropped carrier collsns
    0          0        0       0       0       0
pi@raspberrypi:~ $

candump can0 -e doesnt show error frames for the sample 0.75

Code: Select all

pi@raspberrypi:~ $ candump can0 -e
  can0  005   [1]  01
  can0  005   [1]  01
  can0  005   [1]  01
for 0.8 sample it doesn't show anything

kubasmyk
Posts: 5
Joined: Sat 17. Jul 2021, 11:02

Re: usb pcan fd raspberry pi

Post by kubasmyk » Mon 19. Jul 2021, 21:30

In my microcontroller I have settings:
Can module cock frequency SYSCLOCKOUT/2 =45Mhz
BRP=5
TSEG1 =14
TSEG2 =3
SJW =2
SBG= Only_falling_edges
SAM=Sample_one_time
Enhanced CAN mode enabled


I have used the calculator to workout the sample time
http://www.bittiming.can-wiki.info/#TMS320
I plugged my clock speed 45Mhz into it
I plugged the target sample time 81%
I plugged SJW 2

The result matched my bitrate of:
500k
BRP
TSEG1
TSEG1
It calculated the sample time to be = 83.3
It also said Number of time quanta = 18

this doesn't work

Code: Select all

pi@raspberrypi:~ $ sudo ip link set can0 up type can bitrate 500000 sample-point 0.833
pi@raspberrypi:~ $ candump can0
It works with PcanView on windows 10. This makes me believe its not fault of other node.

Hopefully it is the information you requested

I noticed it works when use this to set it. maybe "red herring"

Code: Select all

sudo ip link set can0 up type can bitrate 500000 sample-point 0.876
pi@raspberrypi:~ $ ip -s -d link show can0
47: can0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
          bitrate 500000 sample-point 0.875
          tq 250 prop-seg 3 phase-seg1 3 phase-seg2 1 sjw 1
          pcan: tseg1 1..256 tseg2 1..128 sjw 1..128 brp 1..1024 brp-inc 1
          dbitrate 2000000 dsample-point 0.750
          dtq 12 dprop-seg 14 dphase-seg1 15 dphase-seg2 10 dsjw 1
          pcan: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..1024 dbrp-inc 1
          clock 80000000
          re-started bus-errors arbit-lost error-warn error-pass bus-off
          0          246939     0          1          1          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
    RX: bytes  packets  errors  dropped overrun mcast
    1986245    249503   246941  11      2       0
    TX: bytes  packets  errors  dropped carrier collsns
    0          0        0       0       0       0


M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: usb pcan fd raspberry pi

Post by M.Heidemann » Tue 20. Jul 2021, 10:12

Hello,

The error counts suggests there are still issues with this config.

have you tried to configure microcontroller for 80% Sample-Point and use
80 % SP on the PCAN side?

As you mentioned the TMS320 series is used here, you could, according to the calculator use the following settings for your microcontroller:

500Kbit/s at 45MHZ -> SP 80%

BRP: 6
TQ: 15
Tseg1: 7
Tseg2: 2
SJW: 2

Does this work as intended?

Also, have you checked termination?

The mcp2515 seems to have internal 120Ohm termination, which if the missing termination is not accounted for also could lead to errors on the bus.

Please report back to us regarding this.

Best Regards

marvin
---
Marvin Heidemann
PEAK-Support Team

Post Reply