Files
ESP32-S3-Touch-LCD-5B/wiki/pages/can-bus-integration.md
T
julian 974082cb3e Add diag console probe (OBD-II mode 01/09 on 0x7DF); wiki: diagnostic polling, two sources
Firmware:
- CANDriver::transmit(): the single sanctioned transmit path (single-shot,
  echoed as CANTX lines, TX_FAILED alert counted); CAN-task warnings now take
  the serial lock
- DiagProbe module: `diag pids` supported-PID bitmap scan, `diag pid <hex>`,
  `diag vin`, `diag ecu`, `diag status`; ISO-TP reassembly with flow control;
  one request in flight, refused for 3 s after any foreign tester frame
- Console dispatch chained via Tunables::setExtraCommandHandler()
- CLAUDE.md and docs/UART_PROTOCOL.md updated

Wiki:
- New page obd-diagnostic-polling (broadcast vs polled, 0x6F1->0x612 addressing,
  Route A generic OBD PID table, Route B, test-day procedure, firmware probe)
- New sources: google-ai-dde7m57-pids (clipping, unverified, 0x612 direction
  contradicted), dwr-335d-torque-pids (thread + raw/BMW 335d.csv decoded)
- Clippings/ folder added to the schema (Obsidian Web Clipper, treated as raw/)
- bmw-m57n-engine, can-bus-integration, open-questions, index, log updated
2026-09-21 19:51:49 +02:00

53 lines
4.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
type: concept
tags: [can-bus, reverse-engineering]
updated: 2026-07-16
---
# CAN Bus Integration
The core technical challenge of the project: reading real data from the [[bmw-m57n-engine]]'s CAN bus and mapping it into the display's data structure.
## Current firmware state (repo)
- ESP32-S3 TWAI peripheral, 500 kbps.
- Falls back to dummy simulated data when CAN is off or failing.
- **Raw frame logger (repo, added 2026-07-15):** every received frame is streamed over USB-CDC as `CANRAW,<ts_ms>,<id>,<extd>,<dlc>,<hex>`, serialized by a mutex so lines don't interleave. This is how [[can-capture-2026-07-15]] was taken — the board is now its own CAN sniffer. Logs are tethered-only (no onboard SD recording yet; the board has a microSD slot for a future "black box").
- Configured message map:
> [!warning] The firmware is NOT in LISTEN_ONLY mode — it ACKs the bus
> Despite older comments/docs saying "LISTEN_ONLY", the TWAI driver is installed in **`TWAI_MODE_NORMAL`** `(repo)` — a deliberate choice so it sends ACK bits and stops transmitters from flooding retries. Consequences: (1) the board is an **active bus participant**, not a passive sniffer — correct on a live multi-ECU bus, but do NOT power it in ACK mode on a bench with a single other node and no termination. (2) The onboard **TJA1051T/3 transceiver is non-isolated**, so its ground MUST be common with the vehicle (simplest: power the board from vehicle 12 V, whose negative *is* the reference). A flaky ground on an actively-ACKing node causes intermittent bus errors that look like data problems. → [[esp32-s3-touch-lcd-5b]]
| ID | Byte(s) | Mapped to |
|--------|---------|-----------|
| 0x4F | 0 | Coolant temp |
| 0x55 | 7 | Oil temp |
| 0x201 | 3 | Gearbox oil temp |
| 0x1001 | 0, 1 | Gear position / gear number |
| 0x101F | 0–1 | Battery voltage (16-bit BE) |
> [!warning] These IDs are almost certainly placeholders, not real BMW IDs.
> Two red flags: (1) `0x1001` and `0x101F` exceed `0x7FF`, the maximum for standard 11-bit CAN identifiers — BMW E-series PT-CAN of the M57N era uses 11-bit frames `(unverified)`, so these would never match. (2) None of the five IDs appear in community BMW reverse-engineering documentation. The map needs to be rebuilt from real bus captures or a trustworthy source before any of the displayed data can be believed.
> [!info] Research done 2026-07-15, then CONFIRMED live
> Web research produced a replacement candidate map — **0x1D0** (coolant + oil temp), **0x1D2** (gear), **0x0B5** (gearbox temp), **0x3B4** (battery voltage) — with confidence ratings and two layout disputes to settle on the bench. Full table and sources: [[can-id-candidates]]. The first live capture ([[can-capture-2026-07-15]]) confirmed all four IDs are present and resolved the 0x1D2 gear encoding. Fault codes are NOT passively broadcast (diagnostic requests required) — the `fault_codes` field needs a design decision.
## Verification plan
1. ~~Get a raw capture of the actual bus. File the log into `raw/`.~~ ✅ **Done** 2026-07-15 with the board's own logger → `raw/can-capture-2026-07-15-gearshift.csv`, summarized in [[can-capture-2026-07-15]]. **Still needed: a cold-start + confirmed-engine-running capture** to lock coolant/battery scaling (the first capture's engine state was unconfirmed and the battery/oil-temp bytes were dormant).
2. Identify candidate IDs by watching which bytes track known physical behavior (rev the engine, warm it up, shift gears). *In progress:* gear (0x1D2) done; coolant drift seen; RPM/battery pending. Use a **differential capture** for gear (hold each position, diff steady states) rather than a continuous sweep.
3. Cross-check against community DBC files / reverse-engineering wikis for the donor vehicle. ✅ done → [[can-id-candidates]].
4. Update `automotive_data.h` `(repo)` and mark each mapping `(verified)` here only after it matches reality on the live bus.
## Signal-source caveat
Coolant/oil temp come from the DDE, but **gearbox temp and gear position come from the EGS module** — they only exist on the bus if the swap retained the automatic transmission and its ECU. `(unverified)` → [[open-questions]]
## Transmit path `(repo, 2026-09-21)`
The firmware is no longer strictly read-only: `CANDriver::transmit()` exists, used only by the on-demand `diag` console probe (single-shot OBD-II requests on `0x7DF`, refused while a scan tool is polling). Nothing is sent without a typed command. Details and the test-day procedure → [[obd-diagnostic-polling]].
## Related
[[bmw-m57n-engine]] · [[esp32-s3-touch-lcd-5b]] · [[open-questions]]