Site Information

 Loading... Please wait...

SAE J1939 Programming with Arduino - Proof of Concept

Posted by Wilfried Voss on

This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino.

SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino

Naturally, with the impression that the Arduino hardware is a far cry away from commercially available, industrial solutions, some doubters may challenge even the point that the Arduino software is up to the task of running a full SAE J1939 protocol stack. Therefore, I deem it necessary to accomplish and document a basic proof of concept. And even if you consider such a proof unnecessary, take a look at the test examples as they shows details of node communication that are of interest for each programmer. These tests explain the actual SAE J1939 protocol in more detail than any other textbook or manual.

Note: While I have tested the ARD1939 protocol characteristics in great detail, I have not documented all test results in this book, because not all of these scenarios provided a sufficient educational value.

It is also important to note that, while my test environment records timestamps, the time values as shown on the various screen shots reflect the messages at the time when they reached the actual network, i.e. they do not necessarily reflect the ECU’s internal timing.

Ironically, the Arduino is the perfect hardware to accomplish these tests, because it allows the quick setup of simulated malfunctions. Consequently, I used two Arduino systems, one as the test object and another one to simulate protocol malfunctions.

Specifically, I used an Arduino Mega 2560 version (ARD1939-Mega) as the test object, while an Arduino Uno system acted as the network simulator. In order to verify the address claim process plus the TP (Transport Protocol) communication process and timing, I modified the Arduino Uno’s code to produce communication and timing errors. The test node (i.e. the Mega 2560), in turn, must detect the errors produced by the testing node.

Both nodes will have an initial address of 0x80 (128). Both nodes also use the same NAME settings with the exception of the ECU Instance. The Arduino Uno has set the ECU Instance in its NAME to ‘0’, while the Arduino Mega uses an instance of ‘1’. This assures that the Uno will always win the address claim process against the Mega.

The settings in the code are:

1. ARD1939.h

// NAME Fields Default
#define NAME_IDENTITY_NUMBER 0xFFFFFF
#define NAME_MANUFACTURER_CODE 0xFFF
#define NAME_FUNCTION_INSTANCE 0
#define NAME_ECU_INSTANCE 0x00 or 0x01
#define NAME_FUNCTION 0xFF
#define NAME_RESERVED 0
#define NAME_VEHICLE_SYSTEM 0x7F
#define NAME_VEHICLE_SYSTEM_INSTANCE 0
#define NAME_INDUSTRY_GROUP 0x00
#define NAME_ARBITRARY_ADDRESS_CAPABLE 0x01

2. ARD1939 – setup()

// Set the preferred address and address range
j1939.SetPreferredAddress(SA_PREFERRED);
j1939.SetAddressRange(ADDRESSRANGEBOTTOM, ADDRESSRANGETOP);

// Set the NAME
j1939.SetNAME(

NAME_IDENTITY_NUMBER,
NAME_MANUFACTURER_CODE,
NAME_FUNCTION_INSTANCE,
NAME_ECU_INSTANCE,
NAME_FUNCTION,
NAME_VEHICLE_SYSTEM,
NAME_VEHICLE_SYSTEM_INSTANCE,
NAME_INDUSTRY_GROUP,
NAME_ARBITRARY_ADDRESS_CAPABLE);

Note: Per SAE J1939/81 each ECU (or better Control Application, since an ECU can accommodate several CAs) must maintain a unique NAME.

For the ultimate proof I used screen shots made with the ADFweb CAN analyzer software to document the communication between the two nodes, including timing (i.e. measuring response times and timeouts as defined by the SAE J1939 Standards Collection).

The following information can also very well serve as a generic SAE J1939 compliance test. However, there is no claim that the test methods as described are 100% complete or serve every test scenario.


A Comprehensible Guide to J1939

SAE J1939 has become the accepted industry standard and the vehicle network technology of choice for off-highway machines in applications such as construction, material handling, and forestry machines. J1939 is a higher-layer protocol based on Controller Area Network (CAN). It provides serial data communications between microprocessor systems (also called Electronic Control Units - ECU) in any kind of heavy duty vehicles. The messages exchanged between these units can be data such as vehicle road speed, torque control message from the transmission to the engine, oil temperature, and many more.

A Comprehensible Guide to J1939 is the first work on J1939 besides the SAE J1939 standards collection. It provides profound information on the J1939 message format and network management combined with a high level of readability.

Read more...