Embedded HandbookApps
All sections › 0. About the handbook
STM32F103, STM32F407 · level intermediate · 6 min read
Open in the interactive handbook

0б. Topic routes: CAN and automotive diagnostics

Routes A, B, V and G from section 0 follow the parts of the handbook, and the beginner's route (0а) leads to a first device. The routes here are of another kind: you already have a task, and you need to go through all the sections of one topic in order, without collecting them from the table of contents.

The first such route is D: CAN and automotive diagnostics. The topic is spread widely across the handbook: the bus, the protocols on top of it, message description files, a test bench on the computer and five mini-projects. In order, it reads in ten steps — from a frame on the bus to your own unit that lives on the bus on an equal footing with the factory ones.

Prerequisites: section 0 — levels and boards (0.1, 0.2); if you are not yet comfortable with the microcontroller, first take the beginner's route (0а) or route A (0.3) up to UART and interrupts.

Terms used in the documentation

Term Meaning
learning path a route: sections in order for one task
silent mode (SILM) listen-only mode: the node does not acknowledge frames and does not send error frames
bus load the share of time the bus is occupied by frames
rest-bus simulation simulating the other units on the bus on a test bench

0б.1 How to follow a topic route

The rules are the same as for the beginner's route (0а.1): one step — one section, you take away the "What to take away" column from the section, and the subsections from "What to skip for now" are put off until the second pass.

A topic route has one rule of its own: the car is not the first test bench. The first six steps are done on the desk — two boards, or a board and a USB-CAN adapter, on a short piece of bus with two terminators. The device is connected to the car at the seventh step, and the first connections are in "listen-only" mode only (198с.2).

The route level is intermediate → advanced: the CAN bus (19), UDS (19д) and your own unit (198у) are advanced sections, the other seven are intermediate.


0б.2 Route D: CAN and automotive diagnostics

Route level: intermediate → advanced. Ten steps: the bus, decoding messages, the test bench, a first device, diagnostics in two layers and three devices for the car.

Step Section What to take away What to skip for now
1 19 the frame and arbitration, the transceiver and two 120 Ω terminators, a sample point around 87.5 %, a receive filter is mandatory; loopback mode works without a transceiver 19.7 errors and bus-off — at step 10
2 19е what DBC is: message, signal, factor and offset; Intel and Motorola byte order 19е.3–19е.5: the multiplexer, counters and CRC, the code generator — at steps 9 and 10
3 19ж a bench on the computer: a USB-CAN adapter, SocketCAN, candump and cansend — the computer becomes a node on the bus 19ж.2–19ж.3: how gs_usb works byte by byte
4 198е a first device: an SLCAN sniffer on the F103, listen-only mode, a ring buffer in the interrupt; why the strings go over UART rather than USB 198е.6 checking the core against the model
5 19в a long message on top of 8-byte frames: SF, FF, CF and FC flow control; timeouts 19в.4 addressing in the car and frame padding
6 19г OBD-II: the functional request 0x7DF and responses 0x7E8…0x7EF, response = service + 0x40, PIDs and formulas, trouble codes; a simulator on STM32 — no car needed yet 19г.5 ELM327
7 198р a scanner for the car: the connector and power through protection, a filter for eight response addresses, round-robin polling —
8 19д UDS: the same path, a different vocabulary — sessions and TesterPresent, data by DID, trouble codes, flashing through diagnostics on the F407 19д.5 seed and key — on the first reading the idea is enough
9 198с, 198т a dashboard — listen-only, a filter list and signals from the DBC; a logger — timestamps, a ring buffer and writing to a card one of the two — the other on a second pass
10 198у your own unit on the bus: a message in the DBC with a counter and CRC, your own trouble codes, bus-off, flashing over the bus —

Route D: ten steps in a zigzag — the bus, DBC, the bench, the sniffer, ISO-TP, OBD-II, the scanner, UDS, the dashboard or the logger, your own unit — and seven forks after it; the block colour is the level of the hardest section in it

The order rests on one thing: every next step uses the previous one. The sniffer (4) reads the bus decoded by the DBC (2) and is tested on the bench (3); OBD-II (6) rides on top of ISO-TP (5); UDS (8) rides on the same ISO-TP with the same way of responding and refusing; your own unit (10) puts it all together: the DBC, trouble codes, UDS and flashing over the bus.


0б.3 What you need on the desk


0б.4 Where next: forks after route D


0б.5 Pitfalls

Starting with the car. A node with the wrong bit rate on the car's bus does not stay silent: it sends error frames and disturbs the units. First the bench (step 3) and the simulator (19г.6); in the car, the first connections are in "listen-only" mode only (0б.1).

A single node on the bus. A frame without an acknowledgement is retransmitted endlessly — a lone node does not go bus-off but stays error-passive. For debugging without a second node there is loopback mode (19.7).

Waiting for reception without a filter. Without an explicitly configured filter, bxCAN receives nothing (19.5).

USB and CAN on the F103 at the same time. They share the same memory and are not available together (19.8) — that is why the sniffer sends its strings over UART (198е).

Confusing OBD-II and UDS. The road is the same — ISO-TP and the same way of responding and refusing — but the vocabulary differs: OBD-II is common to all cars, UDS is manufacturer-specific (19д.1).


0б.6 Summary


Next: section 0в "Topic routes: from prototype to product" — the second topic route: the path from a working prototype to a device that can be handed over to series production.

Open in the interactive handbook