Ramana Reddy
Ramana Reddy

Reputation: 399

How to communicate with can with slcan?

I have a target board where there is a can interface driven by peak drivers. On the host side I installed can-utils. I have a can cable which gets detected as /dev/ttyUSBx when I plugin.

The target board receives candata at 500000 baud rate

So on the host I executed,

sudo modprobe can
sudo modprobe can-raw
sudo modprobe slcan

sudo slcand -o -s8 -t hw -S 500000 /dev/ttyUSBx
sudo ip link set up slcan0

then I sent the candata from the host using:

cansend slcan0 600#ffffffffffffff

I can see the same using candump slcan0 on the host.

But I don't receive anything on the target.

I tried the same with other cable in which I used (on the host)

sudo modprobe can
sudo ip link set can0 type can bitrate 500000 triple-sampling on
sudo ifconfig can0 up

then I was able to send can messages. If I try the same on the previous cable it throws error saying Cannot find device "can0".

So How do I send through slcan interface?

Upvotes: 3

Views: 17502

Answers (2)

foxiris
foxiris

Reputation: 3378

according to eLinux - Bringing CAN I/F up

ASCII Command CAN Bitrate
s0 10 Kbit/s
s1 20 Kbit/s
s2 50 Kbit/s
s3 100 Kbit/s
s4 125 Kbit/s
s5 250 Kbit/s
s6 500 Kbit/s
s7 800 Kbit/s
s8 1000 Kbit/s

Upvotes: 4

yegorich
yegorich

Reputation: 4849

Your CAN bitrate is wrong. To setup 500kbit/s you need to invoke following commands:

sudo slcand -o -s6 -t hw -S 3000000 /dev/ttyUSBx
sudo ip link set up slcan0

-s6 means CAN bitrate 500kbit/s, -s8 means 1Mbit/s. -S parameter is used to setup serial speed to the USB-to-serial controller in the USB-to-CAN cable. The full CAN bitrate table for slcan can be found here.

Upvotes: 4

Related Questions