How to enable CAN bus on Nvidia Jetson TX2 Developer Board

I. Requirements

  • Nvidia Jetson TX2 Developer Board
  • Flash Jetson TX2 with Jetpack 3.2
  • Jumper wires
  • 120 ohm resistor (optional)
  • Transceivers (up to 2 for 2 CAN bus ports). I used this Waveshare transceiver

waveshare

II. How to wire

In Jetson TX2 dev board, it comes with 2 CAN controllers. So one can have 2 different CAN ports by using 2 transceivers connecting to these CAN controllers. This article shows how to enable both CAN ports and let them communicate with each other.

Locate J26 / GPIO Expansion Header and its pin. You can find the spec of these pins on the Jetson TX2 Dev Kit Carrier Board Specification document at https://developer.nvidia.com/embedded/downloads , all the documents are free to download but require a login.

=== Connecting Jetson & Transceiver ===
Can0
Pin 5 <-> CAN RX
Pin 7 <-> CAN TX
GND <-> GND
3.3v <-> 3.3

IMG_0589

Can1
Pin 15 <-> CAN RX
Pin 17 <-> CAN TX
GND <-> GND
3.3v <-> 3.3

III. Commands

If using Jetpack 3.2 or later, you won’t have to worry about enabling header for mttcan, this seems like a missing thing from earlier Jetpack version.

In a terminal, type following commands to setup CAN channels and their bitrate. The bitrate here is 500K but one can change to other numbers per  your need. I did test up to 1 million bit-rate.

sudo modprobe can
sudo modprobe can_raw
sudo modprobe mttcan
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0
sudo ip link set can1 type can bitrate 500000
sudo ip link set up can1

In another terminal, check if the CAN bus are set up

ifconfig

Install can-ultils to send and receive CAN message over terminal

sudo apt-get install can-utils

III. Example send & receive can message

For example, you connect both can0 to can1 together. You want to send a sample message from can0 and receive from can1.

In one terminal, run:

candump can1

In another terminal, run, for example:

cansend can0 01a#11223344AABBCCDD

If the message was sent successfully, you will see the message on can1’s terminal

IV. Possible Error

The transceiver do not come with a terminal resistor (120 ohm) built-in. If the other CAN device you connect to also does not have the terminal resistor, you need to insert one into the system to get the message flow through. Otherwise, all messages would go into error state.

Reference:

https://devtalk.nvidia.com/default/topic/1025010/jetson-tx2/how-to-use-can-on-jetson-tx2-/

https://devtalk.nvidia.com/default/topic/1006762/jetson-tx2/how-can-i-use-can-bus-in-tx2-/3

https://sgframework.readthedocs.io/en/latest/cantutorial.html

 

*** Disclosure: As an Amazon Associate I earn from qualifying purchases. ***

Thank you for visiting. I love to keep my website efficient with useful content. I personally use and test all hardware items mentioned in this website. Using my affiliate link for your purchase costs nothing to you but helps the site greatly to deliver even more awesome content in the future.

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s