CAN on Linux Operation Summary

https://processors.wiki.ti.com/index.php/AM335X_DCAN_Driver_Guide

Bringing CAN interface up - eLinux.org

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 iproute2 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 CommandCAN Bitrate
s010 Kbit/s
s120 Kbit/s
s250 Kbit/s
s3100 Kbit/s
s4125 Kbit/s
s5250 Kbit/s
s6500 Kbit/s
s7800 Kbit/s
s8

1000 Kbit/s

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值