• Stars
    star
    324
  • Rank 125,472 (Top 3 %)
  • Language
    C
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SAE J1939 protocol free to use for embedded systems or PC with CAN-bus

Open SAE J1939

SAE J1939 is a protocol for shaping the CAN-bus message in a specific way that suits industrial vehicles such as tractors, machinery, trucks and more.

SAE J1939 is a very easy protocol to use, but there is a lack of information about SAE J1939, due to the cost of the protocol document, available how to shape a CAN-bus message according to SAE J1939 protocol standard. So therefore I’m writing a SAE J1939 protocol available for free to use on any embedded systems such as STM32, Arduino, AVR, PIC etc or PC.

To learn to build on this project, you need first to understand SAE J1939. I have written this project in C language because C is an industry standard. The C language dialect I have chosen is ANSI C (C89) and I don't use dynamical memory allocation in this library. So it will work with MISRA C standard.

With this library, you can communicate with valves, engines, actuators, machinery, hardware and all other things that are suitable for heavy industrial mobile applications. I have build up a basic structure of the project and I hope that other users will send pull request of their C code for extra functionality to SAE J1939 standard because SAE J1939 is a huge standard.

Looking for CANopen library? https://github.com/DanielMartensson/Easy-CANopen/

Looking for a QT C++ framework implementation with Open SAE J1939 over USB? https://github.com/DanielMartensson/OpenSourceLogger

Logging for a STM32 project with Open SAE J1939? https://github.com/DanielMartensson/STM32-PLC

Getting started

The first thing you need to know is to read the document Open SAE J1939.pdf inside the Documentation folder. Learn the structure of the project, else you won't be able to understand SAE J1939. After you have got a basic understanding of the project, you are able to build on it. Keep it simple and follow the SAE J1939 standard!

After you have understand the structure of the project, then select processor choice in Hardware -> Hardware.h file. Here you can select for example STM32, Arduino, PIC, AVR etc. or if you want to run it on PC first, then select PROCESSOR_CHOICE 0 and run some examples. That's the debugging mode for internal CAN feedback.

How to use the project

  • Step 1: Download this repository
  • Step 2: Go to Hardware -> Hardware.h and select your processor, if it's not available, please write code for it and send me a pull request
  • Step 3: Copy over the Src folder to your project folder inside your IDE. Rename Src to for example Open SAE J1939. That's a good name.
  • Step 4: Use the Examples -> Open SAE J1939 -> Startup.txt example as your initial starting code for a SAE J1939 project.
#include <stdio.h>

/* Include Open SAE J1939 */
#include "Open_SAE_J1939/Open_SAE_J1939.h"

/* Include ISO 11783 */
#include "ISO_11783/ISO_11783-7_Application_Layer/Application_Layer.h"

int main() {

	/* Create our J1939 structure */
	J1939 j1939 = {0};

	/* Load your ECU information */
	Open_SAE_J1939_Startup_ECU(&j1939);

	while(1) {
		/* Read incoming messages */
		Open_SAE_J1939_Listen_For_Messages(&j1939);
		/* Your application code here */

	}

	return 0;
}

See the examples in Examples -> SAE J1939 how to change the address, NAME or identifications for your ECU.

The structure of the project

a

SAE J1939 functionality

  • SAE J1939:21 Transport Layer
    • Acknowledgement
    • Request
    • Transport Protocol Connection Management
    • Transport Protocol Data Transfer
  • SAE J1939:71 Application Layer
    • Request Component Identification
    • Request ECU Identification
    • Request Software Identification
  • SAE J1939:73 Diagnostics Layer
    • DM1
    • DM2
    • DM3
    • DM14
    • DM15
    • DM16
  • SAE J1939:81 Network Management Layer
    • Address Claimed
    • Commanded Address
    • Address Not Claimed
    • Delete Address

Extra functionality

  • ISO 11783 Tractors And Machinery For Agriculture And Forestry
    • ISO 11783-7 Implement Messages Application Layer
      • Auxiliary Valve Command
      • Auxiliary Valve Estimated Flow
      • Auxiliary Valve Measured Position
      • General Purpose Valve Command
      • General Purpose Valve Estimated Flow

Questions and answers

  • Q: Can this library be used with C++?
    • A: Yes it can be used with C++
  • Q: I want to build on this library, what should I do?
    • A: First you need to know ANSI C (C89) and bitwise operations. Then you need to understand the SAE J1939:21 Transport Layer structure. Don't forget to update the PDF with your new functionality.
  • Q: Can I use this on my Arduino?
    • A: Yes, this C code is 100% pure C code and only using C standard library and also the code does not take account of what hardware you are using.
  • Q: Do I need to install the library for to use the library?
    • A: No, just copy over the .c and .h files to your project and compile. I have used this with QT framework.
  • Q: This project is quite old now and not so much updates, is it still worth to use it?
    • A: Yes, this library only updates when I or other includes more functionality from SAE J1939. The reason why I wrote this in ANSI C (C89) is because it's an industry standard and will you will always be able to compile this library and use it on all systems.
  • Q: What is your plan with the library?
    • A: To make SAE J1939 available for everybody
  • Q: I don't have CAN-bus, but can I use this library anyway with UART, USB, WiFi etc?
    • A: Yes. This is only a way to shape a message in a specific way.
  • Q: Can I send data with this library, even if I don't have CAN-bus?
    • A: Yes. There are something called DM14 transmit request, DM15 status response and DM16 binary transfer. Use that if you want to transfer data in an industrial way.
  • Q: Can I send multi package messages from from multiple ECU:s to one ECU at the same time?
    • A: No. If you starting to send multipackages from multiple ECU:s to another ECU, then that ECU cannot understand the message. Transmit only multipackage messages one at the time if the destination address is the same.
  • Q: I don't want to use 'ANSI C (C89)' with Open SAE J1939. Can I use the latest C standard with Open SAE J1939?
    • Yes, you can use the latest C standard with this library.
  • Q: Is it possible to compile this library onto a Windows MS-DOS or Windows 95 machine?
    • A C89 compatible compiler and an IDE and it should not be any problem

Issues and answers

  • I: I cannot compile this library. I'm using Keil Microvision.
    • A: Keil Microvision cannot handle binary numbers such as 0b010101. Try STM32CubeIDE instead because Open SAE J1939 is made in STM32CubeIDE
  • I: Can you provide us with some hardware examples for example STM32?
    • A: Yes! There is a STM32 example how to get connection with CAN-bus including an interrupt listener for messages. Go to Examples -> Hardware folder at look for CAN_STM32.txt. Also there is a USB example as well for QT C++.

More Repositories

1

CControl

Using advanced control and computer vision techniques in an easy way for embedded
C
195
star
2

EmbeddedLapack

Linear algebra for embedded system with MATLAB style
C
128
star
3

Adaptive-Control

Adaptive control methods developed by Karl Johan Åström and Björn Wittenmark from the 70-80's for industrial use
MATLAB
81
star
4

STM32-PLC

STM32 microcontroller with lots of periferials such as ADC, differential ADC, Input Capture, PWM, USB, Encoder, DAC, Digital Input, RTC, CAN-bus + Alarm etc.
C
77
star
5

Easy-CANopen

A CANopen protocol for all systems such as embedded, PC, etc.
C
70
star
6

MataveID

System identification toolbox for GNU Octave and MATLAB
MATLAB
69
star
7

STM32-Libraries

Collection of rewritten Arduino libraries to STM32 libraries
C
62
star
8

PLC-Simulations

A collection of PLC simulations with CodeSyS V3, Siemens LOGO and iX Developer
38
star
9

MataveControl

GNU Octave and MATLAB control toolbox
MATLAB
26
star
10

OpenSourceLogger-Qt

Open Source Data Acquisition System
C++
18
star
11

Unscented-Kalman-Filter

Unscented Kalman Filter in C code and MATLAB code - Easy to use
16
star
12

OpenSourceLogger

Data acquisition software with STM32-PLC. Collect measurement, analyze CAN-messages and send SAE-J1939 messages to other ECUs.
C
12
star
13

GoobySoft

General software for logging and controlling devices. Controlling Modbus, CAN bus via STM32PLC etc
C++
11
star
14

Optimal-Control

A collection of physical linear state space models with optimal control and Matavecontrol
8
star
15

Deeplearning2C

Using Deeplearning4J with JavaFX for mobile and desktop use and generate C-code and MATLAB-code
Java
7
star
16

JLogger-Mobile

A free opensource sensor to log file IoT tool for Android/Iphone/Windows/Linux/Mac
C
6
star
17

jFaces

Use jFaces to predict unknown images by training a set of images
Java
6
star
18

Darknet-Data-Creator

Create data and train models with Darknet framework
Java
5
star
19

GNU-Octave-Logger

Basic data acquisition system with Arduino UNO and GNU Octave
MATLAB
4
star
20

Camera-Reporter

Camera reporter with mail feature. This project uses the Darknet library for identify objects. It also uses Spring Boot to handle the web service and mail
Java
4
star
21

STM32-Ethernet-Camera

PCB board with camera and ethernet connection + CAN-bus
C
3
star
22

OpenSourceLogger-Web

Use and STM32 to store measurements into a MySQL server over the web
C
3
star
23

Java-Applications

Simulation of 3D models, web applications, JavaEE, JavaFX and Sockets
C
3
star
24

CSV2MySQL

Insert CSV into a MySQL/MariaDB database by using a schedule task
Java
3
star
25

Pictures-Of-Things

Data trained with Darknet Data Creator
Java
2
star
26

Memorize-Sentences

A tool for memorizing sentences in all languages.
Java
2
star
27

PiJukeBox

This is an old Swedish radio Centrum U68 from 1940 that I have rebuilt into a MP3-player, sorry.
Java
2
star
28

Test-Bench-Data

Contains CRUD, Charts, Menu Layout, FTP downloader, Spring JPA, Spring Security
Java
2
star
29

BooK

A booking system made in JavaFX for mobile and desktop use
Java
2
star
30

STM32-Registers-Only

Programming the ARM STM32 controllers with registers only
C
1
star
31

Stock-Trend

Analyse trends of stocks from Yahoo Finance
C++
1
star
32

FisherFaces-Examples

Testing - What can be done with Fisherfaces
MATLAB
1
star
33

C-Applications

Embedded C with ST Microelectronics CubeMX and other C-applications
C
1
star
34

GoobyBox

I/O Shield for Arduino UNO
1
star