CAN bus with Arduino Due

From openinverter.org wiki
Jump to navigation Jump to search

You can analyse CAN bus traffic using an Arduino Due.

You will need the following:

  • An Arduino Due board
  • One or two SN65HVD230-based CAN transceivers
  • An SPI Micro SD storage module (optional)

Here are the steps:

Configure your Arduino IDE

Download and install the Arduino IDE on your computer

Tools -> Board -> Boards Manager. Type "due" in the search box and install "Arduino SAM Boards (32-bits ARM Cortex-M3)"

Connect your computer to the the "programming" USB port on the Arduino Due board with a USB cable. The Due has two USB ports and they're used for different purposes. More on that later...

Tools -> Port. Make sure your Arduino board is selected

File -> Examples -> 01.Basics -> Blink

Sketch -> Upload

Hopefully you have a blinking light on your Arduino board. This means your IDE is working.

Get CAN working

The Due has two on-board CAN interfaces. However, the board lacks the necessary CAN transceivers to make then useful. You will need to add the transceivers yourself. You can find suitable 3.3V SN65HVD230-based CAN transceivers easily on eBay. They are very cheap. Unfortunately, not all of them work.

This SN65HVD230 transceiver did not work

Initially, I tried tiny ones that look like this. They were all faulty.

This SN65HVD230 transceiver worked

I tried some bigger ones with screw terminals. These all worked perfectly.

Connect the transceivers to the Due board

The CAN0 interface is on the pins marked CANRX and CANTX

The CAN1 interface is on the pins marked DAC0 (RX) and 53 (TX)

Connect the CAN bus on the two transceivers together (CANL to CANL, CANH to CANH)

Connect your computer to the the "native" USB port on the Arduino Due board with a USB cable and make sure Tools -> Board: "Arduino Due (Native USB port)" is selected.

Tools -> Manage Libraries... Type "due_can" in the search box and install "due_can"

File -> Examples -> due_can -> CAN_ExtendedPingPong

Sketch -> Upload

Tools -> Serial Monitor

If your CAN transceivers are working properly, you should be rewarded with incrementing numbers in the serial monitor window.

Install GV-RET

Once you've confirmed that your CAN transceivers are working, you can move on to installing the Generalized Electric Vehicle Reverse Engineering Tool (GV-RET). This software will allow your Due CAN transceivers to talk to SavvyCAN.

You need to install a number of libraries (in addition to the due_can library installed in the last section).

Tools -> Manage Libraries... and install the following libraries:

  • SdFat
  • DueFlashStorage

Now install the following libraries manually. In each case, the installation procedure is:

  1. Download the .zip file
  2. Rename the file to remove "-master" or any other postfixes. This is important!
  3. Install the library with Sketch -> Include Library -> Add .ZIP Library... and select the file.

You need all of these:

Once the libraries are all installed, you can install GV-RET. Go to the GitHub webpage, and click on Code -> Download .ZIP.

Expand the .zip file and put the folder in your Arduino sketchbook location. Open the GV-RET project and install it

File -> Open -> GVRET.ino

Sketch -> Upload

Tools -> Serial Monitor

If everything worked, you should be rewarded with the following messages in the serial console:

Resetting to factory defaults

Using stored values for digital toggling system

Running on CANDue hardware

11977 - ERROR: Could not initialize SDCard! No file logging will be possible!

Build number: 343

Done with init

Congratulations! Your Due is now a powerful CAN sniffer and injection tool. You can connect the CAN-H and CAN-L terminals of a CAN bus transceiver to the CAN bus in your vehicle.

Get started with SavvyCAN

SavvyCAN is a powerful, free, open source tool for analysing CAN traffic. Download and install it on your computer. It can be a bit intimidating, so there's a 30 minute tutorial to help you find your feet:

No doubt you're far to impatient to sit through a tutorial, so let's dive straight in and connect to your Due. Go back to the Arduino IDE and note down the name of your Due USB connection. On my Mac, it's "/dev/cu.usbmodem2441"

Connection -> Open Connection Window

Add New Device Connection and select the USB connection you noted earlier

Create New Connection

Check "Enable Bus" and set the Speed to match your CAN bus. 500000 is a good guess.

Check "Enable Console" and you should see SavvyCAN successfully connect to your Due.

Start hacking