CAN总线调试

【CAN总线调试】会挽雕弓如满月,西北望,射天狼。这篇文章主要讲述CAN总线调试相关的知识,希望能为你提供帮助。
CAN总线
CAN是控制器局域网络(Controller Area Network, CAN)的简称,是由以研发和生产汽车电子产品著称的德国BOSCH公司开发的,并最终成为国际标准(ISO 11898),是国际上应用最广泛的现场总线之一。 在北美和西欧,CAN总线协议已经成为汽车计算机控制系统和嵌入式工业控制局域网的标准总线,并且拥有以CAN为底层协议专为大型货车和重工机械车辆设计的J1939协议。
配置can

user@server:~$ cat /etc/can_setup.sh #!/bin/shmodprobe can modprobe can_raw modprobe mttcanip link set can0 up type can bitrate 500000 restart-ms 5000 ip link set can1 up type can bitrate 500000 restart-ms 5000

验证can
user@server:~$ ip -details -statistics link show can0 8: can0: < NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10 link/canpromiscuity 0 can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 5000 bitrate 498701 sample-point 0.870 tq 26 prop-seg 33 phase-seg1 33 phase-seg2 10 sjw 1 mttcan: tseg1 2..255 tseg2 0..127 sjw 1..127 brp 1..511 brp-inc 1 mttcan: dtseg1 1..31 dtseg2 0..15 dsjw 1..15 dbrp 1..15 dbrp-inc 1 clock 38400000 re-started bus-errors arbit-lost error-warn error-pass bus-off 000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 RX: bytespacketserrorsdropped overrun mcast 29844083730510000 TX: bytespacketserrorsdropped carrier collsns 210824268700000

检查dmesg消息
user@server:~$ dmesg |grep can [0.000000] OF: fdt:memory scan node memory, reg size 48, [1.521230] tegra-pwm 3280000.pwm: PWM clk can sleep in ops [1.521649] tegra-pwm c340000.pwm: PWM clk can sleep in ops [1.522360] tegra-pwm 32c0000.pwm: PWM clk can sleep in ops [1.522751] tegra-pwm 32f0000.pwm: PWM clk can sleep in ops [6.330840] FAN: can\'t find tach_gpio [21.855925] can: controller area network core (rev 20120528 abi 9) [21.868303] can: raw protocol (rev 20120528) [21.912229] net can0: mttcan device registered (regs=ffffff800d141000, irq=69) [21.926728] net can1: mttcan device registered (regs=ffffff800d147000, irq=70) [21.934051] mttcan c310000.mttcan can0: bitrate error 0.2% [21.934179] mttcan c310000.mttcan can0: Bitrate set [21.934238] mttcan_controller_config: ctrlmode 0 [21.934252] mttcan c310000.mttcan can0: Bitrate set [21.934310] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready [21.949344] mttcan c320000.mttcan can1: bitrate error 0.2% [21.949478] mttcan c320000.mttcan can1: Bitrate set [21.949546] mttcan_controller_config: ctrlmode 0 [21.949563] mttcan c320000.mttcan can1: Bitrate set [21.949621] IPv6: ADDRCONF(NETDEV_CHANGE): can1: link becomes ready

检查candump输出
user@server:~$ candump can0 |head can0607[8]61 00 00 00 0F A0 06 C8 can0601[8]00 3C 00 02 01 01 44 0B can0602[8]00 00 00 00 00 00 00 00 can0605[8]1F C8 4D 40 00 2C F6 00 can0606[8]80 01 37 E0 00 39 00 00 can0602[8]00 00 00 00 00 00 00 00 can0601[8]00 3C 00 02 01 01 44 0C can0605[8]1F BA 4C F0 00 30 29 00 can0606[8]80 01 37 E0 00 39 00 00 can0607[8]61 00 00 00 0F A0 07 C9


    推荐阅读