Adding CAN to the BeagleBone (Black)

The CAN bus (Controller Area Network) was originally designed by Bosch for the automotive market to connect ECUs (Engine/Electronic Control Units) together.

Today, this robust communications bus is commonly found, not only in vehicles, but also on the factory floor in automation (e.g. CANOpen) and other applications such as PV solar inverter/battery Energy Storage Systems (ESS).

The Sitara AM335x MCU found on the BeagleBone includes two CAN 2.0 controllers (DCAN) using IP modules from Bosch.

The BeagleBone Black PCB, however, doesn’t include any CAN bus transceivers and these must be added externally.

CAN Transceiver Wiring

The BeagleBone Black has two DCAN ports:

  • DCAN0 is multiplexed on the I2C2_SCL and I2C2_SDA pins and is generally reserved for the Cape Identification EEPROM.
  • DCAN1 is multiplexed with UART1 and is considered the better choice if only one CAN bus is needed.

I/O pins on the Beagle Bone Black are 3.3V logic levels and not tolerant to 5V. Hence 5V transceivers should not be used without the appropriate level shifters/voltage dividers.

SN65HVD230 CAN Bus Transceiver Breakout

If you don’t want to manufacture a cape, SN65HVD230 breakout boards such as the one above are prevalent on Amazon, Aliexpress, ebay etc. Being 3.3V are ideal for use with the BeagleBone.

SN65HVD230 Can Bus Transceiver Breakout wired to a BeagleBone Black

The module’s CTX line should be connected to DCANx_TX. Likewise, CRX should be connected to DCANx_RX.

Driver Installation

The installation of CAN drivers on the BB is a breeze. The BeagleBone Debian distribution (I’m using Debian 9.9 2019-08-03) comes complete with CAN drivers already installed.

debian@beaglebone:~$ dmesg | grep -i can
[    1.045136] CAN device driver interface
[    1.046571] c_can_platform 481cc000.can: c_can_platform device registered (regs=fa1cc000, irq=42) 
[    1.047539] c_can_platform 481d0000.can: c_can_platform device registered (regs=fa1d0000, irq=43)
[    1.275146] can: controller area network core (rev 20170425 abi 9)
[  856.286265] c_can_platform 481d0000.can can1: setting BTR=1c02 BRPE=0000

However the multiplexed pins are not assigned to the CAN controller by default.

To temporary assign I/O header P9 pins 24 & 26 to DCAN1, execute:

config-pin p9.24 can
config-pin p9.26 can 

or to assign I/O header P9 pins 19 and 20 to DCAN0, execute:

config-pin p9.19 can
config-pin p9.20 can

Now manually bring up the CAN interface using:

sudo /sbin/ip link set can1 up type can bitrate 500000 

The bitrate above is specified as 500kHz for example, but this should be changed to be compatible with devices on your CAN bus.

Start Automatically

If you want a more permanent installation, the I/O assignment can be performed at boot via device tree overlays. Edit the /boot/uEnv.txt file and modify the following lines under ###Additional custom capes :

###Additional custom capes
uboot_overlay_addr4=/lib/firmware/BB-CAN0-00A0.dtbo
uboot_overlay_addr5=/lib/firmware/BB-CAN1-00A0.dtbo

This example enables both CAN0 and CAN1.

To automatically bring up the interface on boot, edit your /etc/network/interfaces file and add the following:

auto can0
iface can0 inet manual
    pre-up /sbin/ip link set can0 type can bitrate 500000 triple-sampling on restart-ms 100
    up /sbin/ifconfig can0 up
    down /sbin/ifconfig can0 down

Cape Design Files

If you want to make your own CANBus Cape as pictured above, open source design files are available below:

Testing & Code Development

CAN-Utils is a collection of extremely useful debugging tools using the SocketCAN interface and can be used to test and debug your interface.

Check out our tutorial for example C SocketCAN code.




4 Comments

  1. Hello…

    This is an awesome project for beginners like me for CAN interfaces on the am335x. I have marked this page and your github page for future reference. If you are to make more ideas available, please update at will!

    Seth

  2. Just FYI.
    It took me a while to figure out that the BeagleBone Black does not support CAN FD.
    Beaglebone Supports CAN 2.0 A/B (ISO 11898) at up to 1 Mb/s.
    CAN FD is an extension to the original CAN bus protocol that was specified in ISO 11898-1.

    • Thanks CRAIG for writing this very resourceful page. I’m going to mark it future projects!
      Any further findings will be greatly appreciated.
      Thanks @Christopher Holland. I think ESP32 did supported CAN -FD at some higher Rates as well.

  3. Thank you so much. A very basic question since I am beginner. I want to use the CAN H signals as a trigger -> so can I configure the BBB to have multiple pins as can and receive CAN data?

Leave a Reply

Your email address will not be published.


*