Site Information

 Loading... Please wait...

SAE J1939 Protocol Stack Sketch for Arduino Due

Posted by Wilfried Voss on

Arduino DUE CANShield With 2 CAN Ports

The availability of Controller Area Network (CAN) interfaces in combination with other interface technologies explains the vast popularity of the ARM Cortex-M3 processor in the CAN and SAE J1939 industry. The processor provides the means to easily and quickly create applications like CAN/J1939 gateways, CAN Bridges, J1939 ECUs, J1939 Data Logger, and many more.

The  Arduino Due is the first ARM-based Arduino development board. The programming of the microcontroller is accomplished through the familiar Arduino IDE (Windows, Mac), keeping the programming as backward compatible to other Arduino systems as possible, thus allowing a smooth migration between processor systems.

Just like any other ARM M3 processor, the Due supports two CAN ports. The downside, though, is the mere fact that the Due's CAN capabilities are basically useless without additional hardware components. In order to save costs, but at the same time enabling the user to pay only for the interfaces needed for the project, the board design is limited to providing the processor with the bare necessities, while routing all interfacing signals “as is” to onboard connectors.

For instance, the serial interfaces such as Controller Area Network (CAN) and UART (RS-232/422/485) provide only TTL levels, and you will need additional hardware (transceivers) to make them hardware-compliant with their respective standards. For more detailed information, see my post  ARM Cortex M3 Development Boards Require External CAN Bus Transceiver.

There are several options to add the necessary CAN transceivers to the Due board:

CAN Bus Driver Software

The best package I found was the  due_can package by Collin Kidder as published on GitHub. I used his source code for a quick head start, but also modified it slightly and added a "wrapper" around it, i.e. I created more user-friendly CAN Bus access functions.

For more information, see my post Arduino Due 2-Channel CAN Bus Driver Software.

ARD1939 - SAE J1939 Protocol Stack for Arduino

The ARD1939 SAE J1939 protocol stack for Arduino was originally developed for the Arduino Uno and Arduino Mega 2560.

sae-j1939-ecu-programming-300w.jpgAll technical information about ARD1939, the SAE J1939 protocol stack for Arduino, plus detailed description of implementation and available function calls is included in my book SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino.

Arduino sketches (software projects) include a J1939 network scanner, and a simple SAE J1939 to USB Gateway application with associated Windows GUI (Visual Studio C# project). The collection of sketches is concluded by the ARD1939 project, a fully functional SAE J1939 protocol stack for the Arduino Uno and Mega 2560.

ARD1939 for Arduino Due

The ARD1939 code itself is directly compatible with the Arduino Due, however, the Arduino Due CAN Bus driver software required some modifications. Basically, I needed to adjust the CAN Bus function calls to the same functionality as used for the Uno and Mega 2560.

Please note: I had contemplated releasing ARD1939 in form of the original source code but ultimately decided against it, mostly out of respect for those small businesses that make a living from selling SAE J1939 devices and software tools. Instead, I provide a pre-compiled code.

Download the Software

Disclaimer: All Arduino sketches and other code samples and projects as introduced here are free software; you can redistribute and/or modify them. The programs are introduced in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. With downloading these programs, you confirm that these code samples and projects were created for demonstration and educational purpose only.

=> Download the ARD1939Due Arduino Sketch (zip file)...

Last, but not least, a few tips...

  • Make sure you have the latest Arduino IDE installed (check at arduino.cc). The Arduino people have this absolutely annoying habit of providing updates that are far from backwards-compatibility, meaning compiling a perfectly good program may result in an enormous list of inexplicable error messages.
  • Make sure, your IDE is set up for the Arduino Due. Go to Tools->Boards->Boards Manager to install Due capabilities.


Programming Arduino Getting Started with Sketches

by Simon Monk

programming-arduino-getting-started-with-sketches-by-simon-monk.jpgClear, easy-to-follow examples show you how to program Arduino with ease! "Programming Arduino: Getting Started with Sketches" helps you understand the software side of Arduino and explains how to write well-crafted Sketches (the name given to Arduino programs) using the C language of Arduino. This practical guide offers an unintimidating, concise approach for non-programmers that will get you up and running right away.

Programming Arduino: Getting Started with Sketches explains basic concepts and syntax of C with simple language and clear examples designed for absolute beginners - no prior knowledge of programming is required. It leads you from basic through to advanced C programming concepts and features dozens of specific examples that illustrate concepts and can be used as-is or modified to suit your purposes.

  • All code from the book is available for download.
  • Helps you develop working Sketches quickly.

Coverage includes: C Language Basics; Functions; Arrays, Strings; Input / Output; Standard Library Goodies; Storage; LCD Displays; Programming for the Web; Program Design; C++ and Library Writing

More Information...