--- type: concept tags: [link, uart, protocol, architecture] updated: 2026-09-21 --- # Controller Link (A → B) The system is two ESP32-S3 boards. Controller A (Waveshare ESP32-S3-Touch-LCD-5B, sibling repo) reads the BMW PT-CAN bus and owns all decoding; Controller B ([[esp32-s3-lcd-1-3]], this repo) is a **slave / extension**: it consumes a compact packet, displays it, and will drive the Patrol gauges from it ([[patrol-gauge-outputs]]). ``` BMW PT-CAN ──▶ Controller A (5B) ──UART 5 Hz──▶ Controller B (1.3) ╰── BLE (planned, redundant) ──╯ → [[link-redundancy]] ``` Architecture rule: **B never touches CAN.** Anything B needs must be put into the packet by A. See `(sibling: 5B wiki → dual-controller-architecture)` for A's view of the same link. ## Wire-level contract (repo, both repos' `include/protocol/automotive_data.h` and `docs/UART_PROTOCOL.md` (5B repo)) - 115200 8N1, 3.3 V TTL, one direction A → B, 5 Hz (every 200 ms) - Frame: `0xAA` · version `0x01` · length `0x12` · 18-byte payload · XOR checksum · `0x55` = **23 bytes** - Payload (little-endian): `packet_id` u8 · `timestamp_ms` u32 · `gear_position` u8 · `gearbox_oil_temp` i16 (0.1 °C) · `engine_oil_temp` i16 (0.1 °C) · `coolant_temp` i16 (0.1 °C) · `battery_voltage` u16 (0.01 V) · `fault_codes` u16 bitmap · `valid_flags` u8 · `debug_enabled` u8 - B declares the link **lost after 1000 ms** without a valid packet and shows a no-data state `(repo)`; A only transmits while its CAN task is running (CAN toggle ON → UART auto-starts) `(repo)` ### What each field actually carries today (sibling: 5B wiki → can-id-candidates) | Field | Source on A | Status | |---|---|---| | `coolant_temp` | CAN 0x1D0 byte 0, raw − 48 | verified live | | `gearbox_oil_temp` | CAN 0x0B5 byte 7, raw − 40 | verified live | | `engine_oil_temp` | CAN 0x1D0 byte 1 | **dead — sensor not fitted on this M57N, reads 0xFF**; B will never get a real value | | `gear_position` | CAN 0x1D2 lever/mode + 0x0BA target gear | verified live | | `battery_voltage` | CAN 0x3B4, 12-bit × 0.015 V | verified live | | `fault_codes` | A's own derived faults (bit 0 = lever vs gearbox mismatch), **not** DDE DTCs | `(repo)` | | RPM | **not in the packet** — A has it verified from CAN 0x0AA but the protocol has no field | needed by [[patrol-gauge-outputs]] | ## Pins - A transmits on **GPIO 44** (`uart_manager.cpp`, `UART_TX_PIN 44`) `(repo)`; RX 43 unused - B receives on **IO1** (left header, pin 4), TX IO2 unused `(repo)` > [!warning] Two docs said A transmits on GPIO 43 (both fixed or deleted 2026-09-21) > The 5B repo's root `CLAUDE.md` (corrected 2026-09-21) and this repo's former `.docs/UART_WIRING_GUIDE.md` (deleted 2026-09-21) both said "GPIO 43 TX". The 5B firmware and `docs/UART_PROTOCOL.md` (5B repo) say **44**. The code wins `(repo)`. > [!warning] GPIO 44 on the 5B is not a bare pin — it feeds an RS485 transceiver > On the 5B schematic, IO44 is the `RS485_TXD` net into an SP3485 with automatic direction control, and only the differential **A/B pair** reaches the terminal block `(sibling: 5B wiki → esp32-s3-touch-lcd-5b)`. Both wiring guides describe a direct "GPIO 44 → IO1 + GND" TTL wire, which the 5B does not physically expose. So either (a) the RS485 A line is being fed straight into B's TTL input and happens to work, (b) there is an RS485→TTL module on the B side that the docs don't mention, or (c) the wire is soldered to the module pin. **Which one is true is unknown** `(unverified)` and it decides how robust the wired link is in the car → [[open-questions]] #1, [[link-redundancy]]. ## Protocol drift between the two repos > [!warning] The `gear_position_t` enums differ `(repo, 2026-09-21)` > - **B's header** (matches `docs/UART_PROTOCOL.md` (5B repo)): 0 P · 1 R · 2 N · 3 D · **4 Sport · 5 Manual** · 6–13 M1–M8 · 14 Error > - **A's header** (rewritten during CAN decoding): 0 P · 1 R · 2 N · 3 D · **4–9 M1–M6** · 0xFF Unknown > > Same byte on the wire, different meanings: a value of 4 is "Sport" to B and "1st gear" to A. One side must be changed and `PACKET_VERSION` bumped. Which side is correct depends on what A's CAN parser actually emits now — check its `can_driver.cpp` before touching B. Also note A's protocol header now says all CAN IDs are 11-bit and the old placeholder map is dead; B's copy of the header still carries the placeholder CAN section. Harmless (B never parses CAN) but confusing — strip it when the enums are reconciled. ## Change discipline Any new signal (RPM first) means, in order: add the field and a `valid_flags` bit on A → bump `PACKET_VERSION` → copy the header to B → B rejects packets with an unexpected version → B's UI/gauge code consumes the field. The version byte exists precisely so a stale B fails loudly instead of misreading bytes. ## Related [[esp32-s3-lcd-1-3]] · [[link-redundancy]] · [[patrol-gauge-outputs]] · [[open-questions]]