Page tree
Skip to end of metadata
Go to start of metadata

CAN,全称为“Controller Area Network”,即控制器局域网,是国际上应用最广泛的现场总线之一。最初,CAN被设计作为汽车环境中的微控制器通讯,在车载各电子控制装置ECU之间交换信息,形成汽车电子控制网络。比如:发动机管理系统、变速箱控制器、仪表装备、电子主干系统中,均嵌入CAN控制装置。


PanGu开发板的J25扩展座中已支持CAN信号。

CAN信号PanGu开发板STM32MP1 Pinout
CAN1_TXJ25.25PH13
CAN1_RXJ25.27PI9

这里需要连接CAN收发器模块后才可以使用。

在dts中配置CAN控制器的Pinmux后,更新至PanGu开发板,即可以看到一个can0设备。

i2somtech@PanGuBoard:~$ sudo ifconfig -a
can0: flags=128<NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 34

eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.2.190  netmask 255.255.255.0  broadcast 192.168.2.255
        ether 16:e1:f0:d2:1a:81  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 60  base 0xc000

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 204  bytes 19380 (18.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 204  bytes 19380 (18.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


配置CAN设备波特率为50Kbps,并发送数据

# ip link set can0 up type can bitrate 50000
# ifconfig can0 up
# cansend can0 100#01.02.03.04.05.06.07.08

在另外的PanGu开发板或CAN设备上执行

# ip link set can0 up type can bitrate 50000
# ifconfig can0 up
# candump can0
  • No labels