Nissan Leaf's CAN bus data capturing and analyzing


CAN basics

Controller Area Network (CAN) protocol is a robust, multi-master system for data transmission, where data is not sent directly from one node to another but instead all nodes communicate directly on the bus. This approach ensures reliability, making CAN a preferred communication choice across various industries such as automotive, aviation, industrial automation, medical equipment and many others.

CAN low (CAN_L) and CAN high (CAN_H) are physical lines used to transfer data by a method called differential signaling. These paired lines connect all nodes in the network. The voltage difference between the CAN_L and CAN_H lines is interpreted as data (bits) on the CAN bus. The advantage of using a differential signal is its resistance to electromagnetic interference and noise, ensuring reliable communication.

can-bus-nissan-leaf001

There are Standard and Extended types of CAN messages. Standard CAN have an 11-bit identifier space,

can-bus-nissan-leaf002

while Extended CAN (or CAN 2.0) builds on this, with additional data:

can-bus-nissan-leaf003

For a detailed explanation of the CAN packet structure and other information, please refer to the source section.

The Task

It was required to find out what is the state of health (SOH) of the Nissan Leaf’s battery pack. While one approach involves experimentally measuring the current capacity of the battery and comparing it with the nominal capacity, we aimed for a more elegant solution. Our method involved observing the CAN bus and analyzing the packet with the SOH ID.

Our Solution

In order to solve this challenge, we put together some hardware and firmware.

can-bus-nissan-leaf004

Access to the CAN bus can be achieved by connecting to the vehicle’s OBD port.

can-bus-nissan-leaf005

One can use a DB9 to OBD cable or connect two wires directly to the CAN_L and CAN_H pins of the OBD port.

can-bus-nissan-leaf006

We successfully captured some data. Keep in mind that the Nissan Leaf’s CAN bus baud rate is 115200. According to the available documentation, the battery SOH message ID is 5B3, and its frequency on the CAN bus is 2 Hz. The packet we captured with this ID looks like this:

0x5B3 0x78 0x92 0x3F 0xD9 0x90 0x78 0xB8 0x8A

can-bus-nissan-leaf007

The battery SOH information is contained in the second byte of the packet. It can be calculated in the following way:

$$92_{16} = 10010010_{2}$$ $$SOH = 10010010_{2} » 1$$ $$SOH = 01001001_{2}$$ $$SOH = 73\%$$

We also managed to collect and decode CAN bus data such as steering wheel movement data, state of charge (SOC) of the vehicle battery, and more. Here are the files containing data that we captured from the Nissan Leaf, Fiat Punto, and StreetScooter electric VAN.

There is also a Leaf Spy Pro Android app that acquires data from Nissan Leaf vehicles. A Bluetooth dongle is required. One of its best features is monitoring the voltage of each of the 96 battery cells.

General Tips

  • Keep in mind that the CAN bus in different vehicles can have different baud rates.

  • The availability of CAN IDs varies and depends on the manufacturer and model of the vehicle. Sometimes, it is challenging to find documentation for CAN IDs. In such cases, it may be necessary to look for documentation of specific devices of interest, sometimes even some reverse engineering is needed. The Nissan Leaf is one of the best documented vehicles in terms of available documentation, there are also communities and forums that have done a great job of decoding the data.

  • DBC files are database files that define the structure of CAN messages, detailing message IDs, signal names, bit lengths, scaling factors, and offsets. They are essential for decoding raw CAN data into human-readable values. The Leaf’s DBC file can be found here.

  • When collecting data with your prototype, remember that it can be damaged if the pins on the lower part are directly exposed, as they can short-circuit. To prevent this, ensure the pins are protected, at least by isolating them with tape.

Support

Work supported by Pane AG.

pane-ag-team-professional-marko

Sources

CAN general

  • Steve Corrigan, Texas Instruments, Introduction to the Controller Area Network (CAN), SLOA101A
  • KMP Drivetrain Solutions, Practical tips: CAN-Bus (link)
  • Arduino forum, I’m using OBD Connector for my car device (link)

Nissan Leaf

  • Nissan Leaf OBD-II manual (link)
  • Nissan LEAF CAN bus messages (.DBC format) (link)
  • Nissan Leaf 2018 CAN (link)
  • CAN messages IDs (link)
  • My Nissan Leaf forum