SAE J1939 Programming with Arduino - Program Structure
This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino.
As with every Arduino application, the initialization of data and the J1939 protocol takes place during the setup() function, while the actual application resides in loop().
setup() - The j1939.Init function is mandatory to operate ARD1939.
You also need to set the preferred address and a NAME (for test purposes you can use the project default settings). Setting an address range is optional.
ARD1939 will not deliver any data (PGNs) unless you set the message filter. ARD1939 supports up to 10 (UNO) or 100 (Mega 2560) message filters.
loop() – This function must start with a delay() call, directly followed by j1939.Operate().
It is mandatory that the delay time and the time passed to j1939.Operate are identical, otherwise the protocol timing will be off, which, in turn, may cause error conditions.
The following code sample demonstrates a sample J1939 protocol stack application:
Each Arduino sample application, as introduced in the following chapters, will follow this same scheme.
Note: The ARD1939 sketch I provide through the download page also follows this template. I have, however, added some sample code that I used for the proof of concept. These sample code sections are commented out in the main file, but you can, of course, reactivate the sections you like to use.
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.