Part 4 of 5 · Listening to the truck

The CAN bus controllers

A modern Iveco Daily is a network of computers that talk to each other all the time over two data buses. Two small controllers listen to those conversations and translate them into values the rest of Tartaruga can use. This work is not finished. It has been the most difficult part of the project so far.

Start here

Two kinds of CAN, and why that matters

Most people who have heard of CAN think of one thing: two wires, twisted together, carrying messages between the computers of a car. That is high-speed CAN. The Iveco uses it for the engine. But the body of the Iveco uses a different kind: fault-tolerant CAN. On a diagram the two look the same. Electrically they are very different, and almost all the tools, boards and examples you find are made for high-speed CAN.

High-speed CAN (engine bus)

5 V2.50 idledominantidle HL

Both wires rest at the same voltage. A message is a small push apart. Fast, but a broken or shorted wire stops the bus.

Fault-tolerant CAN (body bus)

5 V2.50 H idleL idledominant

The wires rest at opposite ends, and swap over for a message. Slower, but the bus keeps working on one wire if the other breaks or shorts.

SIMPLIFIED · TYPICAL LEVELS

Why does Iveco do this? The body wiring runs through doors, mirrors, the dashboard and many connectors. Wires in a door hinge break, and connectors corrode. A fault-tolerant bus keeps the central locking and the lights working with a damaged wire. That is good for the owner and hard for anyone who wants to listen in:

  • The common, cheap CAN transceiver chips cannot be used on it. They are made for high-speed CAN.
  • The resting levels are the opposite of what most equipment expects. Signals can look inverted.
  • A wrong interface does not just fail to read. If it drives the bus, it can disturb the whole body network of the truck.
Two buses

What the Iveco says to itself

Both buses are available on one connector that Iveco provides for body builders. We do not use the diagnostic (OBD) socket.

B-CAN · body bus · fault-tolerant

The body bus

  • Doors
  • Ignition and reverse gear
  • Lights
  • Radio and climate control panel
  • A copy of the engine speed
C-CAN · engine bus · high-speed

The engine bus

  • Engine speed and accelerator pedal
  • Coolant temperature
  • Battery voltage as the engine computer sees it
  • Engine running, engine stopped, starter active
  • Ignition position, light status, central locking

The CAN controllers are built to listen only. Making that true in hardware took longer than we expected.

Our controllers must never change what the truck does. They read what the truck says, and publish the decoded values as Modbus TCP servers for the PLCs, the SCADA, the radar controller and the web dashboard. The software was set to listen-only from the beginning.

Even so, the first engine-bus monitor disturbed the truck. If it was switched on while connected to the bus, its transmit line sat at the wrong level for a short time during start-up, before the software took control. In that moment the transceiver drove the bus. The engine computers logged fault codes and the instrument cluster went blank. We worked around it at first by connecting the monitor only after it had started. The permanent fix was in hardware: the transceiver is now wired into its silent mode, so it physically cannot drive the bus, whatever the processor does.

When we do need to talk to the engine computer, for example to read or clear fault codes, we use the Bosch KTS 540 diagnostic software and its interface on the truck PC (Part 1). That is a workshop tool, made for that job.

Reverse engineering

Unknown speed, unknown format

Iveco does not publish how its buses work. At the start we knew neither the speed of each bus nor the format of its messages. A CAN controller set to the wrong speed sees nothing, or only errors, and that looks exactly like a wiring fault or a broken chip. We went through many combinations of speed and message format, on both buses, before each one gave clean messages.

Once the messages came through, the meaning still had to be found. The engine bus follows the J1939 truck standard, so many of its messages can be looked up. The body bus does not, and much of it is specific to Iveco. Every value has to be found by experiment: open a door, switch on the lights, start the engine, and watch which bytes change.

So far we have found 36 different messages on the body bus and decoded about 60 values on the engine bus. Some values are certain. Others still need more testing. To finish the map, the controllers will record every message they do not yet understand, with a reference number and the exact time. Because all the controllers share the satellite time from the suspension controller (Part 2), we can note in the logbook what we did at that moment, and match it to the message later.

The values we want most are the real fuel level in the factory tank (the Iveco dashboard shows a calculated value we do not trust), exhaust temperature, and fault codes.

How we got here

A long road to clean messages

This is what happened, in order. Not all of it was the hardware's fault.

The start: Arduino and a CAN shield

We began with an Arduino and a Waveshare CAN bus shield. Between two Arduinos on the bench it worked. On the engine bus it worked in part. On the body bus it never worked, and for a good reason we did not yet understand: the shield has a high-speed transceiver, and the body bus is fault-tolerant CAN.

The Arduino IDE on the ESP32

When the ESP32's own CAN controller (TWAI) would not cooperate, we tried programming the ESP32 with the Arduino IDE instead, to get around the problem. Some parts worked, most did not. This first voyage of discovery was the most frustrating period of the whole project.

Why we kept coming back to the ESP32

An Arduino needs a separate CAN controller chip, the MCP2515, next to the processor. The ESP32 has a CAN controller built in, and it works efficiently once it is set up correctly. One chip instead of two, a simpler board, and plenty of processing power left for everything else. So every time, we came back to the ESP32.

The plan: CAN on the ESP32-P4

The ESP32-P4 boards we use for the suspension and radar controllers, including the Guition board, have CAN controllers built in. The plan was to read both Iveco buses directly on those boards, with no extra hardware.

Perfect on the desk, silent on the truck

In the chip's self-test mode, where it sends messages to itself, the CAN controller passed ten tests out of ten. Connected to the real truck, it decoded nothing.

Our own mistakes with the pins

A large part of the problem was ours. These boards have far fewer free pins than the chip itself, and many are already used by the SD card or the Ethernet port. We repeatedly tried to use pins that did not exist on the board, or that belonged to the SD card or Ethernet. On the Guition board, the signal from the pins did not reach the CAN controller. We blamed the chip, but we were not routing the pins to the CAN controller correctly. Along the way, we destroyed one Waveshare ESP32-P4 board by accident: an open wire carrying 5 V touched the board on the workbench, and a 3.3 V processor does not survive that.

Proving the truck was not the problem

When nothing worked, we went back to an Arduino, this time an Arduino Mega with an MCP2515 CAN controller, connected to the same wires. It decoded the live engine-bus traffic immediately. The bus and the wiring were good. The Arduino was a test tool here, not the destination.

The transceiver hunt

For the body bus we tried several transceiver chips and boards. The common high-speed transceivers cannot work on fault-tolerant CAN. One ready-made CAN board even had its CAN-H and CAN-L terminals labelled the wrong way round. We also bought parts for CAN FD when we needed CAN FT: two letters apart, and completely different systems. Some chips could not even reach the speed we needed. Only a dedicated fault-tolerant transceiver works on the Iveco body bus. The rest are now a box of useless CAN chips.

Two faults that look the same

Even with the right transceiver, the body bus gave nothing. On the oscilloscope the receive line toggled perfectly. The CAN controller still saw no messages. There were two separate causes. First, the receive signal was inverted compared with what the ESP32 expects; we solved this by inverting it inside the chip. Second, on our own transceiver board, the receive signal never rose high enough for the ESP32 to read it as a logic one. A different pull-up resistor fixed it. The two faults look identical on the scope, which is why this took weeks.

Two dedicated boards

CAN now runs on two Waveshare ESP32-S3-ETH boards, one for each bus. The ESP32-S3 has a CAN controller that is proven in the field, and these boards have Ethernet built in. Each board listens to one bus and is its own Modbus TCP server. An earlier link between the two boards over an RS-485 cable has also been replaced by Ethernet.

The hardware

Two boards in one box

Both boards sit side by side in a 3D-printed enclosure, together with a small circuit board of our own that carries the CAN transceivers and the power supply regulators.

The enclosure has one small cooling fan. Each board measures the temperature of its own chip. The body-bus board reads the engine-bus board's temperature over the network, takes the higher of the two, and runs the fan at one of four speeds. Most of the time the fan is off and the box is silent.

Like the other ESP32 controllers, each board has its own diagnostic web page (Part 3), so we can see the bus traffic and the decoded values from any browser on the truck network.

We decided not to add a display or any other extra function to the CAN boards. Each one does one job only: listen to its bus and publish what it hears.

PHOTO TO COME
CAN enclosure, lid open
The two CAN boards and the transceiver board in their enclosure.
PHOTO TO COME
CAN diagnostic page
The diagnostic page of one of the CAN boards.
What it taught us

The difficult parts

Find out which kind of CAN you have

Before buying anything, find out which kind of CAN each bus uses. Classic high-speed CAN, CAN FD and fault-tolerant CAN need different transceivers, different wiring and have different resting voltages. Some modern systems (CAN FD) even change speed and message length in the middle of each message, so one correct setting does not mean you have understood the bus.

CAN FD is not CAN FT

Two letters, two completely different systems. CAN FD (Flexible Data-rate) is a newer, faster CAN that changes speed in the middle of each message. CAN FT (fault-tolerant) is the slow, robust bus in the Iveco body. We bought FD parts for an FT bus, and that money was lost. In this field, acronyms seem to be given out like long-service awards to the specialists. For the rest of us, every acronym is a possible trap. Check what each one means before you buy.

Check the logic voltage before you connect anything

This is the most important lesson on this page. Some CAN transceivers and shields work at 5 V, others at 3.3 V. The ESP32 is a 3.3 V chip, and 5 V on one of its pins can destroy it. Check the transceiver's supply and output voltage before you connect it. We lost a board this way, simply because an open 5 V wire touched it on the workbench.

Choose the hardware after you know the bus

Many CAN chips have a maximum speed, and many support only one kind of CAN. Find out the bus type and speed first, then choose the chips. Buy the other way round and you end up, as we did, with a box of CAN chips you cannot use.

A self-test proves very little

Ten out of ten in the chip's self-test meant only that the chip could hear itself. Only the real bus is a real test.

Read the board's pin map, not the chip's

A pin that exists on the chip may not exist on the board, or may already belong to the SD card or Ethernet. Most of our "broken" interfaces were wrong pins.

Measure at the processor pin

A signal that looks perfect on the scope can still be too weak for the processor to read as a logic one. Measure the voltage at the processor pin, not only at the transceiver.

Make "listen-only" true in hardware

A setting in software does not protect the bus while the processor is starting up. Put the transceiver into silent mode in the wiring.

Do not trust jumper wires

Single jumper connectors stretch with use and stop making good contact. Some are not even square inside: they work one way round and fail when turned through 90 degrees. Single wires also fall off. Every one of these faults looks like a software or chip problem, and each one cost us hours. Use multi-pin connectors wherever you can.

Know when to change the chip

When a part has been fighting you for months, it is often cheaper to change the part. Moving to a simpler, proven chip, with the right pins and the right transceiver, solved the problem.

Not finished

What comes next

Next: Part 5 describes the web dashboard and the server that connects it to the truck.

The series

How the truck thinks