Additional Information

Site Information

 Loading... Please wait...

SAE J1939 Programming with Arduino - The CAN Bus Interface

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

While the code as introduced in the previous chapter was well designed and thus is highly efficient, I inserted yet another software layer between the CAN Bus interface and the ARD1939 protocol stack.

I wrote the ARD1939 source code in plain C (not C++) to assure the highest level of compatibility with other embedded systems and their compilers (yes, the code already runs under an ARM system). Naturally, systems other than the Arduino Uno or Mega 2560 require different CAN Bus drivers, and it would be quite a cumbersome endeavor to find and replace all CAN Bus function calls within the protocol.

For that reason, I created some “generic” function calls that are being used by the protocol stack. For future implementations, I only need to rewrite the can.cpp module.

Note: In addition to the MCP2515 function calls, I added a CAN Bus message ring buffer. The MCP2515’s message buffer is limited, and with higher busload (high message frequency) you will lose messages.

These function calls are yet again based on the basic structure of each serial communications program:

  1. Initialization
  2. Read Data
  3. Write Data
  4. Check Status

These functions are represented by:

  1. Initialization: canInit()
  2. Read Data: canReceive(…)
  3. Write Data: canTransmit(…)
  4. Check Status: canCheckError()

Note: For highest compatibility between compilers, I refrained from using complex structures and their pointers. The KISS principle (Keep It Simple Stupid!) makes porting the code an easy task and it increases code readability. All that comes with virtually non-existing performance restraints.


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