Applying the SAE J1939 Interface (continued)

Newsletter header - volume 13 issue 1

(Section continued)

Sensor Tip
History, Overview and How to Apply the SAE J1939 Interface (continued)

How to Apply SAE J1939

Applying SAE J1939 involves understanding its structure, selecting the right hardware/software, and integrating the protocol into your embedded system, telematics device, or diagnostic tool. Below is a practical, step-by-step guide.

1. Understand Your Use Case

Identify what you want to achieve:

• Reading engine speed, temperatures, pressures
• Logging diagnostic codes (DM1, DM2)
• Controlling actuators (torque control, retarder, etc.)
• Communicating with ECUs in heavy equipment

Your use case determines which PGNs/SPNs you must support.

2. Get the Required Documents

SAE J1939 is a family of standards. Common ones include:

• J1939-21: Data link layer
• J1939-71: Vehicle application layer (PGNs and SPNs)
• J1939-73: Diagnostics
• J1939-81: Network management

These describe message formats, timing, and parameter definitions.

3. Choose the Hardware

You need:

• A CAN transceiver
• A CAN controller or MCU with CAN built-in
• Optional gateway or telematics device for logging

Common microcontrollers:

• STM32 (bxCAN, FDCAN)
• Microchip PIC/dsPIC/AVR with CAN
• NXP LPC/FlexCAN

For testing, USB-to-CAN tools help:

• Peak PCAN
• Kvaser Leaf
• Vector VN series

4. Implement or Use a J1939 Stack

You can either:

• Use an existing J1939 software stack
• Develop your own

A minimal stack includes:

• CAN driver
• 29-bit ID encoder/decoder
• PGN and SPN management
• Transport Protocol (BAM, RTS/CTS)
• Address claiming
• Diagnostics handler

5. Encode/Decode CAN IDs and PGNs

Every frame uses a 29-bit CAN identifier. You need to extract:

• Priority
• PDU Format (PF)
• PDU Specific (PS)
• Source Address

Then derive the PGN:

PGN = (DP
⋅ 216 ) + (PF ⋅ 28 ) + PS

For PDU1 messages (PF < 240), PS is a destination address; PGN ends with 00.

6.
Handling Multi-Packet Messages

Implement:

• BAM for broadcast messages
• RTS/CTS for peer-to-peer transfers

This is needed for large messages such as DM messages and proprietary data.

7. Parse SPNs Inside PGNs

Each SPN has:

• Length in bits/bytes
• Scaling/resolution
• Offset
• Valid range

Example: Engine Speed (SPN 190)
Speed = 0.125
⋅ raw

8. Implement Diagnostics

Support key diagnostic messages:

• DM1: Active faults
• DM2: Previously active faults
• DM3–DM7: Clearing faults, freeze frames
• DTC decoding using SPN + FMI

This enables real-world fault monitoring.

9. Perform Testing

Verify:

• Timing and repetition rates of PGNs
• Correct decoding/encoding of SPNs
• Network management (address claim)
• Handling bus load (typically 40–70% max load)

Use CAN analyzers for validation.

10. Integrate Into the System

Depending on the project:

• ECU firmware: embed the stack into your application
• Telematics: log PGNs and send to server
• Diagnostics: create a scan tool interface
• Gateway: translate between J1939 and other protocols

Physical Connections of a J1939 Interface Sensor to a J1939 Network

Below is a clear, practical guide for wiring any sensor with a J1939 interface into a vehicle or machine J1939 CAN bus.

1. Required Physical Signals

A J1939-compliant sensor typically has 4 or 5 wires:

• CAN-High (CAN-H)
• CAN-Low (CAN-L)
• Power Supply (+12 V or +24 V, depending on system)
• Ground (GND)• Optional: Shield / Drain Wire (SHLD)

These connect directly to the vehicle’s J1939 CAN backbone.

2. Standard Wiring Connections

Connect as follows:

• Sensor CAN-H
→ Vehicle CAN-H
• Sensor CAN-L
→ Vehicle CAN-L
• Sensor Power Input
→ Vehicle +12 V or +24 V
• Sensor Ground
→ Vehicle Ground
• Sensor Shield
→ Vehicle shield or chassis ground (if provided)

Ensure:

• Ground is common with the vehicle
• CAN wires are twisted pair

3. Termination Rules (Very Important)

The J1939 backbone requires exactly two 120 Ω terminators:

• One at each physical end of the bus
• Sensors should NOT have termination unless they are at the end of the bus

If the sensor includes a termination resistor option:

• Disable it unless it is physically at the bus end

4. Stub Length Requirements

J1939 uses a backbone + short stubs.

• Maximum stub length: ≤ 1 meter
• Avoid long drops to the sensor
• Use proper twisted-pair cabling

5. Power Requirements

Typical:

• 9–32 V DC wide-range input for heavy-duty systems
• Sensor ground must match vehicle ground

Include:

• Reverse-polarity protection (often built into sensor)
• Proper fusing on the power feed

6. Shielding and EMI Considerations

If your cable has shielding:

• Connect shield to vehicle ground at one end only
• Do not ground both ends to avoid ground loops

This improves noise immunity for long cable runs.

7. J1939 Connector Types (Common)

Depending on the vehicle or equipment, you will encounter:

• Deutsch 9-pin (J1939 Type I or Type II)
• Deutsch 6-pin (older)
• Custom OEM harness connectors

Pins typically include:

• CAN-H
• CAN-L
• Battery +
• Ground

8. What Happens After Physical Connection

Once wired:

• The sensor announces its Source Address using address-claiming
• It begins broadcasting PGNs (Position, Angle, Pressure, etc.)
• Other ECUs or controllers listen automatically

No extra configuration is needed unless the manufacturer requires SA or baud-rate setup.

9. Quick Checklist

• Twisted pair CAN wiring used
• CAN-H and CAN-L polarity correct
• Power matches 12/24 V system
• Only two terminators on the bus
• Stub length < 1 meter
• Shield grounded on one end

Connecting a Magnetic Multi-Turn Rotary Sensor to a J1939 Network

Below is a clear, practical guide to integrating a magnetic multi-turn rotary sensor (typically SSI, SPI, analog, or CAN-based) into a J1939 network.

1. Identify Your Sensor Type

Magnetic multi-turn rotary sensors normally come in three categories:

A. Native J1939-Output Sensor

Best case — The sensor already supports SAE J1939 and outputs PGNs directly.

B. CAN Sensor (Non-J1939)

Outputs raw CAN frames but not in J1939 format → Requires a gateway or custom firmware to convert to PGNs.

C. Non-CAN Sensor

SSI, SPI, I²C, analog voltage, PWM
→ Requires a microcontroller interface to read the sensor and publish J1939 messages.

2. Choose the Integration Method

Case A: Sensor with Native J1939 Support

You only need to:

• Connect CAN-High, CAN-Low, +V, Ground.
• Ensure proper termination (120
Ω at each bus end).

• Configure:

◦
Source Address (SA)
◦ PGNs used
◦ Baud rate (usually 250 kbps or 500 kbps)

Common PGNs for position sensors:

• PGN 61481 – Position/Angle Information
• PGN 65103 – Proprietary A (if manufacturer-specific)

No microcontroller required.

Case B: Sensor with Generic CAN Output

You must create a translation layer.

Requirements:

• A microcontroller or CAN gateway

Examples:

◦ STM32 with FDCAN
◦ Arduino with MCP2515 + CAN transceiver
◦ ESP32 with CAN bus
◦ Commercial gateways (Kvaser DIN Rail, HMS Anybus)

Process:

1. Read sensor CAN frames.
2. Interpret angle data based on vendor data sheet.
3. Encode angle into appropriate J1939 PGN.
4. Send J1939 message onto the network.

Example J1939 angle SPN:

• SPN 1675 – Angular Position

Payload example (2 bytes):
Angle = 0.0055°
⋅ raw

Case C: Sensor with SSI, SPI, Analog, PWM

You need to:

1. Interface with a microcontroller

• SSI → use timer + GPIO reading
• SPI/I²C
→ direct MCU peripheral
• Analog
→ ADC input• PWM → timer input capture

2. Convert measured angle to SPN scaling

3. Broadcast a J1939 PGN

A common PGN choice:

• PGN 61481 – Position (standard)
• PGN 65280–65535 – Proprietary A/B PGNs (if no standard PGN fits)

3. Required J1939 Electrical Connections

Your sensor or interface must connect to the vehicle network:

CAN-H
→ CAN-H
CAN-L
→ CAN-L
+VBAT or +12/+24 V
Ground (shared)

Ensure:

• Bus has two 120-ohm terminators at each end.
• Stub length is short (typically < 1 meter).
• Cable is twisted-pair, shielded preferred.

4. Encoding the J1939 Message

Typical J1939 encoder steps:

1. Choose PGN, for example: PGN = 61481
2. Set priority (usually 6)
3. Source address assigned dynamically or static
4. Pack angle data into 8-byte payloadExample payload structure:

• Byte 0–1: Angle (LSB, MSB)
• Byte 2–7: Reserved (Ffh)

5. Example Microcontroller Pseudocode
raw = read_sensor()angle_deg = raw * resolution // from datasheetpayload[0] = (raw & 0xFF)payload[1] = (raw >> 8) & 0xFFpayload[2..7] = 0xFFsend_J1939(PGN_61481, priority=6, SA=my_address, data=payload)

6. Validation and Testing

Use:

• PCAN-View
• Kvaser CanKing
• Vector CANalyzer

There is obviously a lot of details t cover in implementing SAE J1939 protocol for a specific application that is beyond the scope of this newsletter article. Hopefully this overview will help with understanding the process, planning and some implementation.
Please email suggestions for technical subjects you would like to suggest for this newsletter to this link: Newsletter Editor