Site Information

 Loading... Please wait...

SAE J1939 Programming with Arduino - MCP2515 Function Calls

Posted by Wilfried Voss on

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

There are further functions, among others, for message filtering and settings masks, and they are worth being checked out for more sophisticated functions, but they are not necessary for simple CAN communication tasks.

The implementation of the MPC2515 library is fairly easy: Open Arduino, create a new file, then use the menu items Sketch->Add File… to include the following files to the project:

  • mcp_can.cpp
  • mcp_can.h
  • mcp_can_dfs.h

In the Arduino project file add the following on top:

#include "mcp_can.h"
#include <SPI.h>
MCP_CAN CAN0(10);

Let me repeat two important points regarding the MCP2515 here:

  • The Seeed Studio CAN bus shield has been undergoing some hardware changes to become compatible with systems such as the Arduino Mega 2560. The version 1.0 will work with the Arduino Uno, while all higher versions also work with the Mega 2560. This will also affect the code of the Arduino projects, specifically the line “MCP_CAN CAN0(10);” in the main module selecting the CS pin. That line must change to “MCP_CAN CAN0(9);” for all CAN bus shield versions above 1.0.
  • While the MCP2515 provides message filters and masks, their programming presented a challenge to a point of virtual uselessness (the original code delivered by Microchip is useless per default). The MCP2515 driver code as used in this book’s Arduino projects does refer to message filtering, but the author of the code does not guarantee proper functionality. For that reason, all message filtering in the introduced Arduino projects is accomplished per software.

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