Site Information

 Loading... Please wait...

Blog

SAE J1939 Programming with Arduino - A Simple SAE J1939 to USB Gateway

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

I deem it necessary to provide a definition of “SAE J1939 to USB Gateway,” because there are several variants of gateway applications.

If you browse through the Internet in search for J1939 gateways, you will primarily find CAN gateways that support the conversion of 11-Bit and 29-Bit CAN messages into another serial technology such as USB, RS232, etc. Since SAE J1939 is based on CAN messages with a 29-Bit identifier, many manufacturers take the liberty of calling their devices “SAE J1939 gateways,” which is not only misleading but also may lead to technical problems when connecting these devices to a real vehicle (diesel engine).

The problem lies in the fact that these so-called gateways do not come with an integrated SAE J1939 protocol stack and thus cannot support the address claiming process according to SAE J1939/81. When transmitting data into a J1939 vehicle network you need to supply a node (source) address with the data frame, and that node address must be unique. The absence of a protocol stack in the gateway may result in node ID collisions and therefore may cause serious technical problems.

The problem can be circumvented when all node IDs in the network are hard-coded and you assign a free node ID to messages you send into the network. This may work in limited cases, but this method is, naturally, not recommended.

The purpose of these types of J1939 gateways should be mere data monitoring, i.e. only receiving J1939 messages (you still need to decipher J1939 messages longer than 8 bytes, which is a cumbersome task). In order to communicate with the vehicle bus (bidirectional communication) you need a full SAE J1939 protocol implementation with address claim procedure and support of messages longer than 8 bytes.

Nevertheless, in the following I will introduce this kind of gateway with all its disadvantages, but I will do so for mere demonstration and educational purposes. The Arduino sketch, as introduced in the following, is the first step toward a full SAE J1939 gateway with integrated protocol stack (See chapter ARD1939 – SAE J1939 Protocol Stack for Arduino).

Some of the previous Arduino sketches as introduced in this book already provide the features for a simple SAE J1939 to USB gateway. However, they were designed to merely receive messages. A gateway application requires that we can send messages as well. The need for bidirectional communication also leads to the next requirement for a J1939 gateway, namely the definition of a communication protocol between the gateway and the host system (usually a PC).

Since our focus is on the Arduino hardware, the connection between the gateway (i.e. the Arduino) and the PC is established per USB interface. The foundation of the USB protocol is already established through the Serial.print function and the protocol will be based on transmitting ASCII text.

The data communication is managed through the Arduino’s serial monitor, but I will also introduce a replica of the serial monitor with Visual Studio C# in another chapter to follow. If you wish to create a more sophisticated data communication between the Arduino and a PC, the following projects will provide a solid foundation.

Our simple J1939 to USB gateway will provide three functions:

  • A J1939 Network Scanner, i.e. the Arduino will scan a J1939 network for existing nodes and retrieve information from them.
  • A Data Traffic Monitor similar to the previously introduced projects.
  • A Data Traffic Simulator, i.e. the Arduino will send user-defined messages into the network.

Note: As usual, the following Arduino projects are available through the download page at ARD1939 - SAE J1939 Protocol Stack for Aduino. However, all three functions (network scanner, data traffic monitor, and data traffic simulator) are combined into one project, since the ladder two features are additions to the previous project.


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...

Programmable, Arduino-Due-Based USB Gateway With Two CAN Bus Ports

As part of our business strategy of providing prototyping solutions for the CAN Bus (including SAE J1939, ISOBUS, NMEA 2000) we have decided to focus more on the Arduino platform, specifically the Arduino Due. The Due, while providing the power of an ARM Cortex M3 processor, comes with two CAN Bus ports per default, however, lacking the [...]

Read More »


USB Module with 2 CAN FD Interfaces Plus Analog And Digital IRIG-B Inputs

The CAN-USB/400-FD by esd electronics is equipped with two independent CAN FD interfaces according to ISO 11898-1:2015; they are driven by the ISO 16845:2004 certified esdACC (esd advanced CAN Core) implemented in an Altera® FPGA. The interface is able to send and receive ISO conform CAN FD (up to 5 Mbit) or CAN 2.0 A/B messages. The CAN [...]

Read More »