9 destinations

← CAN bus guides

Set Up a USB CAN Adapter on Linux with SocketCAN

Configure can0, set bitrate, capture frames with candump, test with vcan and troubleshoot bus-off on a controlled Classical CAN bench.

Configure a USB CAN adapter as a Linux network interface, set the correct Classical CAN bitrate, capture frames with candump, and separate software problems from wiring problems.

Before connecting a USB CAN adapter

Write down the bus voltage domain, nominal bitrate, connector pinout, ground reference and termination plan. Do not infer a connector pinout from its shape. OBD-II, DB9, JST and pluggable terminals can carry different signals in different products.

For a first capture, use a powered bench with a known-good node and a current wiring diagram. Keep the adapter in listen-only mode if its driver supports that mode and you do not need to transmit. Isolation can reduce one class of ground-current problem, but it does not protect against a wrong pinout, over-voltage or unsafe commands.

1. Confirm the interface and configure can0

SocketCAN exposes CAN controllers as Linux network devices. After connecting the adapter, look for the interface:

ip -details link show

If the driver created can0, bring it down before changing bit timing. Then start it with the bitrate used by the bench. This example uses 500 kbit/s:

sudo ip link set can0 down
sudo ip link set can0 up type can bitrate 500000 restart-ms 100
ip -details -statistics link show can0

The bitrate is not discovered automatically by these commands. A mismatched bitrate can produce error frames, error-passive state or bus-off. The Linux kernel documentation also exposes controller-specific timing, listen-only, loopback and termination settings when the driver implements them.

If the adapter supports switchable termination through SocketCAN, query its reported options before changing anything:

ip -details link show can0
sudo ip link set dev can0 type can termination 120

Only enable that resistor when the adapter is intended to be one physical end of the trunk. Do not add a third terminator to an already terminated bus.

2. Capture frames with candump

The can-utils project provides candump, cansend, canplayer and other SocketCAN utilities. Start with a passive display:

candump can0

To create a timestamped log suitable for later replay or DBC decoding:

candump -L can0 | tee can0-capture.log

Record the exact bench state beside the log: adapter, firmware, operating system, bitrate, wiring, termination and which nodes were powered. A trace without that context is difficult to reproduce.

Do not transmit onto an unknown bus just to prove the adapter works. If transmission is part of a controlled bench test, use an assigned test identifier and a payload agreed by the bench owner.

3. Test the toolchain without CAN hardware

Linux provides a virtual CAN driver. It is useful for checking scripts, filters and log formatting before a physical adapter is involved:

sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set vcan0 up
candump vcan0

In a second terminal, send one test frame to the virtual interface:

cansend vcan0 123#DEADBEEF

This proves only the local SocketCAN toolchain. It does not validate a USB driver, transceiver, isolation barrier, cable or physical bus.

Troubleshooting by symptom

No can0 interface

  • Check dmesg for driver binding and USB enumeration errors.
  • Confirm the adapter is supported by the running kernel or by the vendor driver you intentionally installed.
  • Check whether the interface has a different name.

can0 is up, but no frames appear

  • Confirm at least one node is transmitting.
  • Re-check bitrate, CANH/CANL polarity, common reference requirements and connector pinout.
  • Confirm two—not zero, one or three—appropriate end terminations on the trunk.
  • Inspect filters before assuming the bus is silent.

The interface enters bus-off

Stop transmission and inspect the physical layer. Repeatedly restarting a controller does not fix a wrong bitrate, missing acknowledgement, wiring fault or termination error. Save the error counters and exact setup before changing more than one variable.

Next bench step

Once the capture is stable, map raw identifiers to named signals with the local DBC decoding guide. If you are evaluating isolated hardware, review the CAN Isolated pilot boundary before applying.

Primary references