Site Information

 Loading... Please wait...

SAE J1939 Programming with Arduino – End of Message Acknowledgment Timeout

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

In order to test all timeouts during an RTS/CTS session, I used a dedicated Arduino sketch to simulate all the “nasty” features that would trigger a communication breakdown. This method was easier to implement rather than using a full SAE J1939 stack. Fiddling with the protocol stack code to simulate error conditions turned out to be time-consuming and it brought no improvement to the actual code (actually, quite the opposite, since it would blow up the code size).

As with all previous examples, this Arduino sketch (implemented on the Uno) is quite simple, and it leaves you all the possibilities of simulating a defective J1939 node.

First, we need to define the Clear to Send message in the global memory space:

  • byte msg_CTS[] = {0x11, 0x03, 0x01, 0xFF, 0xFF, 0x5F, 0xEA, 0x00};

The data is based on the previously described RTS/CTS session (see the DATA section in line 2).

The Arduino sketch, i.e. the loop() function was tailored for this specific RTS/CTS session:

As soon as the j1939Receive(…) function returns a valid data frame, we verify the PGN. If the PGN is the Transport Protocol (TP) PGN, we look at the first byte in the data array to determine if the message is a Request to Send or a Connection Abort message.

If it is a Request to Send, the Arduino transmits the Clear to Send data frame. However, the sketch will not send its End of Message Acknowledgment and that should trigger a Connection Abort message from the Mega 2560.

  • Line 1: The Mega 2560 sends the Request to Send message.
  • Line 2: The Uno transmits the Clear to Send message.
  • Line 3 – 5: The Mega transmits the data.
  • Line 6: After a timeout without receiving the End of Message Acknowledgment, the Mega sends out the Connection Abort message citing a timeout.

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