Site Information

 Loading... Please wait...

SAE J1939 Programming with Arduino - BAM Session (SAE J1939/21)

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

Test items include:

  • Basic function
  • Timing control

The initial test of the BAM session requires only one ECU, in this case I am using the full protocol running on the Arduino Mega 2560 (The Arduino Uno is still connected to the network, thus the Mega 2560 will claim a source address of 0x81 = 129).

The code we added to the Mega 2560’s loop() function is highlighted:

First, we use a global variable nCounter, which is set to its default value of zero.

Inside the loop() function we create a “long” message with 15 data bytes. Then we check the address claim status, and we continue when “normal data traffic” was reached, meaning the address claim process was successful.

Every five seconds (randomly chosen) we determine the acquired source address, and send a PGN (59999, also randomly chosen) using the long message. We also use a destination address of 255, the global address, which should trigger a BAM session.

Let’s have a look at the screen shot made from the ADFweb CAN analyzer software tool:

Line 1:

  • The ECU sends the BAM (Broadcast Announce Message).
  • ID (HEX):
  • 0x1C indicates a priority of 7.
  • 0xECFF initiates the TP (Transport Protocol), meaning this is the TP.CM (Connection Management) PGN of 0xEC00 (60416) plus the global address of 0xFF (255).
  • 0x81 (129) is the ECU’s source address
  • DATA (HEX):
  • 0x20 = 32 = Control byte indicating a BAM
  • 0x000F indicates a total length of 15 data bytes (LSB first, MSB last)
  • 0x03 indicates the number of packets to be transmitted
  • 0xFF (Reserved, according to SAE J1939/21)
  • 0x00EA5F indicates the PGN (59999) of the multi-packet message (LSB first, MSB last)

Line 2 through Line 4:

  • Data sent by the ECU at address 0x81 (129)
  • The first byte indicates the sequence number, in this case going from 1 to 3
  • The following 7 bytes are raw data.
  • All unused data in the last package is being set to 0xFF

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.