zz-嵌入式linux的can0配置141215a

//zz//####################################################################################

zz-嵌入式linux的can0配置141215a

zz-write:
@2014-12-16 00:46:33
@2014-12-16 23:18:38
@

REF:
linux can 总线socket接口测试使用 
http://blog.chinaunix.net/uid-26119896-id-3452315.html

How to configure and use CAN bus
http://blog.csdn.net/flymachine/article/details/7251061

/etc/network/interfaces 文件的内容

KeyWord:

ip link set can0 type can bitrate 500000
ip link set can0 up type can
ip -details link show can0

//zz//####################################################################################
1.
使用 ip 命令来查看与设置

1)
设置 can0 波特率为 125Kbps
# ip link set can0 type can tq 125 prop-seg 6  phase-seg1 7 phase-seg2 2 sjw 1

或者
# ip link set can0 type can bitrate 125000
或者
# ip link set can0 type can bitrate 500000 triple-sampling on
# ip link set can0 type can bitrate 500000 triple-sampling on loopback on

2)
查看 can0 的配置,波特率为 500Kbps,所用的系统时钟为 16MHz
# ip -details link show can0
 can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
    link/can 
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 
    bitrate 500000 sample-point 0.875 
    tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
    sja1000: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
    clock 16000000

3)
查看 can0 的比特率配置等,以及统计数据(接收/发送/出错帧等)
# ip -details -statistics link show can0 


//zz//####################################################################################
2.
使用 ifconfig,ip 命令来开启,关闭

# ifconfig can0 down

# ifconfig can0 up
或者
# ip link set can0 up type can

//zz//####################################################################################
3.
配置,调试工具软件:
canconfig 这类的工具也可以完成配置,开关功能

接收
# ./candump can0

发送
# cansend can0 -e 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88

//zz//####################################################################################
4.
/etc/network/interface
开机自动配置

auto can0
iface can0 inet manual
#pre-up ip link set $IFACE type can bitrate 125000 listen-only off
pre-up /ip link set $IFACE type can bitrate 125000 triple-sampling on
up /sbin/ifconfig $IFACE up

down /sbin/ifconfig $IFACE down


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值