Skip to main content

8. CAN

8. 1 Introduction​

CAN, short for Controller Area Network, is a serial communication protocol widely used for real-time data communication. Originally developed by the German company Bosch, the CAN protocol was designed for communication between electronic control units (ECUs) in the automotive field. Due to its efficient and reliable characteristics, the CAN protocol has been widely adopted in other fields such as industrial automation, medical devices, marine, aerospace, and more.

8.2 Enabling CAN​

The CAN interface function is not enabled by default on the development board. To use the CAN interface, an external expansion board needs to be connected. This example uses Waveshare's CM4-IO-WIRELESS-BASE-B and USB-CAN-A for testing. Please note that other models of expansion boards may have incompatible drivers due to different chips, and further research is required.

  1. 修改 /boot/config.txt 文件:

    sudo vim /boot/config.txt
    dtparam=mcp2515 can0=off 改为 dtparam=mcp2515 can0=on

8.3 Modify the /boot/config.txt file:​

  1. Activate the can0 interface and set the bitrate to 500 kbps:

    sudo ip link set can0 up type can bitrate 500000
  2. Disable the CAN interface:

    sudo ip link set can0 down
  3. View the CAN interface status:

    ifconfig can0
  4. Receive CAN messages:

    candump can0

8.4 Testing​

  1. Open a serial port assistant on the Windows computer to send data.

For more detailed testing, refer to: https://www.waveshare.com/wiki/USB-CAN-A