Press "Enter" to skip to content

SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino

SAE J1939 ECU Programming & Vehicle Bus Simulation with ArduinoPaperback: 140 pages
Publisher: Copperhill Media Corporation (March 23, 2015)
Language: English
ISBN-10: 1938581180
ISBN-13: 978-1938581182
Product Dimensions: 7.4 x 0.3 x 9.7 inches

This book, authored by a renowned specialist in Controller Area Network (CAN) technologies, serves as an excellent guide for those looking to implement an SAE J1939 protocol stack for embedded systems. It is replete with numerous C/C++ code examples and valuable documentation, which offer insights into the resulting J1939 vehicle network data traffic. The book delves into the inner workings of the protocol in great detail, covering topics such as designing and transmitting J1939 data frames, receiving and processing J1939 data frames, and simulating J1939 ECUs (Electronic Control Units).

Several Arduino sketches (software projects) are available. One is a network scanner for J1939. Another is a simple SAE J1939 to USB Gateway application with an associated Windows GUI (Visual Studio C# project). The ARD1939 project, a fully functional SAE J1939 protocol stack for the Arduino Uno and Mega 2560, completes the collection of sketches.

As an added benefit, this book includes a proof of concept that explains the Transport Protocol (TP) and Address Claim Procedure in detail. The proof of concept provides code examples and bus traffic recordings and follows the SAE J1939/21 (BAM Session, RTS/CTS Session) and SAE J1939/81 standards. This book, combined with the user-friendly Arduino environment and low-cost approach, provides an ideal platform for anyone looking to learn and implement embedded applications with the SAE J1939 protocol stack.

Note: While the book focuses on the Arduino Uno and Mega 2560, the documentation also applies to our SAE J1939 protocol stack for the Arduino Due.
See: SAE J1939 Protocol Stack Sketch for Arduino Due.

 

PDF Download

This title is also available as a PDF Download.

Program Samples Download

The following programming samples (accessible as .zip files) are free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The samples are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. With downloading these programs, you confirm that these code samples and projects were created for demonstration and educational purpose only.

Further Resources

Table of Content

1. Introduction

1.1 The Arduino Uno And Mega 2560 plus CAN Shield

1.1.1 CAN Shield

1.1.1.1 Microchip MCP2515 CAN Controller

1.1.1.2 Arduino CAN-Bus Shield by SK Pang electronics

1.1.1.3 CAN-BUS Shield by Seeed Studio

1.1.2 Performance Restrictions

1.1.3 Serial Interface And CAN Timing Considerations

1.1.4 Connecting Arduino to a Real SAE J1939 Network

1.1.4.1 SAE J1939/13 Off-Board Diagnostic Connector

1.2 Arduino Programming (Sketches)

1.2.1 The MCP2515 Library

1.2.1.1 Function Calls

1.2.1.2 The CAN Interface

1.2.2 Special Programming Topics

1.2.2.1 Hungarian Notation

1.2.2.2 Debugging Code with Macros

2. A Brief Introduction to the SAE J1939 Protocol

2.1 Introduction to Controller Area Network

2.2 The SAE J1939 Higher-Layer Protocol

2.3 Parameter Group Numbers (PGN)

2.3.1 Parameter Groups

2.3.2 Suspect Parameter Numbers (SPN)

2.3.3 PGN Range

2.4 The Two Elements of the SAE J1939 Protocol Stack

2.4.1 SAE J1939/21 – Transport Protocol (TP)

2.4.1.1 Multi-Packet Broadcast (BAM Session)

2.4.1.2 Multi-Packet Peer-to-Peer (RTS/CTS Session)

2.4.2 SAE J1939/81 – Address Claim Procedure

2.4.2.1 Technical Requirements

2.4.2.2 Device NAME

2.4.2.3 Preferred Address

2.4.2.4 Address Claiming Procedure

2.5 SAE J1939 Compliance Criteria

3. SAE J1939 Applications with the Arduino

3.1 SAE J1939 Monitoring And Simulation

3.1.1 SAE J1939 Simulation Example

3.1.1.1 Message Design

3.1.1.2 Arduino Code

3.1.1.3 Proof of Concept

3.1.1.4 Advanced Program Version

3.1.1.5 SAE J1939 Stress Simulator

3.1.2 SAE J1939 Monitoring Examples

3.1.2.1 Receiving J1939 Message Frames

3.1.2.2 Receiving and Responding to J1939 Request Frames

3.1.3 A Simple SAE J1939 to USB Gateway

3.1.3.1 J1939 Network Scanner

3.1.3.2 J1939 Data Traffic Monitoring

3.1.3.3 J1939 Data Traffic Simulation

3.1.3.4 Visual Studio Code

3.2 ARD1939 – J1939 Protocol Stack for Arduino

3.2.1 ARD1939 – Function Overview

3.2.2 ARD1939 – Implementation

3.2.2.1 Functionality Settings

3.2.2.2 Program Structure

3.2.3 Proof of Concept

3.2.3.1 Address Claim Procedure (SAE J1939/81)

3.2.3.1.1 Claiming Address With No Contending Node

3.2.3.1.2 Claiming Address With Contending Node

3.2.3.2 Sending and Receiving Messages

3.2.3.3 Transport Protocol – BAM Session (SAE J1939/21)

3.2.3.3.1 Message Timing

3.2.3.4 Transport Protocol – RTS/CTS Session (SAE J1939/21)

3.2.3.4.1 Message Timing

3.2.3.4.2 Clear to Send Timeout

3.2.4 ARD1939 – Sample Application

4. Conclusion

Appendix A – Debugging Macros

Appendix B – ARD1939 Protocol Stack Reference

Function Calls Description

Application Structure

Appendix C – Recommended Literature

From the Author

After writing Controller Area Networking (CAN) with Arduino, the next logical step was looking into higher-layer protocols based on CAN, in this case, the SAE J1939 vehicle network protocol. I consider J1939 the most effective CAN protocol in the market due to its small memory footprint and a bandwidth that surpasses other protocols such as CANopen and DeviceNet.

However, my swift choice for SAE J1939 was not only based on technical aspects but also on the tremendous popularity the J1939 protocol enjoys in the North American market. CANopen and DeviceNet, given the overpowering strength of Industrial Ethernet for automation, are nearing their virtual end-of-lifetime cycle for new developments. Therefore, I dismissed any thoughts of writing a book about them.

The Arduino presented itself again as the obvious choice due to its vast popularity, high level of user-friendliness, and, after all, low costs. The programming and implementation of an SAE J1939 protocol stack using the Arduino requires knowledge of C/C++ programming and some basic understanding of the Controller Area Network (CAN) technology and the SAE J1939 protocol. While I am trying to explain details where necessary (i.e., where the information pertains to programming the code), a fully detailed description of either topic is out of the scope of this book.

 For further, detailed information on Controller Area Network and SAE J1939, see my books:

Both titles are available in paperback form through Amazon.com (including all its language-specific sites), Barnes & Noble (bn.com), Abebooks.com (including all its language-specific sites), and other online bookstores worldwide.

In the same sense, I will also not explain the basics of Arduino hardware and programming. Myriads of books on Arduino, Arduino Sketches, and Arduino Shields are available on the topic, and it makes no sense to repeat the information to increase the page count.

I will, however, briefly refer to the hardware used in my J1939 projects, namely the Arduino Uno, the Arduino Mega 2560, and the CAN Shield, but only to provide information that will enable the reader to replicate my projects. I also deem it necessary to point out the hardware’s performance limitations. After all, the Arduino may be the perfect prototyping solution, but implementing, for instance, a full-blown SAE J1939 protocol meant pushing the limits.

I will also refer to some programming topics beyond Arduino basics and reflect my approach to writing readable code. These topics include programming style, debugging code, and memory management.

ARD1939 – SAE J1939 Protocol Stack for Arduino

I deem it necessary to add a few non-technical (and maybe politically incorrect) aspects to the development of the most exciting feature of this book, the ARD1939, an SAE J1939 protocol stack for Arduino.

Implementing an SAE J1939 protocol stack was (and in many cases still is) out of financial reach for many engineers. The software (i.e., the source code) is either grossly overpriced or comes with hefty royalties (object code, libraries), meaning you must pay for each copy. At least in the case of the Arduino hardware, this will change, and the ARD1939 protocol stack project is available as a free download.

Developing a J1939 protocol is not a big deal for an experienced programmer. The only obstacle is spending some good money on the official document, the SAE J1939 Standards Collection. I deem my code as good as any commercially available protocol stacks. And yes, I have successfully tested my code against several commercially available J1939 devices.

I had contemplated releasing ARD1939 in the form of the source code. Still, I ultimately decided against it, mostly out of respect for those small businesses that make a living from selling SAE J1939 devices and software tools. Instead, I provide a pre-compiled code.

The source code could be easily adapted to any other embedded hardware (I have it already running on an ARM system) and even Windows or Linux PCs with CAN capabilities.

Furthermore, the costs for off-the-shelf, industrial-strength hardware with an extended temperature range are surprisingly low. In my experience, you can easily create an SAE J1939 node with USB and Ethernet port (gateway application) with industrial-strength enclosure for under US$200 at volume = 1.

I believe that the average Arduino user will be quite able to write effective J1939 applications using the pre-compiled ARD1939 code, regardless of whether or not they have access to the source code. After all, there is no real need to modify a working code. It supports all SAE J1939 protocol features and should always focus on the actual application.

Copyright © 2024 Copperhill Technologies Corporation