Tags :


linux can bus is a fundemental part in embedded linux systems used in industry. Some of the embedded linux boards has the can module on themselve and there is no need for extra can bus adaptor to connect to can devices. Therefore, for using canbus inside the OS it's just needed to enbale the can feature in the kernel.

But sometimes it's very usefull to debug the software running on an embedded linux board in a linux pc and debug or monitor the program more easily. When the program uses the can bus of the board we need to provide the linux can interface to the linux PC and here canusb modules come to play their roles.

CANUSB connectors are very popular in windows world but there are little documentations on how to use them with a linux pc or in the other words canusb linux are not very known.

In linux the CAN protocol is supported by linux SocketCAN library and lots of utilies are there such as can-util to do all the things that can softwares such as can analyser, can monitor, can logger or canbus sniffer can do. 


Two types of device drivers for CAN exist in linux: Character device based drivers and network socket based drivers.

The Linux kernel supports CAN with the SocketCAN framework. this framework uses the model of network devices, which allows multiple applications to access one CAN device simultaneously. But LAWICEL CANUSB is controlled by the ASCII protocol and is based on based on the model of character devices. 

In order to use of these type of CANUSBs like lawicel can bus adaptor, the slcan driver provides a CAN network device for these type of CAN interfaces. The slcan driver converts the ASCII frames to structcan_frame which is used in the Linux CAN subsystem (aka SocketCAN linux). You may have a CAN device supporting the SLCAN protocol on RS232, USB-serial adapters, whatever.

This can bus interface named CANUSB or Lawicel CANUSB has the following properties:

  • Can handle up to 1Mbit/s CAN bitrate
  • Industrial Temp range -40C to +85C
  • USB 2.0 Full Speed, uses FTDI FT245RL usb chip
  • Philips SJA1000 CAN Controller running at 16Mhz
  • Philips 82C251 CAN Tranceiver (ISO 11898-24V)
  • Compliant to CAN 2.0A (11bit ID) & CAN 2.0B (29bit ID)
  • Supports RTR frames
  • 32 CAN frames deep FIFO buffer for incomming frames
  • Time Stamp (optional) in mS for incomming frames
  • CAN connection according to CiA DS102-1 standard
  • Power supplied via USB
  • Free Interface DLL (32 & 64bit) or low level Ascii Commands API
  • Free Windows USB driver available (32 & 64bit)
  • Free Linux USB driver available
  • Free MacOS USB driver available


Prepare linux-can and CAN utils

Load kernel modules

Load the kernel modules we need for CAN. On Ubuntu these modules are already available, so we don't need to compile it.

$ sudo modprobe can 
$ sudo modprobe can-raw 
$ sudo modprobe slcan

Prepare CAN utils

Get and compile the 

$ git clone 
$ cd can-utils
$ make

Plug USB, Attach and startup can interface

$ sudo ./slcan_attach -f -s5 -o /dev/ttyUSB0
attached tty /dev/ttyUSB0 to netdevice slcan0
$ sudo ./slcand ttyUSB0 slcan0
$ sudo ifconfig slcan0 up

The parameter "s5" stands for baudrate 250k.

Now, the linux-can and the CAN utils are ready and can be used with the usb can. Use the command line CAN utils Linux-can and utils prepared? It's time to use it for analysing the can module

Dump can messages from the CAN controller

Display the messages received with the CAN interface.

$ candump slcan0

Send sequences of CAN frames to CAN USB Adaptor

For some tests its very useful to send sequences. First prepare a file with the messages:

$ cat test.log
(0.1) slcan0 5D1#0000
(0.2) slcan0 271#0100
(0.3) slcan0 289#72027000
(0.4) slcan0 401#081100000000

And now play it:

$ canplayer -l 20 -I test.log -v -g500


Other Resources:

  • There is an instruction for installing the CAN driver linux on a linux machine here
  • The ftdi usb driver linux (d2xx driver) can be found here



P. Walter said...
I had the problem that candump showed nothing. The problem was this step: sudo ./slcan_attach -f -s5 -o /dev/ttyUSB0 Changed it to this, and now it works: sudo ./slcand -o -c -s5 -t hw /dev/ttyUSB0
July 1, 2015 11:59
Mahmoud Farshbafdoustar (author) said...
Yes, it seems that slcand combines three utilities in one: old slcand, slcan_attach and stty. So your comment can be used instead of the first 2 lines.
July 21, 2015 10:42


All Categories