Linux-下Can的配置

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Linux下Can的配置2015-12-0713:57747人阅读评论(0)收藏举报分类:linux(55)CAN总线配置在Linux系统中,CAN总线接口设备作为网络设备被系统进行统一管理。在控制台下,CAN总线的配置和以太网的配置使用相同的命令。在控制台上输入命令:1.ifconfig–a可以得到以下结果:1.can0Linkencap:UNSPECHWaddr00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-002.NOARPMTU:16Metric:13.RXpackets:0errors:0dropped:0overruns:0frame:04.TXpackets:0errors:0dropped:0overruns:0carrier:05.collisions:0txqueuelen:106.RXbytes:0(0.0B)TXbytes:0(0.0B)7.Interrupt:188.eth0Linkencap:EthernetHWaddr00:50:c2:22:3b:0e9.UPBROADCASTMULTICASTMTU:1500Metric:110.RXpackets:0errors:0dropped:0overruns:0frame:011.TXpackets:0errors:0dropped:0overruns:0carrier:012.collisions:0txqueuelen:100013.RXbytes:0(0.0B)TXbytes:0(0.0B)14.eth1Linkencap:EthernetHWaddr00:50:c2:22:3b:6015.UPBROADCASTMULTICASTMTU:1500Metric:116.RXpackets:0errors:0dropped:0overruns:0frame:017.TXpackets:0errors:0dropped:0overruns:0carrier:018.collisions:0txqueuelen:100019.RXbytes:0(0.0B)TXbytes:0(0.0B)20.Interrupt:41Baseaddress:0xe00021.loLinkencap:LocalLoopback22.inetaddr:127.0.0.1Mask:255.0.0.023.inet6addr:::1/128Scope:Host24.UPLOOPBACKRUNNINGMTU:16436Metric:125.RXpackets:256errors:0dropped:0overruns:0frame:026.TXpackets:256errors:0dropped:0overruns:0carrier:027.collisions:0txqueuelen:028.RXbytes:19952(19.9KB)TXbytes:19952(19.9KB)在上面的结果中,eth0和eth1设备为以太网接口,can0设备为CAN总线接口。接下来使用ip命令来配置CAN总线的位速率:1.iplinksetcan0typecantq125prop-seg6phase-seg17phase-seg22sjw1也可以使用ip命令直接设定位速率:1.iplinksetcan0typecanbitrate125000当设置完成后,可以通过下面的命令查询can0设备的参数设置:1.ip-detailslinkshowcan0当设置完成后,可以使用下面的命令使能can0设备:1.ifconfigcan0up使用下面的命令取消can0设备使能:1.ifconfigcan0down###########################################1、首先配置can0iplinksetcan0typecantq125prop-seg6phase-seg17phase-seg22sjw1这时dmesg可以看到sja1000_fpga_pci0000:07:04.0:settingBTR0=0x01BTR1=0x1c2、ip-detailslinkshowcan0查看一下can0:mtu16qdiscpfifo_faststateUNKNOWNqlen10link/cancanstateERROR-ACTIVE(berr-countertx0rx0)restart-ms0bitrate500000sample-point0.875tq125prop-seg6phase-seg17phase-seg22sjw1sja1000:tseg11..16tseg21..8sjw1..4brp1..64brp-inc1clock160000003、接收测试,接收测试软件发送的帧:#./candumpcan0interface=can0,family=29,type=3,proto=10x00000002[8]70010203040506070x00000002[8]70010203040506070x00000002[8]70010203040506070x00000002[8]70010203040506070x00000002[8]70010203040506070x00000002[8]70010203040506070x00000002[8]70010203040506070x00000002[8]70010203040506070x00000002[8]70010203040506074、发送测试./cansendcan0-e0x110x220x330x440x550x660x770x88interface=can0,family=29,type=3,proto=1测试软件上能看到接收的帧5、重启使用内核文档说的iplinksetcan0typecanrestart-ms100会报RTNETLINKanswers:Deviceorresourcebusy使用ifconfigcan0down;iplinksetcan0uptypecan即可并没有掌握sja1000波特率的配置。摸索出4种常见波特率:250kbps:iplinksetcan0typecantq125prop-seg6phase-seg17phase-seg22sjw1125kbps:iplinksetcan0typecantq250prop-seg6phase-seg17phase-seg22sjw1500kbps:iplinksetcan0typecantq75prop-seg6phase-seg17phase-seg22sjw11000kbps:iplinksetcan0uptypecanbitrate2000000常见用法:ip-detailslinkshowcan0ifconfigcan0down;iplinksetcan0uptypecan./candumpcan0./cansendcan0-e0x110x220x330x440x550x660x770x88^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^62.使用loopback模式测试:使用loopback模式可测试本机的can驱动是否正常工作.#iplinksetcan0down#iplinksetcan0typecanbitrate50000loopbackonxilinx_cane0008000.cancan0:bitrateerror0.0%#iplinksetcan0up#candumpcan0&#cansendcan0123#11223344556677

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功