SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino
Paperback: 140 pages
Publisher: Copperhill Media Corporation (March 23, 2015)
Product Dimensions: 7.4 x 0.3 x 9.7 inches
This book, written by a leading expert in the field of Controller Area Network (CAN) technologies, represents the perfect guide to implementing an SAE J1939 protocol stack for embedded systems. The book is filled with numerous C/C++ code examples and valuable documentation of the resulting J1939 vehicle network data traffic. It explains in great detail the inner workings of the protocol through designing and transmitting J1939 data frames, receiving and processing J1939 data frames, and simulating J1939 ECUs (Electronic Control Units).
Other Arduino sketches (software projects) include a J1939 network scanner, and a simple SAE J1939 to USB Gateway application with associated Windows GUI (Visual Studio C# project). The collection of sketches is concluded by the ARD1939 project, a fully functional SAE J1939 protocol stack for the Arduino Uno and Mega 2560.
As an added value, the included proof of concept explains (by means of code examples and bus traffic recordings) the details of the Transport Protocol (TP) according to SAE J1939/21 (BAM Session, RTS/CTS Session) and the Address Claim Procedure according to SAE J1939/81. In combination with the low-cost and high-level user-friendliness approach of the Arduino environment, this book represents the ideal platform to learning and implementing embedded applications with the SAE J1939 protocol stack.
While the book's focus is 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.
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.
- Generic ARD1939 Arduino Sketch
- ARD1939 - Data Traffic Simulation
- ARD1939 - Advanced Data Traffic Simulation
- ARD1939 - J1939 Gateway
- ARD1939 - Receiving Messages
- ARD1939 - Requesting Messages
- ARD1939 - RTS/CTS Tester
- ARD1939 - Stress Test
- MCP_CAN Library for Arduino
Table of Content
1.1 The Arduino Uno And Mega 2560 plus CAN Shield
1.1.1 CAN Shield
22.214.171.124 Microchip MCP2515 CAN Controller
126.96.36.199 Arduino CAN-Bus Shield by SK Pang electronics
188.8.131.52 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
184.108.40.206 SAE J1939/13 Off-Board Diagnostic Connector
1.2 Arduino Programming (Sketches)
1.2.1 The MCP2515 Library
220.127.116.11 Function Calls
18.104.22.168 The CAN Interface
1.2.2 Special Programming Topics
22.214.171.124 Hungarian Notation
126.96.36.199 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)
188.8.131.52 Multi-Packet Broadcast (BAM Session)
184.108.40.206 Multi-Packet Peer-to-Peer (RTS/CTS Session)
2.4.2 SAE J1939/81 - Address Claim Procedure
220.127.116.11 Technical Requirements
18.104.22.168 Device NAME
22.214.171.124 Preferred Address
126.96.36.199 Address Claiming Procedure
2.5 SAE J1939 Compliance Criteria
3.1 SAE J1939 Monitoring And Simulation
3.1.1 SAE J1939 Simulation Example
188.8.131.52 Message Design
184.108.40.206 Arduino Code
220.127.116.11 Proof of Concept
18.104.22.168 Advanced Program Version
22.214.171.124 SAE J1939 Stress Simulator
3.1.2 SAE J1939 Monitoring Examples
126.96.36.199 Receiving J1939 Message Frames
188.8.131.52 Receiving and Responding to J1939 Request Frames
3.1.3 A Simple SAE J1939 to USB Gateway
184.108.40.206 J1939 Network Scanner
220.127.116.11 J1939 Data Traffic Monitoring
18.104.22.168 J1939 Data Traffic Simulation
22.214.171.124 Visual Studio Code
3.2 ARD1939 - J1939 Protocol Stack for Arduino
3.2.1 ARD1939 - Function Overview
3.2.2 ARD1939 - Implementation
126.96.36.199 Functionality Settings
188.8.131.52 Program Structure
3.2.3 Proof of Concept
184.108.40.206 Address Claim Procedure (SAE J1939/81)
220.127.116.11.1 Claiming Address With No Contending Node
18.104.22.168.2 Claiming Address With Contending Node
22.214.171.124 Sending and Receiving Messages
126.96.36.199 Transport Protocol – BAM Session (SAE J1939/21)
188.8.131.52.1 Message Timing
184.108.40.206 Transport Protocol – RTS/CTS Session (SAE J1939/21)
220.127.116.11.1 Message Timing
18.104.22.168.2 Clear to Send Timeout
3.2.4 ARD1939 - Sample Application
Appendix A – Debugging Macros
Appendix B - ARD1939 Protocol Stack Reference
Function Calls Description
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 personally consider J1939 the most effective CAN protocol in the market due to its small memory footprint combined with a bandwidth that easily 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 great popularity the J1939 protocol enjoys in the North American market. CANopen and DeviceNet, in view of the overpowering strength of Industrial Ethernet for automation, are nearing their virtual end-of-lifetime cycle for new developments and for that reason 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, of course, not only some knowledge of C/C++ programming but also some basic knowledge 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 their language specific sites), Barnes & Noble (bn.com), Abebooks.com (including all their language specific sites), and other online bookstores all over the world.
In the same sense, I will also not engage into explaining the basics of the Arduino hardware and its programming. There are myriads of books on Arduino, Arduino Sketches, and Arduino Shields available on the topic, and it makes no sense repeating the information therein just 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 for the purpose of providing information that will enable the reader to replicate my projects. I deem it also important to point to the hardware’s performance limitations. After all, the Arduino may be the prefect prototyping solution, but implementing, for instance, a full-blown SAE J1939 protocol definitely meant pushing the limits.
I will also refer to some programming topics that not only go beyond Arduino basics but also reflect my personal 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 on the development of the most interesting feature of this book, the ARD1939, an SAE J1939 protocol stack for Arduino.
The implementation of 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 have to pay for each copy. At least in the case of the Arduino hardware, this is going to change, and the ARD1939 protocol stack project is available as a free download.
Quite honestly, the development of a J1939 protocol is not a big deal for an experienced programmer, the only obstacle being that you have to spend 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 a number of commercially available J1939 devices.
I had contemplated releasing ARD1939 in form of the original source code but 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 original 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 these days. 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, through using the pre-compiled ARD1939 code, will be quite able to write effective J1939 applications, regardless of whether or not he/she has access to the original source code. After all, there is no real need to modify a working code. It supports all SAE J1939 protocol features, and the focus should always be on the actual application.