|
本帖最后由 alittle 于 2024-7-25 09:44 编辑
1、CAN控制器有两种通信标准支持不同的最高速度
ISO 11519-2(Low speed)最高速度125kbps
ISO 11898(High speed)最高速度1Mbps(常用)
2、Linux系统下CAN接口配置
- ifconfig -a //查看是否存在can设备
- ifconfig can0 down //配置can通道前先关闭通道
- ip link set can0 type can bitrate 400000 //配置400kbps通信速率
- ip link set can0 up //或 ifconfig can0 up打开通道
- ip -details link show can0 //查看配置完成的can节点信息
- //安装can-utils
- sudo apt install can-utils
- //或者下载源码进行手动编译,源码的编译依赖libsocketcan库
- //https://public.pengutronix.de/software/socket-can/canutils/
- //短接板内can0和can1进行测试,H-H,L-L短接,如果在PC端用CAN测试盒测试,可以使用ZCANPRO软件
- ./candump can0 & //接收can0通道数据并设为后台运行
- ./cansend can1 123#1122334455667788 //控制can1通道发送ID为0x123,数据为0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88的数据包
复制代码
3、常见异常及调试建议
3.1、ifconfig -a找不到can接口
--建议找BIOS工程师确认是否打开了can接口设备节点
3.2、如果can口无法打开,提示bit-timing相关报错
--先检查是否配置can口通信速率,ip link set can0 type can bitrate 400000
--如果配置了还有该报错,可能是驱动有点区别,改用以下命令配置速率
ip link set can0 type can bitrate 400000 fd off
3.3、配置正常,但是无法通信
--找BIOS工程师确认can接口管脚复用情况
--确认通信两端的波特率是否设置一致,可能存在软件设置一致,但是实际硬件测量的波特率与设置值不一致的情况,所以软件设置和硬件测量都需要确认
--检查can总线是否有上终端匹配电阻
|
|