Difference between revisions of "Bringing CAN interface up"

From eLinux.org
Jump to: navigation, search
m (Introduction)
(SLCAN based Interfaces: add set bitrate commands table)
Line 29: Line 29:
 
   $ sudo ip link set up slcan0
 
   $ sudo ip link set up slcan0
  
So far there is no way to set bitrate for SLCAN based devices via ip tool, so you'll have to do this by slcand invocation: -sX parameter. -s8 in the above example will set adapter's bitrate to 1Mbit/s.
+
So far there is no way to set bitrate for SLCAN based devices via ip tool, so you'll have to do this by slcand invocation: -sX parameter. -s8 in the above example will set adapter's bitrate to 1Mbit/s. See the table below for further CAN bitrates:
 +
 
 +
{| class="wikitable sortable"
 +
|-
 +
!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
 +
|}

Revision as of 01:25, 29 April 2014

Introduction

SocketCAN provides several CAN interface types:

  • virtual interfaces like vcan0
  • native (real hardware) interfaces like can0
  • SLCAN based interfaces like slcan0

Virtual Interfaces

Virtual CAN interfaces will be brought up via ipoute2 ip utility:

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

modprobe is needed in the case the driver is sill not loaded.

Native Interfaces

In most cases you won't need to load the kernel driver for your real hardware. So let us concentrate on ip invocation:

 $ sudo ip link set can0 type can bitrate 125000
 $ sudo ip link set up can0

Aside from bringing interface up it is important to specify bitrate (assumes that CONFIG_CAN_CALC_BITTIMING is enabled in kernel)

SLCAN based Interfaces

SLCAN based device provide a serial interface. At first you'll need a special daemon (slcand from can-utils), that will link this serial interface with a virtual CAN device. By default these devices get slcan name base. This is an example for a USB-to-CAN adapter working at 3Mbit/s:

 $ sudo slcand -o -s8 -t hw -S 3000000 /dev/ttyUSB0
 $ sudo ip link set up slcan0

So far there is no way to set bitrate for SLCAN based devices via ip tool, so you'll have to do this by slcand invocation: -sX parameter. -s8 in the above example will set adapter's bitrate to 1Mbit/s. See the table below for further CAN bitrates:

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