🛠 Bus CAN : exploiter les deux contrôleurs DCAN avec can-utils
Objectives
The AM335x embeds TWO CAN controllers (DCAN) — a massive industrial argument compared to consumer-grade boards. You will expose CAN0 on pins P8_17/P8_18 (the MCASP0 pins muxed to DCAN by the community overlay KCP-0001), configure the interface with ip link, and exchange frames using can-utils between two nodes.
Hardware
- 2 BeagleBone Black boards (or 1 BBB + 1 second CAN node)
- 2 CAN 3.3 V transceivers (SN65HVD230 / TJA1050 class in 3.3 V version) on pins P8_17/P8_18
- 2 termination resistors of 120 Ω (one at each end of the bus)
- Wiring: CAN_H to CAN_H, CAN_L to CAN_L, common ground between the boards
Complete code
sudo apt install can-utils device-tree-compiler
# Exposer CAN0 sur P8_17/P8_18 :
# - ancienne image : overlay KCP-0001 via le capemanager
echo cape_can | sudo tee /sys/devices/platform/bone_capemanager/slots
# - image récente : l'overlay est embarqué (KCP-0001) ou chargé via configfs
ls /sys/class/net/ # can0 doit apparaître
# Configurer l'interface (impérativement interface DOWN pour changer le débit)
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 500000
sudo ip link set can0 up
ip -details link show can0
# Émettre / écouter
candump can0 &
cansend can0 123#DEADBEEF
# Test seul sur une carte : activer le loopback interne
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 500000 loopback true
sudo ip link set can0 up
cansend can0 321#CAFEBABE && candump -n 1 can0
Expected verification
In loopback mode, candump receives the frame 321#CAFEBABE sent by cansend. On a two-board bus, cansend on one board makes the frame appear in candump on the other; ip -details shows the active bitrate of 500000 and the interface in UP state.
Common errors
- Forgetting the 120 Ω termination resistors at both ends: corrupted frames, CRC errors, interface going bus-off.
- Different bitrates between the two nodes: no frames pass without an explicit error message — always check both sides.
- Changing the bitrate while the interface is active: ip link set type can bitrate requires the interface to be DOWN first.
- Connecting CAN_H/CAN_L directly to 3.3 V pins: a differential transceiver is required; the pins alone do not make a CAN bus.
- Forgetting the common ground between the two boards: the differential signal does not "float" as well as one might think.
- The CAN overlay is absent by default in modern images: check for the presence of can0 before wiring (dmesg | grep -i can).
Other tutorials for this board
- Premier boot de la BeagleBone Black avec un seul câble mini-USB
- Comprendre les triggers en pilotant les 4 LED utilisateur
- Bouton et LED avec Adafruit_BBIO, la bibliothèque historique
- Lire l'ADC 12 bits sans griller le SoC : la règle des 1,8 V
- Ajouter une horloge temps réel sur le bus I2C des capes
- Micro-HDMI : exploiter les limites d'affichage de la BBB
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash