Compare commits
4 Commits
37f98a241f
...
f7a2d1c3bd
| Author | SHA1 | Date | |
|---|---|---|---|
| f7a2d1c3bd | |||
| 662266e875 | |||
| 6770bf111b | |||
| 90862a573b |
+8
-4
@@ -9,8 +9,9 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
|
||||
|
||||
## Entities
|
||||
|
||||
- [[bmw-m57n-engine]] — the 3.0L BMW diesel whose CAN bus we read; DDE ECU, donor-vehicle unknown, candidate CAN IDs listed (all unverified)
|
||||
- [[esp32-s3-touch-lcd-5b]] — Waveshare 5" display board (Controller A); pinout, PSRAM/LCD gotchas, hardware open questions
|
||||
- [[bmw-m57n-engine]] — the 3.0L BMW diesel whose CAN bus we read; E60/E65 donor (confirmed), DDE ECU, auto box with EGS on bus
|
||||
- [[nissan-patrol-swap]] — the target vehicle: Patrol receiving the M57N + BMW auto; the tapped bus is a BMW island in a Nissan
|
||||
- [[esp32-s3-touch-lcd-5b]] — Waveshare 5" display board (Controller A); onboard TJA1051 CAN transceiver, 7–36 V input, pinout, PSRAM/LCD gotchas
|
||||
|
||||
## Concepts
|
||||
|
||||
@@ -19,8 +20,11 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
|
||||
|
||||
## Synthesis
|
||||
|
||||
- [[open-questions]] — the research frontier: real CAN IDs, donor vehicle, EGS presence, transceiver, power, fault codes
|
||||
- [[can-id-candidates]] — **the E60/E65 CAN ID map from web research**: 0x1D0/0x1D2/0x0B5/0x3B4 with confidence ratings, layout disputes, sources; fault codes not passively broadcast
|
||||
- [[open-questions]] — the research frontier: bench-verify the candidate IDs, operating temp, transient protection, fault-code design decision
|
||||
|
||||
## Sources
|
||||
|
||||
*(none ingested yet — `raw/ESP32-S3-Touch-LCD-5B.md` exists but is empty; re-clip needed)*
|
||||
- [[esp32-s3-touch-lcd-5b-waveshare-wiki]] — official Waveshare product wiki (ingested 2026-07-15); answered CAN-transceiver and power questions, raised the 0–65 °C operating-temp concern
|
||||
- [[e60-vfl-can-codes-xlsx]] — community E60 pre-facelift CAN table (ingested 2026-07-15); E60-specific confirmation of 0x1D0/0x3B4, new 0x304 gear-lever candidate
|
||||
- [[listen-and-send-pid-arduino]] — Arduino ELM327→E46-cluster sketch (ingested 2026-07-15); technique reference for a diagnostic-request fallback, not ID evidence
|
||||
|
||||
+16
@@ -5,3 +5,19 @@ Append-only. `grep "^## \[" log.md | tail -5` for recent activity.
|
||||
## [2026-07-15] setup | Wiki instantiated
|
||||
|
||||
Created schema (`CLAUDE.md`), `index.md`, `log.md`, and five seed pages built from repo knowledge: [[bmw-m57n-engine]], [[esp32-s3-touch-lcd-5b]], [[can-bus-integration]], [[dual-controller-architecture]], [[open-questions]]. Deleted Obsidian's default `Welcome.md`. Flagged: the firmware's CAN ID map looks like placeholders (two IDs exceed 11-bit range); `raw/ESP32-S3-Touch-LCD-5B.md` is an empty clip and needs re-clipping.
|
||||
|
||||
## [2026-07-15] ingest | Waveshare ESP32-S3-Touch-LCD-5 product wiki
|
||||
|
||||
Re-clipped `raw/ESP32-S3-Touch-LCD-5B.md` ingested → [[esp32-s3-touch-lcd-5b-waveshare-wiki]]. Answered two open questions: CAN transceiver is onboard (TJA1051T/3/1J, terminal block, 120 Ω termination switch off by default) and power is solved by the 7–36 V DC wide input (vehicle 12 V direct). New concern raised: operating temp spec is 0–65 °C, marginal for automotive. Updated [[esp32-s3-touch-lcd-5b]] and [[open-questions]]; added schematic PDF to sourcing wishlist.
|
||||
|
||||
## [2026-07-15] ingest | E60 VFL CAN codes spreadsheet + Listen_and_send_PID Arduino sketch
|
||||
|
||||
Two raw sources ingested. (1) `E60 VFL CAN-Bus Codes.xlsx` (community table, ~130 ID blocks from a real pre-facelift E60) → [[e60-vfl-can-codes-xlsx]]: independently confirms 0x1D0 coolant raw−48 (0x7A→74 °C) and 0x3B4 battery voltage (leaning 12-bit LE layout, factor ≈0.0147–0.015), adds 0x304 as a 2-byte gear-lever candidate (P=E3/R=C2/N=D1/M=C9, D value suspect), engine-running flag in 0x3B4 byte 3; contains no oil-temp or gearbox-temp rows. (2) `Listen_and_send_PID_009c` (Arduino MCP2515+ELM327, 2013) → [[listen-and-send-pid-arduino]]: transmits E46 cluster frames from OBD PID polling — filed as technique reference for a future diagnostic-request mode; no map changes. [[can-id-candidates]] updated: coolant now "very high" confidence; oil/gearbox temps flagged as weakest signals.
|
||||
|
||||
## [2026-07-15] query | Deep research: E60/E65 CAN IDs for M57N + ZF EGS
|
||||
|
||||
Deep-research workflow ran (interrupted twice by session task-loss on Windows; ~82 agents total, 95 claims, 30 adversarial verifications completed; synthesis done manually from the journal). Result: [[can-id-candidates]] — coolant/oil temp on **0x1D0** (raw−48, DDE, 100 ms; confirmed live on a real E60), gear on **0x1D2** (EGS, 200 ms, two generation dialects that likely reconcile), gearbox oil temp on **0x0B5** byte 7 (offset disputed 0 vs +40 — bench-critical), battery voltage on **0x3B4** (layout disputed 12-bit×0.015 vs 24-bit×0.001). Fault codes are NOT passively broadcast — require 0x6F1/0x612 diagnostic requests; firmware `fault_codes` field needs a design decision. Firmware's placeholder IDs contradicted by every source. Updated [[can-bus-integration]]; index updated. Cost note: bulk of tokens spent in the initial (pre-interruption) run; resumes replayed from cache.
|
||||
|
||||
## [2026-07-15] update | Donor and target vehicle confirmed by user
|
||||
|
||||
User confirmed: donor chassis is **E60/E65 (2003+)**, transmission is a **BMW auto with EGS on the CAN bus**, target vehicle is a **Nissan Patrol**. Created [[nissan-patrol-swap]]; updated [[bmw-m57n-engine]] (E46-era candidate IDs flagged as probably wrong generation) and [[open-questions]] (three questions moved to Answered). Next: web research for E60-generation PT-CAN broadcast IDs.
|
||||
|
||||
@@ -6,14 +6,18 @@ updated: 2026-07-15
|
||||
|
||||
# BMW M57N Engine
|
||||
|
||||
The target engine for this project: the display reads its CAN bus and shows live data. Everything below is `(unverified)` LLM prior knowledge until backed by an ingested source or real-world testing — treat as a starting map, not gospel.
|
||||
The engine at the heart of the project: the display reads its CAN bus and shows live data. Being swapped into a Nissan Patrol → [[nissan-patrol-swap]].
|
||||
|
||||
## This specific engine (verified — user, 2026-07-15)
|
||||
|
||||
- Donor chassis: **E60/E65 (2003+)** — so a DDE5/DDE6-generation ECU, exact variant TBD.
|
||||
- Transmission: **BMW automatic with its EGS ECU wired into the CAN bus** — gearbox temp and gear position have a real data source. Likely a ZF 6HP-family box with GS19-era EGS `(unverified)`.
|
||||
|
||||
## Overview (unverified)
|
||||
|
||||
- 3.0 L inline-6 turbo-diesel, second generation ("N" = updated) of the M57 family, produced roughly 2002–2008.
|
||||
- Fitted to E46 330d, E39/E60 530d, E53 X5 3.0d, E65 730d, Range Rover L322 (as Td6), among others.
|
||||
- Engine management: Bosch **DDE** (Digitale Diesel Elektronik) — DDE5/DDE6 era depending on year.
|
||||
- The DDE broadcasts engine data on the vehicle's **PT-CAN at 500 kbps**, which matches the firmware's configured baud rate `(repo)`.
|
||||
- Engine management: Bosch **DDE** (Digitale Diesel Elektronik).
|
||||
- The DDE broadcasts engine data on the vehicle's **PT-CAN at 500 kbps**, which matches the firmware's configured baud rate `(repo)`. E60/E65 also carry a K-CAN (~100 kbps) for body functions — we care about PT-CAN only `(unverified)`.
|
||||
|
||||
## Data we want from it
|
||||
|
||||
@@ -21,22 +25,14 @@ Per the project goals: coolant temperature, oil temperature, gearbox oil tempera
|
||||
|
||||
## Key unknowns
|
||||
|
||||
- Which donor vehicle / which DDE version this specific engine came from — this determines the exact CAN matrix. → [[open-questions]]
|
||||
- Whether gearbox data is available at all: gearbox temperature and gear position come from the **transmission ECU (EGS)**, not the DDE. If the swap kept only the engine + DDE, those messages may not exist on the bus. `(unverified)` → [[open-questions]]
|
||||
- Whether a standalone/swap harness alters what's broadcast.
|
||||
- Exact DDE version and donor model year — narrows the CAN matrix further. → [[open-questions]]
|
||||
- Whether the swap harness alters what's broadcast vs. a stock E60.
|
||||
|
||||
## Candidate CAN IDs to verify (unverified — E46/E39-era BMW, widely reported in reverse-engineering communities)
|
||||
|
||||
| ID | Reported content |
|
||||
|------|------------------|
|
||||
| 0x316 | Engine RPM, key status |
|
||||
| 0x329 | Coolant temp, throttle/pedal position |
|
||||
| 0x545 | Check-engine / warning lights, oil temp (some models) |
|
||||
| 0x43F / 0x43B | EGS gear data (model-dependent) |
|
||||
## CAN IDs
|
||||
|
||||
> [!warning]
|
||||
> These do NOT match the IDs currently in the firmware (`0x4F`, `0x55`, `0x201`, `0x1001`, `0x101F` `(repo)`). See [[can-bus-integration]] for why the firmware IDs look like placeholders.
|
||||
> The candidate IDs originally seeded here (`0x316`, `0x329`, `0x545`) are from **E46/E39-generation** documentation and probably do NOT apply — the donor is E60/E65, a newer bus generation with a different matrix. E60-specific research is tracked in [[can-bus-integration]]. The firmware's current IDs (`0x4F`, `0x55`, `0x201`, `0x1001`, `0x101F` `(repo)`) remain placeholder-quality either way.
|
||||
|
||||
## Related
|
||||
|
||||
[[can-bus-integration]] · [[dual-controller-architecture]] · [[open-questions]]
|
||||
[[nissan-patrol-swap]] · [[can-bus-integration]] · [[dual-controller-architecture]] · [[open-questions]]
|
||||
|
||||
@@ -25,6 +25,9 @@ The core technical challenge of the project: reading real data from the [[bmw-m5
|
||||
> [!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
|
||||
> 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]]. 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 (candump / Savvy CAN / cheap USB-CAN dongle) with the engine running. File the log into `raw/`.
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
---
|
||||
type: synthesis
|
||||
tags: [can-bus, reverse-engineering, e60, research]
|
||||
updated: 2026-07-15
|
||||
---
|
||||
|
||||
# E60/E65 CAN ID Candidates (Research Results)
|
||||
|
||||
Findings from the 2026-07-15 deep-research run (95 claims extracted from ~15 sources, 30 adversarially verified against primary repos before the run was interrupted; synthesis done manually from the journal). These are the IDs to program into the firmware **for bench testing against a live capture** — none are `(verified)` until seen on the actual swap's bus.
|
||||
|
||||
## The map (replaces the firmware's placeholder IDs)
|
||||
|
||||
| Signal | CAN ID | Bytes | Scaling | Sender | Rate | Confidence |
|
||||
|--------|--------|-------|---------|--------|------|------------|
|
||||
| Coolant temp | **0x1D0** | byte 0 | °C = raw − 48 | DME/DDE | 100 ms | **Very high** — verified verbatim in E65 docs, present in E90-gen DBC, confirmed live on a real E60 545i, E60 tool32 table lists 0x1D0 "Motordaten" from DDE1 (diesel!), and the [[e60-vfl-can-codes-xlsx]] sheet shows 0x7A→74 °C on a real E60 VFL (raw−48 checks out) |
|
||||
| Engine oil temp | **0x1D0** | byte 1 | °C = raw − 48 | DME/DDE | 100 ms | **High** — same sources as coolant |
|
||||
| Gearbox oil temp | **0x0B5** ("Torque_request_EGS") | byte 7 | ⚠ disputed: raw + 0 vs raw + 40 | EGS | ? | **Medium** — in the E9x community DBC; absent from the E65 repo's decoded EGS messages. Offset must be settled on the bench (a ~40 °C error is dangerous — resolve before trusting) |
|
||||
| Gear lever position | **0x1D2** ("TransmissionDataDisplay") | byte 0 | ⚠ two encodings, see below | EGS | 200 ms | **High that the ID is right**, medium on layout |
|
||||
| Current gear number | **0x1D2** byte 1 upper nibble (GearAct, −4 offset) or **0x0BA** bits 0–3 (E65: values P/R/N…6th) | | | EGS | 20–200 ms | **Medium** — two candidate messages; also **0x304** "Gear lever" — the E60 VFL sheet shows a 2-byte lever message: P=0xE3, R=0xC2, N=0xD1, M=0xC9 (its D=0xC2 duplicates R — likely a sheet typo) |
|
||||
| Battery voltage | **0x3B4** ("Powermanagement Batteriespannung") | ⚠ disputed layout | 12-bit LE × 0.015 V (E65, verified: 0x3D9→14.775 V) vs 24-bit BE × 0.001 V (E90 DBC) | Power module / DDE | 5 s (E65) | **High on ID** (E60 tool32 table + E60 VFL sheet: `64 F3`→12.76 V, consistent with the 12-bit LE layout though implying factor ≈0.0147 vs 0.015). Bonus from the sheet: byte 3 = engine running flag (0x09 on / 0x00 off) |
|
||||
| Engine RPM (bonus) | **0x0AA** | bytes 4–5 | RPM = raw / 4 | DME/DDE | 10 ms | High — cross-generation (E65 + E90 comment) |
|
||||
| Ignition/terminal status (bonus) | **0x130** | byte 0 bitmasks | 0xD5/0xC5/0xC1 | CAS | 100 ms | Medium — used by an M57 project as its only passive decode |
|
||||
|
||||
### The 0x1D2 encoding dispute (must resolve on bench)
|
||||
|
||||
- **E90-generation DBC**: low nibble of byte 0 = 1=P, 2=R, 4=N, 8=D (bitmask style, XOR-inverted copy in high nibble); 2-bit ShiftLeverMode at bit 32 (0=Normal, 1=Sport, 2=Manual). DLC 6.
|
||||
- **E65 live capture** (damienmaguire, verified against code): whole byte 0 = 0xE1=P, 0xD2=R, 0xB4=N, 0x78=D; byte 3 is a rolling counter 0x0D→0xED in steps of 0x10. DLC **5**.
|
||||
- Same ID, different generation dialects — the E60 could speak either. Note the E65 byte-0 values are consistent with the E90 nibble scheme (0xE1 low nibble = 1 = P, 0xD2 → 2 = R, 0xB4 → 4 = N, 0x78 → 8 = D, high nibble = XOR-inverted copy!) — so the two sources may actually agree and the "dispute" is notation. Bench capture decides.
|
||||
|
||||
## Field checklist for the live capture session
|
||||
|
||||
Setup: 500 kbps, listen-only, board's 120 Ω termination switch **OFF**, tap CAN-H/CAN-L on the PT-CAN. **Log everything raw for the whole session** and save the dump into `wiki/raw/` — even IDs we don't care about yet.
|
||||
|
||||
| Test | Watch | Confirms |
|
||||
|------|-------|----------|
|
||||
| Ignition on, engine off | `0x130` byte 0 changes per key position; `0x3B4` appears (~every 5 s) | Terminal status; battery message alive |
|
||||
| Compare `0x3B4` to a multimeter at the battery | Try 12-bit LE ×0.015 and ×0.0147 vs meter (engine off ≈12.4 V, running ≈14+ V); check byte 3 flips 0x00→0x09 on start | Battery layout + factor; engine-running flag |
|
||||
| Cold start, note ambient temp | `0x1D0` byte 0 ≈ ambient+48 raw, then climbs steadily to ~90 °C (raw ~0x8A) | Coolant ID + −48 scaling |
|
||||
| Same, byte 1 | Should ALSO start near ambient but climb **slower** than byte 0 and lag behind | Oil temp really is byte 1 (weakest engine signal) |
|
||||
| Cold start | `0x0B5` byte 7: if raw ≈ ambient → offset 0; if raw ≈ ambient+40… i.e. reads 40 under ambient with offset 0 assumed → offset +40 | Gearbox temp offset dispute (cold start makes the two hypotheses ~40 apart — unmistakable) |
|
||||
| Hold brake, shift P→R→N→D→(S/M) slowly | `0x1D2` byte 0 (note DLC: 5 vs 6!); `0x304` bytes; `0x0BA` bits 0–3 | Gear lever encoding + which message to use; settles the D=R typo in the E60 sheet |
|
||||
| Drive: let the box shift 1→2→3… | `0x1D2` byte 1 upper nibble, `0x0BA` low nibble increments per shift | Current gear number source |
|
||||
| Blip throttle | `0x0AA` bytes 4–5 = RPM×4 | RPM sanity check (fast cross-check that you're on the right bus) |
|
||||
|
||||
If an expected ID is absent entirely, note it — it means the swap harness dropped that module's traffic, which is itself an answer ([[open-questions]] #3).
|
||||
|
||||
## Fault codes: passive reading is NOT possible ⚠
|
||||
|
||||
Consistent across sources: **no DTC/fault-code broadcast exists**. The `dieslg8` project (M57 diesel, later EDC17 DDE) gets coolant temp and DTCs only via **active diagnostic requests** (send on 0x6F1, parse responses on 0x612; e.g. coolant = raw×0.01 − 100). At most, a **MIL/check-engine lamp status bit** may be passively derivable (a commercial Patrol-swap CAN module offers a check-engine output). Consequences for the firmware `(repo)`:
|
||||
|
||||
- The `fault_codes` field in `automotive_data_t` cannot be filled in LISTEN_ONLY mode.
|
||||
- Options: (a) drop the field, (b) show MIL lamp status only, (c) leave LISTEN_ONLY and accept it empty, or (d) later add a diagnostic-request mode (means transmitting on the bus — design decision).
|
||||
|
||||
## Swap-context validation
|
||||
|
||||
A commercial module exists specifically for **BMW M57/N57 swaps into Nissan Patrols/Landcruisers** that derives tach, check-engine lamp, reverse trigger (from the ZF EGS via CAN — the box has no reverse wire), and fan trigger from the engine CAN. Proof that passive listening on exactly this drivetrain-in-a-Patrol works. → [[nissan-patrol-swap]]
|
||||
|
||||
Also useful: an E60 forum claim `(unverified)` that arbitration IDs are identical across E60 K-CAN and PT-CAN (PT-CAN just broadcasts faster, ~10 ms vs ~100 ms) — meaning E90 K-CAN DBC findings likely transfer to our 500 kbps PT-CAN tap.
|
||||
|
||||
## Sources
|
||||
|
||||
- [[e60-vfl-can-codes-xlsx]] — **E60 VFL community spreadsheet (ingested)**: E60-specific confirmation of 0x1D0 (−48 scaling), 0x3B4, 0x1D2 DLC 6; adds 0x304 gear lever; contains NO oil-temp or gearbox-temp rows
|
||||
- [[listen-and-send-pid-arduino]] — technique reference (ingested): ELM327 PID-request pattern for the fault-code fallback; E46 cluster frames, not E60 evidence
|
||||
- `HeinrichG-V12/E65_ReverseEngineering` (GitHub) — E65 760Li PT-CAN, docs verified verbatim by the adversarial pass (0x1D0, 0x3B4, 0x192, 0x1D2, 0x0BA, 0x1A2)
|
||||
- `damienmaguire/BMW-E65-CANBUS` (GitHub) — live E65 735i captures + working EGS emulator code (0x1D2 encoding, 0x192, 0x0AA)
|
||||
- `TimesNewRomanZ/e60-canbus` (GitHub, community `bmw_e9x_e8x.dbc`) — author runs a real E60 545i; 0x1D0 confirmed live on E60
|
||||
- `kmalinich/dieslg8` (GitHub) — M57 diesel (E90 335d, EDC17): diagnostic-request-only coolant/DTC evidence
|
||||
- loopybunny E90 K-CAN DBC — 0x1D0/0x1D2/0x3B4 E90 layouts
|
||||
- E60 forum thread with tool32/EDIABAS-derived ID table — confirms 0x1D0/0x1D2/0x304/0x3B4 exist on E60 with DDE1 as sender
|
||||
- Commercial M57/N57 Patrol-swap CAN module product page — swap-context feasibility
|
||||
|
||||
## Caveats
|
||||
|
||||
- No source used an actual **E60 M57N diesel** end-to-end; the closest anchors are the E60 tool32 table (lists DDE1 as sender for 0x1D0/0x3B4), the E60 VFL spreadsheet (real pre-facelift E60, engine variant unknown), and the M57 dieslg8 project (different chassis generation). Engine-side layouts are inferred from petrol DME captures of the same bus generation.
|
||||
- **Oil temp and gearbox oil temp remain the weakest signals** — absent from both E60-specific sources; only the E9x DBC and E65 docs place oil temp at 0x1D0 byte 1, and only the E9x DBC has gearbox temp (0x0B5 byte 7, offset disputed).
|
||||
- Firmware's current IDs (`0x4F`, `0x55`, `0x201`, `0x1001`, `0x101F`) are contradicted by every source — confirmed placeholders. → [[can-bus-integration]]
|
||||
- Promotion to `(verified)` requires a live capture from the swap's bus: warm the engine and watch 0x1D0 byte 0 climb, shift through P/R/N/D and watch 0x1D2.
|
||||
|
||||
## Related
|
||||
|
||||
[[can-bus-integration]] · [[bmw-m57n-engine]] · [[nissan-patrol-swap]] · [[open-questions]]
|
||||
@@ -6,36 +6,51 @@ updated: 2026-07-15
|
||||
|
||||
# Waveshare ESP32-S3-Touch-LCD-5B
|
||||
|
||||
Controller A of the [[dual-controller-architecture]] — the main in-cabin display.
|
||||
Controller A of the [[dual-controller-architecture]] — the main in-cabin display. SKU 28151, the 1024×600 capacitive-touch variant of the LCD-5 family. Primary reference: [[esp32-s3-touch-lcd-5b-waveshare-wiki]].
|
||||
|
||||
> [!note]
|
||||
> The raw source `raw/ESP32-S3-Touch-LCD-5B.md` (presumably a clip of the Waveshare product page) is currently **empty** — re-clip it and ingest to flesh this page out with official specs.
|
||||
## Specs (source: waveshare-wiki)
|
||||
|
||||
## Specs (repo)
|
||||
- ESP32-S3-WROOM-1-N16R8 module: dual-core LX7 @ 240 MHz, 16 MB flash, 8 MB OPI PSRAM
|
||||
- 5" IPS 1024×600, 65K colors (16-bit), 550 cd/m², GT911 5-point capacitive touch, tempered glass
|
||||
- 2.4 GHz Wi-Fi + BLE 5, onboard antenna (keep metal away from antenna area)
|
||||
- Runs LVGL 8.4.0 at ~50 FPS via ESP32_Display_Panel v1.0.4 `(repo)`
|
||||
|
||||
- ESP32-S3 dual-core @ 240 MHz, 16 MB flash, 8 MB **OPI** PSRAM
|
||||
- 5-inch 1024×600 RGB LCD (RGB888 parallel interface), capacitive touch
|
||||
- Runs LVGL 8.4.0 at ~50 FPS via ESP32_Display_Panel v1.0.4
|
||||
## Power (source: waveshare-wiki)
|
||||
|
||||
## Pin usage in this project (repo)
|
||||
- **7–36 V DC wide-input terminal** — vehicle 12 V feeds it directly, no external regulator needed. ✅ resolves most of the power question
|
||||
- Alternative inputs: USB Type-C 5 V; optional single-cell 3.7 V LiPo (CS8501 charge/boost, 580 mA)
|
||||
- Draw: ~450 mA @ 5 V (~2.3 W)
|
||||
- Remaining caveat: automotive transient/load-dump spikes (ISO 7637) can exceed 36 V `(unverified)` → [[open-questions]]
|
||||
|
||||
| Function | Pins | Notes |
|
||||
|----------|------|-------|
|
||||
| CAN (TWAI) | GPIO 15 TX / GPIO 16 RX | 500 kbps, LISTEN_ONLY; external transceiver required — which one? → [[open-questions]] |
|
||||
| UART1 → Controller B | GPIO 43 TX / GPIO 44 RX | 115200 baud, exposed on the board's RS485 terminal block |
|
||||
| USB Serial | UART0 | debug @ 115200 |
|
||||
> [!warning] Operating temperature 0–65 °C (source: waveshare-wiki)
|
||||
> Tight for a car: sub-zero winters and sun-baked dashboards both fall outside spec. → [[open-questions]]
|
||||
|
||||
## Hard-won hardware lessons (repo)
|
||||
## CAN interface (source: waveshare-wiki)
|
||||
|
||||
- **Onboard TJA1051T/3/1J transceiver**, CAN 2.0, on a 3.5 mm terminal block — wire CAN-H/L straight in. ✅ resolves the transceiver question
|
||||
- **120 Ω termination switch, OFF by default — leave it off** when tapping an existing vehicle bus (the bus is already terminated at both ends).
|
||||
- Firmware drives it via TWAI on GPIO 15 TX / 16 RX, 500 kbps, LISTEN_ONLY `(repo)`.
|
||||
|
||||
## Other interfaces
|
||||
|
||||
| Interface | Details |
|
||||
|-----------|---------|
|
||||
| RS485 | SP3485, auto TX/RX direction; terminal block used for UART1 → Controller B, GPIO 43/44, 115200 baud `(repo)` |
|
||||
| Isolated I/O | Optocoupler digital in 5–36 V (dry/wet contact), open-drain out sinking 450 mA/ch — could read ignition-on or drive a relay later |
|
||||
| I2C | External header; CH422G expander occupies 0x20–0x27 & 0x30–0x3F, GT911 touch at 0x5D — avoid these addresses |
|
||||
| RTC | PCF85063 + CR927 coin cell |
|
||||
| TF card | SD_CS driven via CH422G EXIO4 |
|
||||
| USB Serial | UART0, debug @ 115200 `(repo)` |
|
||||
|
||||
Note: the screen occupies most GPIOs; auxiliary functions (backlight, reset, SD_CS) route through the CH422G IO expander — spare native GPIOs are scarce.
|
||||
|
||||
## Hard-won firmware lessons (repo)
|
||||
|
||||
- 8MB OPI PSRAM demands `qio_opi` memory type + custom board JSON — wrong setting causes screen flicker/drift.
|
||||
- LCD wants a 16 MHz pixel clock with correct PCLK polarity.
|
||||
- Backlight must be manually sequenced at boot to avoid a white flash.
|
||||
|
||||
## Open hardware questions
|
||||
|
||||
- Automotive power: the board wants 5 V; a vehicle supplies 9–16 V with load-dump transients. What regulator/protection is planned? → [[open-questions]]
|
||||
- CAN transceiver part and wiring (the TWAI peripheral is only the controller — GPIO 15/16 are logic-level).
|
||||
- Flashing: use the Type-C port labeled UART; hold BOOT while connecting if the port isn't recognized (source: waveshare-wiki).
|
||||
|
||||
## Related
|
||||
|
||||
[[dual-controller-architecture]] · [[can-bus-integration]]
|
||||
[[dual-controller-architecture]] · [[can-bus-integration]] · [[esp32-s3-touch-lcd-5b-waveshare-wiki]]
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
type: entity
|
||||
tags: [vehicle, swap, project-context]
|
||||
updated: 2026-07-15
|
||||
---
|
||||
|
||||
# Nissan Patrol M57N Swap
|
||||
|
||||
The target vehicle (verified — user, 2026-07-15): a **Nissan Patrol** receiving the [[bmw-m57n-engine]] from an E60/E65 donor, with the BMW automatic + EGS wired into the CAN bus. The display system ([[dual-controller-architecture]]) replaces/augments instrumentation for the swapped drivetrain.
|
||||
|
||||
## Why this matters for research
|
||||
|
||||
- The M57-into-Patrol swap is popular (especially in Australia and the Middle East), so swap-community forums likely contain solved CAN-ID lists and gauge projects for exactly this drivetrain. `(unverified)` → [[can-bus-integration]]
|
||||
- The bus the display taps is essentially a **BMW island in a Nissan vehicle**: only the modules the swap harness retains (DDE, EGS, possibly others) are broadcasting. Nissan-side electronics are not on this bus.
|
||||
- Patrol generation, swap-harness maker (or DIY), and which BMW modules were retained are still unknown → [[open-questions]].
|
||||
|
||||
## Related
|
||||
|
||||
[[bmw-m57n-engine]] · [[can-bus-integration]] · [[open-questions]]
|
||||
@@ -10,23 +10,31 @@ The research frontier. Answering any of these should trigger updates across the
|
||||
|
||||
## Blocking
|
||||
|
||||
1. **What are the real CAN IDs for the M57N data we want?** The firmware's current map is placeholder-quality — two IDs aren't even valid 11-bit identifiers. Needs a live bus capture or a trusted source. → [[can-bus-integration]]
|
||||
2. **Which donor vehicle / DDE version is this engine from?** (E46? E39? E53? Range Rover Td6?) The CAN matrix differs per platform. → [[bmw-m57n-engine]]
|
||||
3. **Is the transmission ECU (EGS) on the bus?** Gearbox temp and gear position come from the EGS, not the engine ECU. If this is a manual swap or the EGS was removed, those two display fields have no data source. → [[can-bus-integration]]
|
||||
1. **What are the real CAN IDs for the E60/E65-generation M57N data we want?** The firmware's current map is placeholder-quality — two IDs aren't even valid 11-bit identifiers. Needs web research (in progress 2026-07-15) + a live bus capture to verify. → [[can-bus-integration]]
|
||||
|
||||
## Project context
|
||||
|
||||
4. **What vehicle is the engine going into?** The parent directory is named `bmw-patrol` — is this an M57N swap into a Nissan Patrol (a well-known diesel swap)? This shapes wiring, power, and what other bus traffic exists. `(unverified guess)`
|
||||
5. **Standalone harness or full donor loom?** Affects which modules broadcast.
|
||||
2. **Exact donor model year / DDE version and EGS variant?** Chassis generation is known (E60/E65); the precise ECU versions would narrow the matrix further. → [[bmw-m57n-engine]]
|
||||
3. **Standalone harness or full donor loom? Which BMW modules were retained?** Affects which modules broadcast on the swap's bus. → [[nissan-patrol-swap]]
|
||||
4. **Which Patrol generation, and how is the display being mounted/powered?** → [[nissan-patrol-swap]]
|
||||
|
||||
## Hardware
|
||||
|
||||
6. **CAN transceiver**: which part (SN65HVD230? TJA1050?) and how is it wired to GPIO 15/16? → [[esp32-s3-touch-lcd-5b]]
|
||||
7. **Automotive power supply**: 12 V vehicle → 5 V board conversion, transient/load-dump protection, ignition-switched vs constant power.
|
||||
8. **Fault codes**: the UART packet reserves a field for fault codes — DDE fault codes are read via diagnostic protocols (KWP2000/UDS over K-line or CAN), not passively broadcast. Is passive reading even possible? `(unverified)`
|
||||
5. **Operating temperature 0–65 °C** (source: waveshare-wiki) — outside automotive norms at both ends (sub-zero winter cabins, sun-baked dashboards). Is the mounting location temperature-controlled enough? Any mitigation (mounting away from vents/sun, accepting reduced lifespan)?
|
||||
6. **Transient protection on the 7–36 V input**: the board takes vehicle 12 V directly, but ISO 7637 load-dump spikes can exceed 36 V `(unverified)`. Consider an upstream TVS diode / automotive-rated buck. Also: ignition-switched vs constant power (the isolated digital input could sense ignition).
|
||||
7. **Fault codes**: the UART packet reserves a field for fault codes — DDE fault codes are read via diagnostic protocols (KWP2000/UDS over K-line or CAN), not passively broadcast. Is passive reading even possible? `(unverified)`
|
||||
|
||||
## Answered
|
||||
|
||||
- ~~Which donor vehicle?~~ → **E60/E65 (2003+)** (verified — user, 2026-07-15) → [[bmw-m57n-engine]]
|
||||
- ~~Is the EGS on the bus?~~ → **Yes — BMW auto with EGS wired in**; gearbox temp and gear position have a real source. (verified — user, 2026-07-15)
|
||||
- ~~Is the target a Nissan Patrol?~~ → **Yes.** (verified — user, 2026-07-15) → [[nissan-patrol-swap]]
|
||||
- ~~CAN transceiver?~~ → **Onboard TJA1051T/3/1J** on a terminal block; leave the 120 Ω termination switch OFF when tapping the vehicle bus. (source: waveshare-wiki, 2026-07-15) → [[esp32-s3-touch-lcd-5b]]
|
||||
- ~~12 V → 5 V power conversion?~~ → **Not needed**: board has a 7–36 V DC wide input. Residual transient concern moved to #6. (source: waveshare-wiki, 2026-07-15)
|
||||
|
||||
## Sourcing wishlist
|
||||
|
||||
- Waveshare ESP32-S3-Touch-LCD-5B product page + schematic (the current raw clip is empty — re-clip it)
|
||||
- ~~Waveshare product page~~ ✅ ingested → [[esp32-s3-touch-lcd-5b-waveshare-wiki]]
|
||||
- Waveshare **schematic PDF** (linked from the product page: `ESP32-S3-Touch-LCD-5-Sch.pdf`) — would confirm CAN GPIO routing and power path
|
||||
- A community DBC / CAN-ID list for the donor platform
|
||||
- A real candump log from the engine running
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,60 @@
|
||||
//OBDII ****************************************
|
||||
#define ENGINE_COOLANT_TEMP 0x05
|
||||
#define ENGINE_RPM 0x0C
|
||||
#define VEHICLE_SPEED 0x0D
|
||||
#define MAF_SENSOR 0x10
|
||||
#define O2_VOLTAGE 0x14
|
||||
#define THROTTLE 0x11
|
||||
#define MIL_CODE 0x01
|
||||
#define Engine_fuel_rate 0x5E // ((A*256)+B)*0.05 in L/h. Does not work on E46 or LS1
|
||||
|
||||
#define PID_REQUEST 0x7DF
|
||||
#define PID_REPLY 0x7E8
|
||||
|
||||
// initialization commands
|
||||
#define INIT_CMD_COUNT 7 //number of init commands to send
|
||||
#define MAX_CMD_LEN 7 //Longest initialization command strings.
|
||||
#define OBD_RECV_BUF_SIZE 48 // maximum characters to be read into buffer
|
||||
//Stings that will be sent during initialization
|
||||
const char PROGMEM s_initcmd[INIT_CMD_COUNT][MAX_CMD_LEN] = {
|
||||
"ATZ\r","ATE0\r","ATL1\r","ATI\r","ATSP6\r","0100\r","ATDP\r"};
|
||||
// ATSPx\r where x is the protocol. Change that command for other protocols.
|
||||
// "ATSP2\r" is to initialze VPW OBDII comunicaiton (LS1).
|
||||
// "ATSP6\r" is to initialize can bus OBDII comunicaiton (Newer LSx engines).
|
||||
// "ATSP3\r" is to initialize ISO OBDII comunicaiton (E46 OBDII).
|
||||
/*
|
||||
ATSPx\r where x is the protocol
|
||||
1 SAE J1850 PWM (41.6 kbaud)
|
||||
2 SAE J1850 VPW (10.4)
|
||||
3 ISO 9141-2 (5 baud init)
|
||||
4 iso 14230-4 KWP (5 baud init)
|
||||
5 iso 14230-5 KWP (fast init)
|
||||
6 ISO 15765-4 CAN (11 bit ID, 500 kbaud) *most common can bus and used in E46
|
||||
7 ISO 15765-4 CAN (29 bit ID, 500 kbaud) *used on newer vehicles
|
||||
8 ISO 15765-4 CAN (11 bit ID, 250 kbaud)
|
||||
9 ISO 15765-4 CAN (29 bit ID, 250 kbaud)
|
||||
|
||||
*/
|
||||
char buffer[OBD_RECV_BUF_SIZE];
|
||||
boolean Prompted;
|
||||
|
||||
/** Array containing the bytes of the CAN message. This array
|
||||
* may be accessed directly to set or read the CAN message.
|
||||
* This field can also be set by the setTypeData functions and
|
||||
* read by the getTypeData functions. */
|
||||
uint8_t dataPID[8];
|
||||
int PID_flag; //flag to show if PID complete and rec'd
|
||||
int PID_flag_o; //flag for which PID should be sent next
|
||||
int CAN_flag; //flag to indicate which can message to send next
|
||||
int PID_SIZE; //size of PID message recieved
|
||||
int IGN_status; // ignition status
|
||||
long time_PID; //timer between RPM sends
|
||||
long time_PID_o; //Timere between non PID sends
|
||||
long time_CAN; // Timer between CAN bus outputs
|
||||
long time_CAN_in; // Timer between CAN bus inputs
|
||||
long time_test; //debug
|
||||
int test_up; //debug
|
||||
int test_flag; //debug
|
||||
int iE; //counter for dataPID[] in the PID_rec void so can keep it's place
|
||||
//*******************************************************
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#include <SPI.h>
|
||||
int slaveSelectPin = 10;
|
||||
#include <SoftwareSerial.h> //Library file for software serial connenction (Used to comunicate with ELM327)
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/power.h> //for power off mode
|
||||
#include <avr/sleep.h> //for power off mode
|
||||
|
||||
#define DEFAULT_CAN_ID 0x0555
|
||||
// added for filter and can changes
|
||||
#define MASK_0 0x20
|
||||
#define MASK_1 0x24
|
||||
#define FILTER_0 0x00
|
||||
#define FILTER_1 0x04
|
||||
#define FILTER_2 0x08
|
||||
#define FILTER_3 0x10
|
||||
#define FILTER_4 0x14
|
||||
#define FILTER_5 0x18
|
||||
|
||||
#define WRITE 0x02 //read and write comands for SPI
|
||||
|
||||
/* Mcp2515 Operation Modes */
|
||||
enum CAN_MODE {
|
||||
CAN_MODE_NORMAL, /* Transmit and receive as normal */
|
||||
CAN_MODE_SLEEP, /* Low power mode */
|
||||
CAN_MODE_LOOPBACK, /* Test mode; anything "sent" appears in the receive buffer without external signaling */
|
||||
CAN_MODE_LISTEN_ONLY, /* Receive only; do not transmit */
|
||||
CAN_MODE_CONFIG, /* Default; Allows writing to config registers */
|
||||
CAN_MODE_COUNT
|
||||
};
|
||||
|
||||
//variables for checking MPG time
|
||||
|
||||
unsigned long MPG; //Calculated MPG step value based on input
|
||||
long MPG_correct = 100; //correction factor for MPG guage
|
||||
|
||||
//variables to capture RPM pulse.
|
||||
int rLSB; //RPM Least significant pit from RPM calc
|
||||
int rMSB; //RPM most significant pit from RPM calc
|
||||
|
||||
long del; //Delay time
|
||||
|
||||
//Variables for temperature light
|
||||
int tempValue;
|
||||
int tempLight;
|
||||
|
||||
//CanMessage message;
|
||||
byte i;
|
||||
int x;
|
||||
uint8_t message;
|
||||
|
||||
/** A flag indicating whether this is an extended CAN message */
|
||||
uint8_t extended;
|
||||
|
||||
/** The ID of the CAN message. The ID is 29 bytes long if the
|
||||
* extended flag is set, or 11 bytes long if not set. */
|
||||
uint32_t id;
|
||||
|
||||
/** The number of bytes in the data field (0-8) */
|
||||
uint8_t len;
|
||||
|
||||
/** Array containing the bytes of the CAN message. This array
|
||||
* may be accessed directly to set or read the CAN message.
|
||||
* This field can also be set by the setTypeData functions and
|
||||
* read by the getTypeData functions. */
|
||||
uint8_t data[8];
|
||||
uint8_t LSBdata;
|
||||
uint8_t MSBdata;
|
||||
uint8_t ErrorState;
|
||||
@@ -0,0 +1,149 @@
|
||||
//******************************************mcp2515 declarations**************************************
|
||||
#include <stdint.h>
|
||||
|
||||
/** For each increment of the BRP, our time quanta goes up this many
|
||||
* nanoseconds (for our 16MHz crystal) */
|
||||
#define TIME_QUANTUM_STEP 125
|
||||
|
||||
/** The minimum bit width in time quanta (1, 1, 1, 2) */
|
||||
#define QUANTUM_WIDTH_MIN 5
|
||||
|
||||
/** The maximum bit width in time quanta (1, 8, 8, 8) */
|
||||
#define QUANTUM_WIDTH_MAX 25
|
||||
|
||||
/** The highest possible BRP value */
|
||||
#define BRP_MAX 63
|
||||
|
||||
/** The SYNC_JUMP_WIDTH is always 1 time quantum */
|
||||
#define SYNC_JUMP_WIDTH 1
|
||||
|
||||
|
||||
/* SPI Commands */
|
||||
enum {
|
||||
MCP2515_CMD_RESET = 0xC0,
|
||||
MCP2515_CMD_READ = 0x03,
|
||||
MCP2515_CMD_WRITE = 0x02,
|
||||
MCP2515_CMD_RTS = 0x80,
|
||||
MCP2515_CMD_READ_STATUS = 0xA0,
|
||||
MCP2515_CMD_BIT_MODIFY = 0x05,
|
||||
};
|
||||
|
||||
#define FIELD_MASK(w) ((1 << w) - 1)
|
||||
|
||||
/* Registers and bits */
|
||||
#define RXM0SIDH 0x20
|
||||
#define RXM1SIDH 0x24
|
||||
|
||||
#define CANSTAT 0x0E
|
||||
#define OPMOD 5
|
||||
#define ICOD 1
|
||||
|
||||
#define CANCTRL 0x0F
|
||||
#define REQOP 5
|
||||
#define REQOP_MASK (FIELD_MASK(3) << REQOP)
|
||||
#define ABAT 4
|
||||
#define CLKEN 2
|
||||
#define CLKPRE 0
|
||||
|
||||
#define CNF3 0x28
|
||||
#define PHSEG2 0
|
||||
#define WAKFIL 6
|
||||
|
||||
#define CNF2 0x29
|
||||
#define PRSEG 0
|
||||
#define PHSEG1 3
|
||||
#define SAM 6
|
||||
#define BTLMODE 7
|
||||
|
||||
#define CNF1 0x2A
|
||||
#define BRP 0
|
||||
#define SJW 6
|
||||
|
||||
#define CANINTF 0x2C
|
||||
#define MERRF 7
|
||||
#define WAKIF 6
|
||||
#define ERRIF 5
|
||||
#define TX2IF 4
|
||||
#define TX1IF 3
|
||||
#define TX0IF 2
|
||||
#define RX1IF 1
|
||||
#define RX0IF 0
|
||||
|
||||
/**
|
||||
* For registers that are duplicated across multiple RX and TX buffers,
|
||||
* use the REG macro.
|
||||
* @param dir - Direction, either "RX" or "TX"
|
||||
* @param num - Number of the buffer, 0 or 1 for RX; 0, 1, or 2 for TX.
|
||||
* @param reg - The register of the buffer, defined below.
|
||||
* @return The address of the register
|
||||
*/
|
||||
#define REG(dir,num,reg) (((dir) + ((num) << 4)) | (reg))
|
||||
#define TX 0x30
|
||||
#define RX 0x60
|
||||
|
||||
#define CTRL 0x00
|
||||
#define SIDH 0x01
|
||||
#define SIDL 0x02
|
||||
#define EID8 0x03
|
||||
#define EID0 0x04
|
||||
#define DLC 0x05
|
||||
#define D0 0x06
|
||||
#define D1 0x07
|
||||
#define D2 0x08
|
||||
#define D3 0x09
|
||||
#define D4 0x0A
|
||||
#define D5 0x0B
|
||||
#define D6 0x0C
|
||||
#define D7 0x0D
|
||||
|
||||
/* TX CTRL bits */
|
||||
#define ABTF 6
|
||||
#define MLOA 5
|
||||
#define TXERR 4
|
||||
#define TXREQ 3
|
||||
#define TXP 0
|
||||
|
||||
/* TXB SIDL bits */
|
||||
#define EXIDE 3
|
||||
|
||||
/* TX DLC bits */
|
||||
#define RTR 6
|
||||
#define DLC0 0
|
||||
|
||||
/* RX CTRL bits */
|
||||
#define RXM 5
|
||||
#define RXRTR 3
|
||||
#define BUKT 2
|
||||
#define BUKT1 1
|
||||
#define FILHIT0 0
|
||||
|
||||
/* RXB SIDL bits */
|
||||
#define IDE 3
|
||||
|
||||
/* RX DLC bits */
|
||||
#define RTR 6
|
||||
#define RB 4
|
||||
// #define DLC0 0 // Duplicate of TX
|
||||
|
||||
/* Operation Modes */
|
||||
#define MCP2515_MODE_NORMAL 0x00
|
||||
#define MCP2515_MODE_SLEEP 0x01
|
||||
#define MCP2515_MODE_LOOPBACK 0x02
|
||||
#define MCP2515_MODE_LISTEN_ONLY 0x03
|
||||
#define MCP2515_MODE_CONFIG 0x04
|
||||
|
||||
/**
|
||||
* CAN bus speeds. These are the bit-times for common frequencies.
|
||||
*/
|
||||
enum {
|
||||
MCP2515_SPEED_500000 = 2000,
|
||||
MCP2515_SPEED_250000 = 4000,
|
||||
MCP2515_SPEED_125000 = 8000,
|
||||
MCP2515_SPEED_100000 = 10000,
|
||||
MCP2515_SPEED_62500 = 16000,
|
||||
MCP2515_SPEED_50000 = 20000,
|
||||
MCP2515_SPEED_31250 = 32000,
|
||||
MCP2515_SPEED_25000 = 40000,
|
||||
MCP2515_SPEED_20000 = 50000,
|
||||
MCP2515_SPEED_15625 = 64000
|
||||
};
|
||||
@@ -0,0 +1,310 @@
|
||||
SoftwareSerial ELM(2, 3); // RX, TX; ELM will be serial name
|
||||
|
||||
void setup()
|
||||
{
|
||||
// enable debugging
|
||||
// #define _DEBUG
|
||||
|
||||
len= 8; //length set at 8 for all messages sent
|
||||
extended = 0x0; //set as not extended format for all messages sent
|
||||
|
||||
// Can bus speeds (E46 is 500 Kbps)
|
||||
// 500 Kbps = MCP2515_SPEED_500000,
|
||||
CAN_begin(MCP2515_SPEED_500000); // set can baud rate
|
||||
CAN_setMode (CAN_MODE_NORMAL); // set can mode
|
||||
|
||||
//set up serial port for debugging with data to PC screen
|
||||
Serial.begin(115200);
|
||||
|
||||
// start serial communication at the adapter defined baudrate
|
||||
ELM.begin(38400); //ELM to Arduino start
|
||||
|
||||
Init(); // initiate ELM327 connection to car
|
||||
|
||||
del = 3; // minimum delay time between sends for Can bus messages (limited by program speed obviously)
|
||||
// if using "delay" command it is milliseconds
|
||||
//time_PID_o = millis();
|
||||
Serial.println("begin main void");
|
||||
IGN_status = 1;
|
||||
time_CAN_in = millis();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
//The main loop calls subroutines to send the actual messages
|
||||
|
||||
//the commented out section used for Debugging
|
||||
//***************************RPM print*****************
|
||||
// Serial.print(time_PID);
|
||||
// Serial.print(" ");
|
||||
// Serial.println(RPM);
|
||||
//****End RPM print ****************************************
|
||||
|
||||
//***************************MPG Print*****************
|
||||
// Serial.print(timeMPG);
|
||||
// Serial.print(" ");
|
||||
// Serial.println(RPM);
|
||||
//****End MPG print ****************************************
|
||||
|
||||
// send_fuel();//ARBID: 545 100ms-400ms
|
||||
// send_temp(); //ARBID: 329 20ms-30ms
|
||||
// send_RPM(); //ARBID: 316, 40ms-60ms
|
||||
|
||||
if(IGN_status >0)
|
||||
{
|
||||
if (PID_flag == 0) PID_send(); //send PID for RPM at regular intervals && millis() - time_PID > 50
|
||||
if(millis() - time_test > 150) set_testvalues(); //after x second get new values. //debug
|
||||
}
|
||||
if (PID_flag > 0) PID_rec(); //check for message ELM if a PID has been sent (flag > 0). Use timer or other means instead of flag?
|
||||
|
||||
if (millis() - time_CAN > del) CAN_bus_send(); //send CAN bus messages at regular intervals
|
||||
|
||||
if (CAN_available()) //check to see if MCP2551 has a message
|
||||
{
|
||||
CAN_getMessage(); //Read the mesage
|
||||
if(id == 0x613) CAN_ProcessMessage(); //if ARBID is 615 (from IKE) process message
|
||||
} //end if CAN available
|
||||
if ((millis() - time_CAN_in) > 1000) // if time since last IKE can message was > 1 second
|
||||
{
|
||||
Serial.println("shut down");
|
||||
IGN_status = 0;
|
||||
sleepNow(); // sleep function called here
|
||||
}
|
||||
|
||||
}// End of Main Void
|
||||
|
||||
//***************************************************************************
|
||||
void CAN_bus_send() // Send CAN bus messages at regular intervals
|
||||
{//rotates through 3 different messages. Sends the RPM twice (every other one)
|
||||
|
||||
if(CAN_flag == 0 || CAN_flag == 2) send_RPM(); //ARBID: 316
|
||||
if(CAN_flag == 1) send_temp(); //ARBID: 329 20ms
|
||||
//if(CAN_flag == 2) send_RPM(); //ARBID: 316
|
||||
if(CAN_flag == 3) send_fuel(); //ARBID: 545
|
||||
|
||||
CAN_flag ++; //increment flag
|
||||
if(CAN_flag > 3) CAN_flag = 0; //if flag exceeds max reset to 0 (should this be zero or 1)?
|
||||
time_CAN = millis(); //reset timer for RPM send
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void PID_send() // ELM_send("01 XX 1\r"); //Sends pid to ELM XX being the PID
|
||||
{
|
||||
if(PID_flag_o == 0) ELM_send("01 0C 1\r"); //RPM send PID to ELM
|
||||
if(PID_flag_o == 1) ELM_send("01 05 1\r"); //Sends pid ENGINE_COOLANT_TEMP
|
||||
if(PID_flag_o == 2) ELM_send("01 0C 1\r"); //RPM send PID to ELM
|
||||
if(PID_flag_o == 3) ELM_send("01 10 1\r"); //Sends pid ENGINE_maf
|
||||
if(PID_flag_o == 4) ELM_send("01 0C 1\r"); //RPM send PID to ELM
|
||||
if(PID_flag_o == 5) ELM_send("01 01 1\r"); //Sends pid ENGINE_MIL status
|
||||
if(PID_flag_o == 6) ELM_send("01 0C 1\r"); //RPM send PID to ELM
|
||||
if(PID_flag_o == 7) ELM_send("01 11 1\r"); //Sends pid ENGINE_TPS status
|
||||
|
||||
|
||||
PID_flag_o ++; //Pid >1 set PID flag so program will listen for response. Increment do send next message
|
||||
if(PID_flag_o > 7) PID_flag_o = 0; //if flag exceeds max reset to 0. back to start
|
||||
PID_flag = 1; //set flag to know to wait for ELM response
|
||||
time_PID = millis(); //reset timer for RPM send
|
||||
}
|
||||
/*
|
||||
void PID_send_others() // ELM_send("01 0C 1\r"); //Sends pid to ELM
|
||||
{
|
||||
if(PID_flag_o == 0) ELM_send("01 05 1\r"); //Sends pid ENGINE_COOLANT_TEMP
|
||||
if(PID_flag_o == 1) ELM_send("01 10 1\r"); //Sends pid ENGINE_maf
|
||||
if(PID_flag_o == 2) ELM_send("01 01 1\r"); //Sends pid ENGINE_MIL status
|
||||
if(PID_flag_o == 3) ELM_send("01 11 1\r"); //Sends pid ENGINE_TPS status
|
||||
|
||||
PID_flag = 1; //set PID flag so program will listen for response
|
||||
PID_flag_o ++; //increment flag
|
||||
if(PID_flag_o > 3) PID_flag_o = 0; //if flag exceeds max reset to 0
|
||||
time_PID_o = millis(); //reset timer for RPM send
|
||||
}*/
|
||||
|
||||
//***************************************************************************
|
||||
void send_RPM() //ARBID 316, RPM
|
||||
{
|
||||
id = 0x316; //From ECU
|
||||
data[0]= 0x05;
|
||||
data[1]= 0x62;
|
||||
data[2]= rLSB; //RPM LSB0xFF
|
||||
data[3]= rMSB; //RPM MSB "0x0F" = 600 RPM0x4F
|
||||
data[4]= 0x65;
|
||||
data[5]= 0x12;
|
||||
data[6]= 0x0;
|
||||
data[7]= 0x62;
|
||||
CAN_send();
|
||||
}//end RPM Loop
|
||||
|
||||
void send_temp() //ARBID 329, Temperature, Throttle position
|
||||
{
|
||||
//********************temp sense *******************************
|
||||
// The sensor and gauge are not linear.
|
||||
// data[1] values and correlating needle position:
|
||||
// 0x56 = First visible movment of needle starts
|
||||
// 0x5D = Begining of Blue section
|
||||
// 0x80 = End of Blue Section
|
||||
// 0xA9 = Begin Straight up
|
||||
// 0xC1 = Midpoint of needle straight up values
|
||||
// 0xDB = Needle begins to move from center
|
||||
// 0xE6 = Beginning of Red section
|
||||
// 0xFE = needle pegged to the right
|
||||
// MAP program statement: map(value, fromLow, fromHigh, toLow, toHigh)
|
||||
|
||||
//Can bus data packet values to be sent
|
||||
id = 0x329; //From ECU
|
||||
data[0]= 0xD9;
|
||||
data[1]= tempValue; //temp bit tdata From OBDII
|
||||
data[2]= 0xB2;
|
||||
data[3]= 0x19;
|
||||
data[4]= 0x0;
|
||||
data[5]= 0xEE; //Throttle position currently just fixed value
|
||||
data[6]= 0x0;
|
||||
data[7]= 0x0;
|
||||
CAN_send();
|
||||
|
||||
}//end Temperature Loop
|
||||
|
||||
void send_fuel()//ARBID 545
|
||||
//From ECU, MPG, MIL, overheat light, Cruise
|
||||
// ErrorState variable controls:
|
||||
//Check engine(binary 10), Cruise (1000), EML (10000)
|
||||
//Temp light Variable controls temp light. Hex 08 is on zero off
|
||||
{
|
||||
|
||||
//**************** set Error Lights & cruise light ******
|
||||
if(tempValue>0xE6){ // lights light if value is 229 (hot)
|
||||
tempLight = 8; // hex 08 = Overheat light on
|
||||
}
|
||||
else {
|
||||
tempLight = 0; // hex 00 = overheat light off
|
||||
}
|
||||
|
||||
// int z = 0x60; // + y; higher value lower MPG
|
||||
if (LSBdata + MPG > 0xFF){ //if adding will go past max value
|
||||
MSBdata = MSBdata + 0x01; //increment MSB
|
||||
}
|
||||
LSBdata=LSBdata + MPG; //increment values based on inj input
|
||||
|
||||
//For debugging
|
||||
// Serial.print(LSBdata);
|
||||
// Serial.print(" ");
|
||||
// Serial.println(MPG);
|
||||
|
||||
//Can bus data packet values to be sent
|
||||
id = 0x545; //From ECU, MPG, MIL, overheat light, Cruise
|
||||
data[0]= ErrorState; //set error byte to error State variable
|
||||
data[1]= LSBdata; //LSB Fuel consumption
|
||||
data[2]= MSBdata; //MSB Fuel Consumption
|
||||
data[3]= tempLight; //Overheat light
|
||||
data[4]= 0x7E;
|
||||
data[5]= 0x10;
|
||||
data[6]= 0x00;
|
||||
data[7]= 0x18;
|
||||
|
||||
//Time captures for MPG gauge
|
||||
// timeMPGp1 = micros();
|
||||
// timeMPG = timeMPGp1 - timeMPGp2;
|
||||
// timeMPGp2 = timeMPGp1;
|
||||
|
||||
CAN_send(); //can send 545
|
||||
|
||||
} //end send_Fuel if
|
||||
|
||||
//********************* Process message ***************
|
||||
void CAN_ProcessMessage()
|
||||
{
|
||||
time_CAN_in= millis(); //set time for last time message recieved
|
||||
// Serial.println("recd 0x615"); //debug
|
||||
Serial.print(data[0],HEX); //debug
|
||||
Serial.print(" "); //debug
|
||||
Serial.print(data[1],HEX); //debug
|
||||
Serial.print(" "); //debug
|
||||
Serial.print(data[2],HEX); //debug
|
||||
Serial.print(" "); //debug
|
||||
Serial.print(data[3],HEX); //debug
|
||||
Serial.print(" "); //debug
|
||||
Serial.print(data[4],HEX); //debug
|
||||
Serial.print(" "); //debug
|
||||
Serial.print(data[5],HEX); //debug
|
||||
Serial.print(" "); //debug
|
||||
Serial.print(data[6],HEX); //debug
|
||||
Serial.print(" "); //debug
|
||||
Serial.println(data[7],HEX); //debug
|
||||
|
||||
//----------------- look for Ignition on -----------------
|
||||
if(bitRead(data[4],0) == 1) //look for IGN on bit
|
||||
{//IGN is on
|
||||
//do something
|
||||
IGN_status = 1; //set flag for IGN status
|
||||
Serial.println("IGN on");
|
||||
}
|
||||
else //AC message from E46 is IGN off
|
||||
{
|
||||
//Stop ELM and stop sending can (Put elm and MCP's to sleep?)
|
||||
Serial.println("IGN off");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------- look for AC on -----------------
|
||||
if(bitRead(data[0],7) == 1) //look for ac on bit
|
||||
{//AC message from E46 is AC on
|
||||
//set pin x low (AC on)
|
||||
// digitalWrite(AC_pin, LOW); //set AC to on; this to be changed to send can message to LS3
|
||||
Serial.println("ac just turned on");
|
||||
}
|
||||
else //AC message from E46 is AC off
|
||||
{
|
||||
//Set pin x high (AC off)
|
||||
// digitalWrite(AC_pin, HIGH); //set AC to OFF; this to be changed to send can message to LS3
|
||||
Serial.println("ac just turned off");
|
||||
}
|
||||
|
||||
} //end process message
|
||||
|
||||
void sleepNow()
|
||||
{
|
||||
/* Now is the time to set the sleep mode. In the Atmega8 datasheet
|
||||
* http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
|
||||
* there is a list of sleep modes which explains which clocks and
|
||||
* wake up sources are available in which sleep modus.
|
||||
*
|
||||
* In the avr/sleep.h file, the call names of these sleep modus are to be found:
|
||||
*
|
||||
* The 5 different modes are:
|
||||
* SLEEP_MODE_IDLE -the least power savings
|
||||
* SLEEP_MODE_ADC
|
||||
* SLEEP_MODE_PWR_SAVE
|
||||
* SLEEP_MODE_STANDBY
|
||||
* SLEEP_MODE_PWR_DOWN -the most power savings
|
||||
*
|
||||
* the power reduction management <avr/power.h> is described in
|
||||
* http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
|
||||
*/
|
||||
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
|
||||
|
||||
sleep_enable(); // enables the sleep bit in the mcucr register
|
||||
// so sleep is possible. just a safety pin
|
||||
|
||||
power_adc_disable();
|
||||
power_spi_disable();
|
||||
power_timer0_disable();
|
||||
power_timer1_disable();
|
||||
power_timer2_disable();
|
||||
power_twi_disable();
|
||||
|
||||
|
||||
sleep_mode(); // here the device is actually put to sleep!!
|
||||
|
||||
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
|
||||
sleep_disable(); // first thing after waking from sleep:
|
||||
// disable sleep...
|
||||
|
||||
power_all_enable();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
//**************** ELM INIT **********************
|
||||
void Init()
|
||||
{
|
||||
boolean passive;
|
||||
unsigned char n;
|
||||
char prompted;
|
||||
|
||||
|
||||
for (i = 0; i < INIT_CMD_COUNT; i++) { //Loop enough times to send all init comands
|
||||
if (!passive) {
|
||||
char cmd[MAX_CMD_LEN];
|
||||
strcpy_P(cmd, s_initcmd[i]); // copy first string from S_initcmd to cmd
|
||||
ELM_send(cmd); // Send cmd string to ELM
|
||||
// Serial.println(cmd); //debug
|
||||
}
|
||||
ELM_rec(OBD_RECV_BUF_SIZE); //call ELM recieve
|
||||
} // end INIT command send loop
|
||||
return;
|
||||
} // end Init subroutine
|
||||
|
||||
|
||||
//*************************** ELM_REC ****************************
|
||||
// currently using Serial read to get data. To read elm just swtich.
|
||||
//buffer array and string size (max number of characters to catch)
|
||||
void ELM_rec(int String_size)
|
||||
{
|
||||
// int String_size = 2; //# of characters per array value to be read
|
||||
// int OBD_RECV_BUF_SIZE = 6; //max data bit pairs to be read
|
||||
long OBD_TIMEOUT_INIT = 100000;
|
||||
int n;
|
||||
char c;
|
||||
// char buffer[String_size-2];
|
||||
unsigned long currentMillis;
|
||||
unsigned long elapsed;
|
||||
|
||||
Prompted =0; //set propmpt ">" recieved flag to zero
|
||||
n = 0;
|
||||
currentMillis = millis();
|
||||
while (n < String_size) { //keep looping until recieved # of characters (String length)
|
||||
if (ELM.available()) { //do nothing if no data avail
|
||||
c = ELM.read();
|
||||
Serial.write(c);
|
||||
// ---------------- switch ------------------------
|
||||
switch (c) {
|
||||
|
||||
case '>': // if command prompt clear buffer and end both loops
|
||||
buffer[n] = 0;
|
||||
n = String_size; //set n to max size to end loop
|
||||
Prompted = 1;
|
||||
break;
|
||||
|
||||
case ' ': //if space discard
|
||||
case '\r': //if space discard
|
||||
break;
|
||||
|
||||
default: //if not command prompt
|
||||
buffer[n] = c; //move c to array. needed for conversion
|
||||
n++; // increment counter for reading in
|
||||
} //end switch
|
||||
} //end ELM available
|
||||
else { //check elapsed time in case elm read errors
|
||||
elapsed = millis() - currentMillis;
|
||||
if (elapsed > OBD_TIMEOUT_INIT) {
|
||||
// init timeout
|
||||
//WriteData("\r");
|
||||
buffer[n] = 0;
|
||||
n = String_size;
|
||||
i = OBD_RECV_BUF_SIZE;
|
||||
Serial.print(elapsed); //debug
|
||||
elapsed = 0;
|
||||
Serial.println(" timeout "); //debug
|
||||
} //end if time out
|
||||
} //end if serial avilable else (time out check)
|
||||
} // end read increment n loop
|
||||
}//end void
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
//*************************** PID_REC ****************************
|
||||
// Extra commands to take ELM data and put into PID array
|
||||
int PID_rec()
|
||||
{
|
||||
int bn = 0; //bit counter
|
||||
char c;
|
||||
// char buffer[String_size-2];
|
||||
int x = 398; //initialize x to no bytes
|
||||
|
||||
|
||||
while (ELM.available()>0){//If ELM has bytes to read
|
||||
c = ELM.read();
|
||||
#if defined(_DEBUG)
|
||||
//Serial.print("C");//debug
|
||||
// Serial.print(c); //debug
|
||||
//Serial.print(" "); //debug
|
||||
#endif
|
||||
|
||||
switch (c) {
|
||||
|
||||
case ' ': //if space discard
|
||||
x = 303; //flag leaving on space or carriage return
|
||||
break;
|
||||
|
||||
case '\r': //if space discard
|
||||
x = 303; //flag leaving on space or carriage return
|
||||
break;
|
||||
|
||||
case '>': // if command prompt clear buffer and end both loops
|
||||
PID_SIZE = iE; //set string size variable to current length of message
|
||||
iE=0;
|
||||
PID_flag = 0; //flag set to OK to send another PID command
|
||||
#if defined(_DEBUG)
|
||||
Serial.println(" ");
|
||||
Serial.println(" prompt recieved with message "); //debug
|
||||
#endif
|
||||
Decode(); //decode pid response
|
||||
return 300; // return good message
|
||||
|
||||
|
||||
default:
|
||||
//if not command prompt, space or return
|
||||
buffer[bn] = c; //store bite in temporary array
|
||||
// Serial.print(buffer[n]);
|
||||
// Serial.print("n= ");
|
||||
// Serial.print(bn);
|
||||
bn++; // increment counter for reading in
|
||||
if(bn > 1){//if we have a full byte, 2 characters
|
||||
// Serial.print("b1=");
|
||||
// Serial.print(buffer[0]);
|
||||
// Serial.print(" b2=");
|
||||
// Serial.print(buffer[1]);
|
||||
// Serial.print(" iE= ");
|
||||
// Serial.print(iE);
|
||||
// Serial.print(" ");
|
||||
|
||||
dataPID[iE] = toHex(buffer[0],buffer[1]); //convert 2 characters read in to hex
|
||||
bn = 0; // reset bit counter
|
||||
iE++; //index for next PID byte
|
||||
}
|
||||
|
||||
if(iE >10)
|
||||
{
|
||||
Serial.println("something has gone wrong with ELM");
|
||||
iE = 0;
|
||||
PID_flag = 0; //flag to ready to send PID command
|
||||
ELM.flush();
|
||||
return 401; //error
|
||||
}
|
||||
} // end switch
|
||||
x = 399; //byte recieved but not finished
|
||||
}//end ELM available
|
||||
|
||||
return x; //return 399 if partial message 398 if no bytes
|
||||
|
||||
}//end void get pid
|
||||
|
||||
// for(i=0 ;i< PID_response_SIZE ;i++){ //clear PID's
|
||||
// dataPID[i]=0; //clear PID's
|
||||
// } //end for //clear PID's
|
||||
|
||||
// for(i=0 ;i< OBD_RECV_BUF_SIZE ;i++){ //clear buffer's
|
||||
// buffer[i]=0; //clear PID's
|
||||
// } //end for //clear PID's
|
||||
|
||||
//******************** decode **************************
|
||||
//Decode for temp and RPM are ready to use. Other PID's need checked.
|
||||
void Decode() //Decode the data recieved in PID_rec Data is stored in dataPID[]
|
||||
{
|
||||
float engine_data;
|
||||
String message;
|
||||
|
||||
#if defined(_DEBUG)
|
||||
for(i=0; i< PID_SIZE; i++){ //debug
|
||||
Serial.print(dataPID[i],HEX); //debug
|
||||
Serial.print(" "); //debug
|
||||
}//debug
|
||||
Serial.println(" = finished dataPID[i]"); //debug
|
||||
#endif
|
||||
|
||||
// ************The switch ******
|
||||
switch(dataPID[1])
|
||||
{ /* Details from http://en.wikipedia.org/wiki/OBD-II_PIDs */
|
||||
case ENGINE_RPM: // ((A*256)+B)/4 [RPM]
|
||||
engine_data = ((dataPID[2]*256) + dataPID[3])/4;
|
||||
//=DEC2HEX(HEX2DEC(G3)/4*6.42/256)
|
||||
// data[3] = engine_data / 40 ; //RPM BMW MSB RPM / 40
|
||||
rMSB = engine_data / 40; //RPM BMW MSB RPM / 40 then to MSB hex (256)
|
||||
// data[2] = engine_data - (data[2] / 6.4 * 256); //RPM LSB
|
||||
rLSB = (engine_data - (rMSB * 40)) * 6.4; //RPM LSB subtract MSB portion then comvert to BMW value
|
||||
message = "ENGINE_RPM rpm = "; //debug
|
||||
break;
|
||||
|
||||
case ENGINE_COOLANT_TEMP: // A-40 [degree C]
|
||||
engine_data = dataPID[2] - 40; //Calculate output value
|
||||
// data[1] = (dataPID[3] + 8.373) / .75; //convert to BMW scale
|
||||
tempValue = (dataPID[2] + 8.373) / .75; //convert to BMW scale
|
||||
// Serial.print("BMW temp value = hex ");/debug
|
||||
// Serial.println(tempValue,HEX);//debug
|
||||
message ="engine coolant temp (degC) = ";//debug
|
||||
break;
|
||||
|
||||
case VEHICLE_SPEED: // A [km]
|
||||
// currently not used
|
||||
engine_data = dataPID[2];
|
||||
message ="VEHICLE_SPEED km ";//debug
|
||||
break;
|
||||
|
||||
case MAF_SENSOR: // ((256*A)+B) / 100 [g/s]
|
||||
engine_data = ((dataPID[2]*256) + dataPID[3])/100;
|
||||
message ="MAF_SENSOR g/s ";//debug
|
||||
break;
|
||||
|
||||
case MIL_CODE: // A * 0.005 (B-128) * 100/128 (if B==0xFF, sensor is not used in trim calc)
|
||||
engine_data = bitRead(dataPID[2],7);
|
||||
|
||||
if(engine_data != 0 || tempValue>229) {
|
||||
ErrorState = 0x02; //Set check engine. Binary 0010 (hex 02)
|
||||
}
|
||||
else {
|
||||
ErrorState = 0x00; // No error light (zero)
|
||||
}
|
||||
message ="MIL = ";//debug
|
||||
|
||||
break;
|
||||
|
||||
case THROTTLE: // Throttle Position
|
||||
engine_data = (dataPID[2]*100)/255;
|
||||
message ="THROTTLE %% ";//debug
|
||||
break;
|
||||
|
||||
} //End Switch case
|
||||
|
||||
#if defined(_DEBUG)
|
||||
// Serial.print("message, engine data");
|
||||
// Serial.print(message);
|
||||
// Serial.println(engine_data); //print output
|
||||
#endif
|
||||
|
||||
return;
|
||||
// Serial.println(" end of subroutine ");
|
||||
|
||||
} //end decode void
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ********* converts 2 charachter ascii to equivalent hex *********
|
||||
uint8_t toHex(char hi, char lo)
|
||||
{
|
||||
uint8_t b;
|
||||
hi = toupper(hi);
|
||||
if( isxdigit(hi) ) {
|
||||
if( hi > '9' ) hi -= 7; // software offset for A-F
|
||||
hi -= 0x30; // subtract ASCII offset
|
||||
b = hi<<4;
|
||||
lo = toupper(lo);
|
||||
if( isxdigit(lo) ) {
|
||||
if( lo > '9' ) lo -= 7; // software offset for A-F
|
||||
lo -= 0x30; // subtract ASCII offset
|
||||
b = b + lo;
|
||||
return b;
|
||||
} // else error
|
||||
} // else error
|
||||
return 0;
|
||||
}
|
||||
|
||||
//************* write data to ELM ******************
|
||||
void ELM_send(const char* s)
|
||||
{
|
||||
ELM.write(s);
|
||||
// Serial.print("writing this (s): "); //Debug
|
||||
// Serial.println(s); //Debug
|
||||
}
|
||||
|
||||
//************* write data to ELM ******************
|
||||
void ELM_send(const char c)
|
||||
{
|
||||
ELM.write(c); // send command over serial bus to ELM
|
||||
// Serial.print("writing this (c): "); //Debug
|
||||
// Serial.println(c); //Debug
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,444 @@
|
||||
//*********************** Can cpp ***************************************
|
||||
//Below is Can bus library and programming. Not specific to E46
|
||||
/*
|
||||
* Copyright (c) 2010-2011 by Kevin Smith <faz@fazjaxton.net>
|
||||
* MCP2515 CAN library for arduino. */
|
||||
|
||||
|
||||
void CAN_CanMessage ()
|
||||
{
|
||||
extended = 0;
|
||||
id = DEFAULT_CAN_ID;
|
||||
len = 0;
|
||||
}
|
||||
// **************************** setByteData *******************
|
||||
void CAN_setByteData (byte b)
|
||||
{
|
||||
len = 1;
|
||||
|
||||
data[0] = b;
|
||||
}
|
||||
|
||||
//******************* setIntData ***************************
|
||||
void setIntData (int i)
|
||||
{
|
||||
len = 2;
|
||||
|
||||
/* Big-endian network byte ordering */
|
||||
data[0] = i >> 8;
|
||||
data[1] = i & 0xff;
|
||||
}
|
||||
|
||||
//******************* setLongData ***************************
|
||||
void CAN_setLongData (long l)
|
||||
{
|
||||
len = 4;
|
||||
|
||||
/* Big-endian network byte ordering */
|
||||
data[0] = (l >> 24) & 0xff;
|
||||
data[1] = (l >> 16) & 0xff;
|
||||
data[2] = (l >> 8) & 0xff;
|
||||
data[3] = (l >> 0) & 0xff;
|
||||
}
|
||||
|
||||
//*********************** setData *****************************
|
||||
void CAN_setData (const uint8_t *data, uint8_t len)
|
||||
{
|
||||
byte i;
|
||||
|
||||
// this->len = len;
|
||||
len = len;
|
||||
for (i=0; i<len; i++) {
|
||||
// this->data[i] = data[i];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//*********************** setData **************************
|
||||
void CAN_setData (const char *data, uint8_t len)
|
||||
{
|
||||
CAN_setData ((const uint8_t *)data, len);
|
||||
}
|
||||
|
||||
//********************* send ******************************
|
||||
void CAN_send ()
|
||||
{
|
||||
//mcp2515_set_msg (0, id, data, len, extended);
|
||||
|
||||
uint8_t tx_buf = 0;
|
||||
|
||||
uint8_t buf[5];
|
||||
|
||||
if (extended) {
|
||||
buf[0] = (uint8_t)(id >> 21);
|
||||
buf[1] = (uint8_t)(((id >> 13) & 0xE0) |
|
||||
(1 << EXIDE) |
|
||||
((id >> 16) & 0x03));
|
||||
buf[2] = (uint8_t)(id >> 8);
|
||||
buf[3] = (uint8_t)(id);
|
||||
} else {
|
||||
buf[0] = (uint8_t)(id >> 3);
|
||||
buf[1] = (uint8_t)(id << 5);
|
||||
}
|
||||
|
||||
if (len > 8)
|
||||
len = 8;
|
||||
|
||||
buf[4] = len << DLC0;
|
||||
|
||||
mcp2515_write_regs (REG(TX, tx_buf, SIDH), buf, 5);
|
||||
mcp2515_write_regs (REG(TX, tx_buf, D0), data, len);
|
||||
|
||||
// mcp2515_request_tx (0);
|
||||
|
||||
mcp2515_bit_modify (REG(TX, tx_buf, CTRL), 1 << TXREQ, 1 << TXREQ);
|
||||
}
|
||||
|
||||
//****************** getByteFromData **********************
|
||||
|
||||
byte CAN_getByteFromData()
|
||||
{
|
||||
return data[0];
|
||||
}
|
||||
|
||||
//**************** getIntFromData ************************
|
||||
int CAN_getIntFromData ()
|
||||
{
|
||||
int val;
|
||||
|
||||
val |= (uint16_t)data[0] << 8;
|
||||
val |= (uint16_t)data[1] << 0;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
//**************** getLongFromData
|
||||
long CAN_getLongFromData ()
|
||||
{
|
||||
long val;
|
||||
|
||||
val |= (uint32_t)data[0] << 24;
|
||||
val |= (uint32_t)data[1] << 16;
|
||||
val |= (uint32_t)data[2] << 8;
|
||||
val |= (uint32_t)data[3] << 0;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
//********************** getData *******************
|
||||
void CAN_getData (uint8_t *data)
|
||||
{
|
||||
byte i;
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
// data[i] = this->data[i];
|
||||
}
|
||||
}
|
||||
|
||||
//******************** getData ***********************
|
||||
void CAN_getData (char *data)
|
||||
{
|
||||
CAN_getData ((uint8_t *)data);
|
||||
}
|
||||
|
||||
/*
|
||||
* CANClass
|
||||
*/
|
||||
|
||||
//********************** Begin ***********************
|
||||
void CAN_begin(uint32_t bit_period) {
|
||||
SPI.begin();
|
||||
SPI.setDataMode(SPI_MODE0);
|
||||
SPI.setBitOrder(MSBFIRST);
|
||||
SPI.setClockDivider(SPI_CLOCK_DIV4);
|
||||
|
||||
//mcp2515_init (bit_time); mcp2515_init (uint32_t bit_period)
|
||||
uint8_t brp;
|
||||
uint8_t bit_width;
|
||||
uint8_t prop_seg;
|
||||
uint8_t phase_1_seg;
|
||||
uint8_t phase_2_seg;
|
||||
|
||||
/* Calculate BRP and bit width */
|
||||
brp = calc_brp (bit_period, &bit_width);
|
||||
|
||||
if (bit_width < QUANTUM_WIDTH_MIN)
|
||||
bit_width = QUANTUM_WIDTH_MIN;
|
||||
|
||||
/* Calculate segment widths based on bit width. This algorithm keeps
|
||||
* the segments as even as possible, favoring phase2, then phase1
|
||||
* to be bigger. */
|
||||
phase_2_seg = (bit_width + 1) / 3;
|
||||
bit_width -= phase_2_seg;
|
||||
|
||||
phase_1_seg = bit_width >> 1;
|
||||
|
||||
prop_seg = bit_width - phase_1_seg - 1;
|
||||
|
||||
/* Set registers */
|
||||
mcp2515_write_reg (CNF1,
|
||||
(brp << BRP) |
|
||||
((SYNC_JUMP_WIDTH - 1) << SJW) );
|
||||
|
||||
mcp2515_write_reg (CNF2,
|
||||
((prop_seg - 1) << PRSEG) |
|
||||
((phase_1_seg - 1) << PHSEG1) |
|
||||
(0 << SAM) | /* Sample once */
|
||||
(1 << BTLMODE) ); /* Phase 2 set by CNF3 */
|
||||
|
||||
mcp2515_write_reg (CNF3,
|
||||
((phase_2_seg - 1) << PHSEG2) |
|
||||
(0 << WAKFIL) );
|
||||
|
||||
mcp2515_write_reg (REG(RX, 0, CTRL),
|
||||
(0x0 << RXM) |
|
||||
(0 << BUKT) );
|
||||
CAN_resetFiltersAndMasks();
|
||||
}
|
||||
|
||||
|
||||
//******************************** reset filters and Masks ****************
|
||||
// added to set filters -- from another program (not from Kevin Smith <faz@fazjaxton.net>)
|
||||
void CAN_resetFiltersAndMasks() {
|
||||
//disable first buffer
|
||||
CAN_setMaskOrFilter(MASK_0, 0b00000000, 0b00000000, 0b00000000, 0b00000000);
|
||||
CAN_setMaskOrFilter(FILTER_0, 0b00000000, 0b00000000, 0b00000000, 0b00000000);
|
||||
CAN_setMaskOrFilter(FILTER_1, 0b00000000, 0b00000000, 0b00000000, 0b00000000);
|
||||
|
||||
//disable the second buffer
|
||||
CAN_setMaskOrFilter(MASK_1, 0b00000000, 0b00000000, 0b00000000, 0b00000000);
|
||||
CAN_setMaskOrFilter(FILTER_2, 0b00000000, 0b00000000, 0b00000000, 0b00000000);
|
||||
CAN_setMaskOrFilter(FILTER_3, 0b00000000, 0b00000000, 0b00000000, 0b00000000);
|
||||
CAN_setMaskOrFilter(FILTER_4, 0b00000000, 0b00000000, 0b00000000, 0b00000000);
|
||||
CAN_setMaskOrFilter(FILTER_5, 0b00000000, 0b00000000, 0b00000000, 0b00000000);
|
||||
}
|
||||
|
||||
//***************************** set mask or FIlter **********************
|
||||
void CAN_setMaskOrFilter(byte mask, byte b0, byte b1, byte b2, byte b3) {
|
||||
CAN_setMode(CAN_MODE_CONFIG); // 1= Configuration, 2 = NORMAL, 3 = SLEEP, 4 = LISTEN, 5 = LOOPBACK
|
||||
CAN_setRegister(mask, b0);
|
||||
CAN_setRegister(mask+1, b1);
|
||||
CAN_setRegister(mask+2, b2);
|
||||
CAN_setRegister(mask+3, b3);
|
||||
CAN_setMode(CAN_MODE_LISTEN_ONLY); // (was 1) 1= Configuration, 2 = NORMAL, 3 = SLEEP, 4 = LISTEN, 5 = LOOPBACK
|
||||
}
|
||||
|
||||
//************************** Set register ******************************
|
||||
void CAN_setRegister(byte reg, byte value) {
|
||||
// mcp2515_write_reg (reg, value); this should be instead to write the registers
|
||||
//static void mcp2515_write_reg (uint8_t addr, uint8_t buf)
|
||||
// used from other program. Replaced by above
|
||||
digitalWrite(slaveSelectPin, LOW);
|
||||
delay(10);
|
||||
SPI.transfer(WRITE);
|
||||
SPI.transfer(reg);
|
||||
SPI.transfer(value);
|
||||
delay(10);
|
||||
digitalWrite(slaveSelectPin, HIGH);
|
||||
delay(10);
|
||||
|
||||
}
|
||||
// end from another program
|
||||
|
||||
|
||||
|
||||
///*********************** end ***********************
|
||||
void CAN_end() {
|
||||
SPI.end ();
|
||||
}
|
||||
|
||||
//********************* setMode *********************
|
||||
void CAN_setMode (uint8_t mode)
|
||||
{
|
||||
// mcp2515_set_mode (mode);
|
||||
mcp2515_bit_modify (CANCTRL, REQOP_MASK, mode << REQOP);
|
||||
}
|
||||
|
||||
//******************** ready **********************
|
||||
uint8_t CAN_ready ()
|
||||
{
|
||||
//return mcp2515_msg_sent ();
|
||||
uint8_t byte;
|
||||
|
||||
mcp2515_read_regs (REG(TX, 0, CTRL), &byte, 1);
|
||||
|
||||
return (!(byte & (1 << TXREQ)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
//****************** Available *********************
|
||||
boolean CAN_available ()
|
||||
{
|
||||
//return (boolean)mcp2515_msg_received();
|
||||
uint8_t byte;
|
||||
|
||||
mcp2515_read_regs (CANINTF, &byte, 1);
|
||||
|
||||
return (byte & ((1 << RX1IF) | (1 << RX0IF)));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//***************** getMessage ***********************
|
||||
void CAN_getMessage ()
|
||||
{
|
||||
// uint8_t test;
|
||||
uint8_t extended;
|
||||
// CanMessage m;
|
||||
//test = mcp2515_get_msg (0, &id, data, &len);
|
||||
extended = mcp2515_get_msg (0, &id, data, &len);
|
||||
|
||||
// return m;
|
||||
}
|
||||
|
||||
//CANClass CAN;
|
||||
|
||||
/*
|
||||
/**
|
||||
* A class representing a single CAN message. The message can be built
|
||||
* using the send<Type>Data functions, or the bytes of the message can
|
||||
* be set directly by accessing the public data[] array. This class is
|
||||
* also used to retrieve a message that has been received. The data
|
||||
* can be read using the get<type>Data functions, or can be read directly
|
||||
* by accessing the public data[] array.
|
||||
*/
|
||||
//class CanMessage {
|
||||
// public:
|
||||
/** A flag indicating whether this is an extended CAN message */
|
||||
// uint8_t extended;
|
||||
/** The ID of the CAN message. The ID is 29 bytes long if the
|
||||
* extended flag is set, or 11 bytes long if not set. */
|
||||
// uint32_t id;
|
||||
/** The number of bytes in the data field (0-8) */
|
||||
// uint8_t len;
|
||||
/** Array containing the bytes of the CAN message. This array
|
||||
* may be accessed directly to set or read the CAN message.
|
||||
* This field can also be set by the setTypeData functions and
|
||||
* read by the getTypeData functions. */
|
||||
// uint8_t data[8];
|
||||
|
||||
// CanMessage();
|
||||
|
||||
/**
|
||||
* Simple interface to set up a CAN message for sending a byte data
|
||||
* type. When received, this message should be unpacked with the
|
||||
* getByteData function. This interface only allows one byte to be
|
||||
* packed into a message. To pack more data, access the data array
|
||||
* directly.
|
||||
* @param b - The byte to pack into the message.
|
||||
*/
|
||||
// void setByteData (byte b);
|
||||
|
||||
/**
|
||||
* Simple interface to set up a CAN message for sending an int data
|
||||
* type. When received, this message should be unpacked with the
|
||||
* getIntData function. This interface only allows one int to be
|
||||
* packed into a message. To pack more data, access the data array
|
||||
* directly.
|
||||
* @param i - The int to pack into the message.
|
||||
*/
|
||||
// void setIntData (int i);
|
||||
|
||||
/**
|
||||
* Simple interface to set up a CAN message for sending a long data
|
||||
* type. When received, this message should be unpacked with the
|
||||
* getLongData function. This interface only allows one long to be
|
||||
* packed into a message. To pack more data, access the data array
|
||||
* directly.
|
||||
* @param l - The long to pack into the message.
|
||||
*/
|
||||
// void setLongData (long l);
|
||||
|
||||
/**
|
||||
* A convenience function for copying multiple bytes of data into
|
||||
* the message.
|
||||
* @param data - The data to be copied into the message
|
||||
* @param len - The size of the data
|
||||
*/
|
||||
// void setData (const uint8_t *data, uint8_t len);
|
||||
// void setData (const char *data, uint8_t len);
|
||||
|
||||
/**
|
||||
* Send the CAN message. Once a message has been created, this
|
||||
* function sends it.
|
||||
*/
|
||||
// void send();
|
||||
|
||||
/**
|
||||
* Simple interface to retrieve a byte from a CAN message. This
|
||||
* should only be used on messages that were created using the
|
||||
* setByteData function on another node.
|
||||
* @return The byte contained in the message.
|
||||
*/
|
||||
// byte getByteFromData ();
|
||||
|
||||
/**
|
||||
* Simple interface to retrieve an int from a CAN message. This
|
||||
* should only be used on messages that were created using the
|
||||
* setIntData function on another node.
|
||||
* @return The int contained in the message.
|
||||
*/
|
||||
// int getIntFromData ();
|
||||
|
||||
/**
|
||||
* Simple interface to retrieve a long from a CAN message. This
|
||||
* should only be used on messages that were created using the
|
||||
* setLongData function on another node.
|
||||
* @return The long contained in the message.
|
||||
*/
|
||||
// long getLongFromData ();
|
||||
|
||||
/**
|
||||
* A convenience function for copying multiple bytes out of a
|
||||
* CAN message.
|
||||
* @param data - The location to copy the data to.
|
||||
*/
|
||||
// void getData (uint8_t *data);
|
||||
// void getData (char *data);
|
||||
//};
|
||||
|
||||
//class CANClass {
|
||||
// public:
|
||||
/**
|
||||
* Call before using any other CAN functions.
|
||||
* @param bit_time - Desired width of a single bit in nanoseconds.
|
||||
* The CAN_SPEED enumerated values are set to
|
||||
* the bit widths of some common frequencies.
|
||||
*/
|
||||
// static void begin(uint32_t bit_time);
|
||||
|
||||
/** Call when all CAN functions are complete */
|
||||
// static void end();
|
||||
|
||||
/**
|
||||
* Set operational mode.
|
||||
* @param mode - One of the CAN_MODE enumerated values */
|
||||
// static void setMode(uint8_t mode);
|
||||
|
||||
/** Check whether a message may be sent */
|
||||
// static uint8_t ready ();
|
||||
|
||||
/**
|
||||
* Check whether received CAN data is available.
|
||||
* @return True if a message is available to be retrieved.
|
||||
*/
|
||||
// static boolean available ();
|
||||
|
||||
/**
|
||||
* Retrieve a CAN message.
|
||||
* @return A CanMessage containing the retrieved message
|
||||
*/
|
||||
// static CanMessage getMessage (); */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
|
||||
void mcp2515_read_regs (uint8_t addr, uint8_t* buf, uint8_t n)
|
||||
{
|
||||
int i;
|
||||
|
||||
digitalWrite (slaveSelectPin, LOW);
|
||||
SPI.transfer (MCP2515_CMD_READ);
|
||||
SPI.transfer (addr);
|
||||
for (i=0; i<n; i++)
|
||||
buf[i] = SPI.transfer (0);
|
||||
digitalWrite (slaveSelectPin, HIGH);
|
||||
}
|
||||
|
||||
void mcp2515_write_regs (uint8_t addr, const uint8_t* buf, uint8_t n)
|
||||
{
|
||||
int i;
|
||||
|
||||
digitalWrite (slaveSelectPin, LOW);
|
||||
SPI.transfer (MCP2515_CMD_WRITE);
|
||||
SPI.transfer (addr);
|
||||
for (i=0; i<n; i++)
|
||||
SPI.transfer (buf[i]);
|
||||
digitalWrite (slaveSelectPin, HIGH);
|
||||
}
|
||||
|
||||
static void mcp2515_write_reg (uint8_t addr, uint8_t buf)
|
||||
{
|
||||
digitalWrite (slaveSelectPin, LOW);;
|
||||
SPI.transfer (MCP2515_CMD_WRITE);
|
||||
SPI.transfer (addr);
|
||||
SPI.transfer (buf);
|
||||
digitalWrite (slaveSelectPin, HIGH);
|
||||
}
|
||||
|
||||
static void mcp2515_bit_modify (uint8_t addr, uint8_t mask, uint8_t bits)
|
||||
{
|
||||
digitalWrite (slaveSelectPin, LOW);
|
||||
SPI.transfer (MCP2515_CMD_BIT_MODIFY);
|
||||
SPI.transfer (addr);
|
||||
SPI.transfer (mask);
|
||||
SPI.transfer (bits);
|
||||
digitalWrite (slaveSelectPin, HIGH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the best prescalar and bit width in time quanta for the given bit
|
||||
* period. This algorithm favors lower prescalars and therefore higher
|
||||
* frequencies and more time quanta per bit.
|
||||
* @param bit_period - Length of bit period in nanoseconds
|
||||
* @param bit_width - Pointer to the location to store the bit width
|
||||
* return - The best prescalar
|
||||
*/
|
||||
static uint8_t calc_brp (uint32_t bit_period, uint8_t *bit_width)
|
||||
{
|
||||
uint32_t total_steps;
|
||||
uint16_t brp_min;
|
||||
uint16_t brp_max;
|
||||
uint8_t error;
|
||||
uint8_t best_width;
|
||||
uint8_t best_brp;
|
||||
uint8_t best_error = BRP_MAX;
|
||||
uint8_t i;
|
||||
|
||||
/* Calculate the minimum BRP that can meet this rate */
|
||||
brp_min = bit_period / (QUANTUM_WIDTH_MAX * TIME_QUANTUM_STEP);
|
||||
/* Calculate the maximum BRP that can meet this rate */
|
||||
brp_max = bit_period / (QUANTUM_WIDTH_MIN * TIME_QUANTUM_STEP);
|
||||
|
||||
/* Don't check outside the valid range */
|
||||
if (brp_min > BRP_MAX)
|
||||
brp_min = BRP_MAX;
|
||||
if (brp_max > BRP_MAX)
|
||||
brp_max = BRP_MAX;
|
||||
|
||||
total_steps = bit_period / TIME_QUANTUM_STEP;
|
||||
|
||||
for (i = brp_min; i <= brp_max; i++) {
|
||||
error = total_steps % (i + 1);
|
||||
|
||||
/* If the number of quanta that make the correct bit rate at this
|
||||
* prescalar is an integer, this is an exact match. */
|
||||
if (error == 0) {
|
||||
best_brp = i;
|
||||
best_width = total_steps / (i + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
/* If rounding up, the error is the difference between the divisor
|
||||
* and the remainder */
|
||||
if ((i + 1) - error < error) {
|
||||
error = (i + 1) - error;
|
||||
}
|
||||
|
||||
/* Store the settings at this BRP if they are the best yet */
|
||||
if (error < best_error) {
|
||||
best_error = error;
|
||||
best_width = (total_steps + ((i + 1) >> 1))/ (i + 1);
|
||||
best_brp = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the best match */
|
||||
*bit_width = best_width;
|
||||
return best_brp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Set the operating mode of the MCP2515
|
||||
*/
|
||||
//void mcp2515_set_mode (uint8_t mode)
|
||||
//{
|
||||
// mcp2515_bit_modify (CANCTRL, REQOP_MASK, mode << REQOP);
|
||||
//}
|
||||
|
||||
/*
|
||||
* Reads a message from the receive buffer and marks it as read.
|
||||
*/
|
||||
uint8_t mcp2515_get_msg (uint8_t rx_buf, uint32_t *id,
|
||||
uint8_t *data, uint8_t *len)
|
||||
{
|
||||
uint8_t buf[5];
|
||||
uint8_t extended;
|
||||
|
||||
mcp2515_read_regs (REG(RX, rx_buf, SIDH), buf, 5);
|
||||
*len = buf[4] & 0x0f;
|
||||
if (*len > 8)
|
||||
*len = 8;
|
||||
mcp2515_read_regs (REG(RX, rx_buf, D0), data, *len);
|
||||
|
||||
extended = buf[1] & (1 << IDE);
|
||||
if (extended) {
|
||||
*id = ((uint32_t)(buf[0]) << 21) |
|
||||
((uint32_t)(buf[1] & 0xE0) << 13) |
|
||||
((uint32_t)(buf[1] & 0x03) << 16) |
|
||||
((uint32_t)(buf[2]) << 8) |
|
||||
((uint32_t)(buf[3]) << 0);
|
||||
} else {
|
||||
*id = ((uint32_t)buf[0] << 3) |
|
||||
((uint32_t)buf[1] >> 5);
|
||||
}
|
||||
|
||||
mcp2515_bit_modify (CANINTF, 1 << (RX0IF + rx_buf), 0);
|
||||
|
||||
return extended;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mcp2515_set_rx_mask (uint8_t mask_num, uint32_t mask, uint8_t extended)
|
||||
{
|
||||
uint8_t reg;
|
||||
uint8_t buf[4];
|
||||
|
||||
if (mask_num == 0)
|
||||
reg = RXM0SIDH;
|
||||
else
|
||||
reg = RXM1SIDH;
|
||||
|
||||
if (extended) {
|
||||
buf[0] = (uint8_t)(mask >> 21);
|
||||
buf[1] = (uint8_t)(((mask >> 13) & 0xE0)
|
||||
| ((mask >> 16) & 0x03));
|
||||
buf[2] = (uint8_t)(mask >> 8);
|
||||
buf[3] = (uint8_t)(mask >> 0);
|
||||
} else {
|
||||
buf[0] = (uint8_t)(mask >> 3);
|
||||
buf[1] = (uint8_t)(mask << 5);
|
||||
buf[2] = 0;
|
||||
buf[3] = 0;
|
||||
}
|
||||
|
||||
mcp2515_write_regs (reg, buf, 4);
|
||||
}
|
||||
|
||||
void mcp2515_set_rx_filter (uint8_t filter_num, uint32_t filter, uint8_t extended)
|
||||
{
|
||||
uint8_t reg;
|
||||
uint8_t buf[4];
|
||||
|
||||
/* Calculate correct register */
|
||||
reg = filter_num * 4;
|
||||
if (reg >= 12)
|
||||
reg += 4;
|
||||
|
||||
if (extended) {
|
||||
buf[0] = (uint8_t)(filter >> 21);
|
||||
buf[1] = (uint8_t)(((filter >> 13) & 0xE0)
|
||||
| ((filter >> 16) & 0x03)
|
||||
| (1 << EXIDE));
|
||||
buf[2] = (uint8_t)(filter >> 8);
|
||||
buf[3] = (uint8_t)(filter >> 0);
|
||||
} else {
|
||||
buf[0] = (uint8_t)(filter >> 3);
|
||||
buf[1] = (uint8_t)(filter << 5);
|
||||
buf[2] = 0;
|
||||
buf[3] = 0;
|
||||
}
|
||||
|
||||
mcp2515_write_regs (reg, buf, 4);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
|
||||
void set_testvalues()
|
||||
{
|
||||
|
||||
|
||||
|
||||
// RPM (put the hex number together then convert to DEC and divide by 6.4)
|
||||
// rLSB; //RPM LSB0xFF
|
||||
// rMSB; //RPM MSB "0x0F" = 600, 0x19 = 1000 add 25 decimal to get next 1000, 7000 = 0xAF
|
||||
rLSB = 0x00;
|
||||
|
||||
// *************RPM
|
||||
|
||||
if(test_up == 0)
|
||||
rMSB = rMSB + 1;
|
||||
if(test_up == 1)
|
||||
rMSB = rMSB - 1;
|
||||
|
||||
if( rMSB < 0x01)
|
||||
{
|
||||
rMSB = rMSB + 2; //set initial value for rMSB
|
||||
test_up = 0; //set needle direction to increasing
|
||||
}
|
||||
if(rMSB > 0xAF) // if beyond 7000 rpm change direction
|
||||
{
|
||||
rMSB = rMSB - 2;
|
||||
test_up = 1; //set needle direction to decreasing
|
||||
}
|
||||
Serial.print("RPM MSB = ");
|
||||
Serial.println(rMSB,HEX);
|
||||
|
||||
if(test_flag > 2) //increment more slowly than RPM
|
||||
{
|
||||
// ************* temperature
|
||||
// tempValue; //temp bit tdata
|
||||
// values and correlating needle position:
|
||||
// 0x56 = First visible movment of needle starts
|
||||
// 0x5D = Begining of Blue section
|
||||
// 0x80 = End of Blue Section
|
||||
// 0xA9 = Begin Straight up
|
||||
// 0xC1 = Midpoint of needle straight up values
|
||||
// 0xDB = Needle begins to move from center
|
||||
// 0xE6 = Beginning of Red section
|
||||
// 0xFE = needle pegged to the right
|
||||
/* if(temp_up == 0)
|
||||
tempValue = tempValue + 1;
|
||||
if(temp_up == 1)
|
||||
tempValue = tempValue - 1;
|
||||
|
||||
if( tempValue < 0x56)
|
||||
{
|
||||
tempValue = tempValue + 2; //set initial value for rMSB
|
||||
temp_up = 0; //set needle direction to increasing
|
||||
}
|
||||
if(tempValue > 0xFE) // if beyond 7000 rpm change direction
|
||||
{
|
||||
tempValue = tempValue - 2;
|
||||
temp_up = 1; //set needle direction to decreasing
|
||||
}*/
|
||||
test_flag = 0;
|
||||
}
|
||||
|
||||
|
||||
//******check engine lights Check engine(binary 10,2), Cruise (1000,8), EML (10000,16), Check eng and EML (32)
|
||||
|
||||
if(rMSB > 0x0D && rMSB < 0x19) //if RPM between 500 and 1000
|
||||
{
|
||||
ErrorState = 0x01; //Set B0
|
||||
tempLight = 0x01; //set B3
|
||||
}
|
||||
|
||||
if(rMSB > 0x19 && rMSB < 0x26) //if RPM between 1000 and 1500
|
||||
{
|
||||
ErrorState = 0x02; //Set B0 check engine. Binary 0010 (hex 02)
|
||||
tempLight = 0x02; //set B3
|
||||
}
|
||||
|
||||
if(rMSB > 0x26 && rMSB < 0x32) //if RPM between 1500 and 2000
|
||||
{
|
||||
ErrorState = 0x04; //Set B0)
|
||||
tempLight = 0x04; //set B3
|
||||
}
|
||||
|
||||
if(rMSB > 0x32 && rMSB < 0x3F) //if RPM between 2000 and 2500
|
||||
{
|
||||
ErrorState = 0x08; //Set B0 Cruise
|
||||
tempLight = 0x08; //set B3 Overheat
|
||||
}
|
||||
|
||||
if(rMSB > 0x3F && rMSB < 0x4B) //if RPM between 2500 and 3000
|
||||
{
|
||||
ErrorState = 0x10; //Set B0 EML
|
||||
tempLight = 0x10; //set B3
|
||||
}
|
||||
|
||||
if(rMSB > 0x4B && rMSB < 0x58) //if RPM between 3000 and 3500
|
||||
{
|
||||
ErrorState = 0x20; //Set B0
|
||||
tempLight = 0x20; //set B3
|
||||
}
|
||||
|
||||
if(rMSB > 0x58 && rMSB < 0x64) //if RPM between 3500 and 4000
|
||||
{
|
||||
ErrorState = 0x40; //Set B0
|
||||
tempLight = 0x40; //set B3
|
||||
}
|
||||
|
||||
if(rMSB > 0x64 && rMSB < 0x71) //if RPM between 4000 and 4500
|
||||
{
|
||||
ErrorState = 0x80; //Set B0
|
||||
tempLight = 0x80; //set B3
|
||||
}
|
||||
|
||||
if(rMSB > 0x71&& rMSB < 0x7D) //if RPM between 4500 and 5000
|
||||
{
|
||||
ErrorState = 0x100; //Set B0
|
||||
tempLight = 0x100; //set B3
|
||||
}
|
||||
|
||||
//PAST 10 CHECKS
|
||||
if(rMSB > 0x7D && rMSB < 0x8A) //if RPM between 5000 and 5500
|
||||
{
|
||||
ErrorState = 0x03; //Set B0
|
||||
tempLight = 0x00; //set B3
|
||||
}
|
||||
|
||||
if(rMSB > 0x8A && rMSB < 0x96) //if RPM between 5500 and 6000
|
||||
{
|
||||
ErrorState = 0x06; //Set B0
|
||||
tempLight = 0x00; //set B3
|
||||
}
|
||||
|
||||
if(rMSB > 0x96 && rMSB < 0xA3) //if RPM between 6000 and 6500
|
||||
{
|
||||
ErrorState = 0xFF; //Set B0
|
||||
tempLight = 0x00; //set B3
|
||||
}
|
||||
|
||||
if(rMSB > 0xA3 && rMSB < 0xAF) //if RPM between 6050 and 7000
|
||||
{
|
||||
ErrorState = 0x00; //Set B0
|
||||
tempLight = 0xFF; //set B3
|
||||
}
|
||||
|
||||
|
||||
|
||||
test_flag++;//increment flag
|
||||
// if(test_flag==10) test_flag=0; //if past end of range reset
|
||||
time_test = millis(); //set timer
|
||||
}//end void
|
||||
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Listen_and_sendPID
|
||||
(b) is with test output
|
||||
009 28 Dec 2013 Adding sleep feature (also will capture AC on request).
|
||||
008 24 dec 2013 Corrected delay to give aprox 15mSec between can sends
|
||||
007 15 Nov 2013 Reworked PID send to sequence between RPM and others. fixed mil light(007a)
|
||||
006 22 Aug 2013 Revised to use timers to send PID's and Can bus messages. Reworked recieve routine to not stop if a partial message is recieved (similar to IPOD controler program)
|
||||
005 started a rewrite to have elm updates not slow loop and less frequent and include AFM
|
||||
004 April 2013 works with Laguna and E46 cluster for RPM. Temp dropped so shortend delay from 10 to 8 shorter delay will require the MPG calculation to be altered.
|
||||
Currently no MPG calculation exists. (shortening delay did not fix temp see version 005 for fix)
|
||||
|
||||
Arduino Connections:
|
||||
ELM wires go in pins D2 and D3, RX,TX
|
||||
Also connect to the ELM, 5V Power and ground. No other connections needed
|
||||
|
||||
This program is designed to extract the RPM, temp etc using PID's using the ELM327 clone
|
||||
then output the signals on CAN bus for a BMW E46 instrument cluster
|
||||
|
||||
A_declarations :has variables and constants
|
||||
A_OBDII_Dec :Global Declarations that are needed for the OBDII subroutines
|
||||
A_MCP_DEC :Declarations needed for the MCP2515 subroutines
|
||||
B_main :has void setup,loop,send_rpm,send_temp,send_fuel,
|
||||
C_ELM_init :Intializes the ELM comunication with the ECU
|
||||
C_OBDII :Subroutines for using PID's
|
||||
C_can :Can message subroutines
|
||||
D_MCP2515 :MCP2515 library converted to subroutine for easy altering
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
type: source
|
||||
tags: [can-bus, e60, reverse-engineering]
|
||||
updated: 2026-07-15
|
||||
raw: "raw/E60 VFL CAN-Bus Codes.xlsx"
|
||||
origin: Community spreadsheet, E60 pre-facelift (VFL) CAN codes; credits Trevor Cook, CarX24
|
||||
---
|
||||
|
||||
# Source: E60 VFL CAN-Bus Codes (spreadsheet)
|
||||
|
||||
Community-compiled table of ~130 CAN ID blocks observed on a **pre-facelift E60** — exactly our donor generation. Mixed content (much of it body/K-CAN: doors, windows, lights), with per-byte example payloads and computed values. All claims `(source: e60-vfl-xlsx)`.
|
||||
|
||||
## Hits for our target signals
|
||||
|
||||
| ID | Sheet says | Notes |
|
||||
|----|-----------|-------|
|
||||
| **0x1D0** | "Engine temp, pressure, handbrake" — B1=0x7A with computed value **74** | 0x7A = 122; 122 − 48 = 74 °C → **independently confirms the raw−48 coolant scaling on a real E60** (matches [[can-id-candidates]]) |
|
||||
| **0x1D2** | "Anzeige Getriebedaten", DLC 6, example `F0 0F FF 2C F0 FF` | Byte 0 = 0xF0 fits the nibble scheme (low nibble 0 = Off, high nibble = inverted copy); DLC 6 matches the E90-gen layout, not the E65's DLC 5 |
|
||||
| **0x304** | "Gear lever", DLC 2: P=0xE3, R=0xC2, N=0xD1, D=0xC2, M1–M7=0xC9 | **New candidate**: a compact E60 gear-lever message. ⚠ D and R share 0xC2 in the sheet — almost certainly a transcription error; bench-check |
|
||||
| **0x3B4** | "Battery- & engine status": B1=0x64 B2=0xF3 → **12.76 V**; byte 3: engine on=0x09 / off=0x00 | 12-bit LE raw would be 0x364=868; ×0.015 gives 13.02 V vs the sheet's 12.76 (implied factor ≈0.0147). **Supports the E65-style 12-bit little-endian layout** over the E90 24-bit BE one; exact factor needs bench check. Engine-running flag in byte 3 is a useful bonus |
|
||||
| 0x130 | Ignition/engine status, DLC 5, per-position byte values | Matches the dieslg8 finding (`0x130` terminal status) |
|
||||
| 0xAA | RPM + throttle | Matches research (0x0AA) |
|
||||
| 0x2CA / 0x366 / 0x32E | Outside/inside temperature | Ambient display data, not engine — nice-to-have |
|
||||
|
||||
## What's absent
|
||||
|
||||
**No engine oil temperature and no gearbox oil temperature rows anywhere in the sheet** — the two signals that were already our weakest. The sheet neither confirms nor refutes 0x1D0 byte 1 (oil) or 0x0B5 byte 7 (gearbox oil).
|
||||
|
||||
## Caveats
|
||||
|
||||
- Body-heavy content suggests capture on K-CAN; the (unverified) forum claim that E60 arbitration IDs are identical across K-CAN/PT-CAN is what makes it transferable to our 500 kbps tap.
|
||||
- Community transcription — individual byte values (e.g. the D/R duplicate on 0x304) contain errors.
|
||||
|
||||
## Relevance
|
||||
|
||||
Second independent, **E60-specific** confirmation of 0x1D0 coolant scaling and 0x3B4 battery voltage; adds 0x304 as a simpler gear-lever candidate. Updated: [[can-id-candidates]].
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
type: source
|
||||
tags: [hardware, waveshare, can-bus, power]
|
||||
updated: 2026-07-15
|
||||
raw: "[[raw/ESP32-S3-Touch-LCD-5B]]"
|
||||
origin: Waveshare wiki, ESP32-S3-Touch-LCD-5 family product page
|
||||
---
|
||||
|
||||
# Source: Waveshare ESP32-S3-Touch-LCD-5 Product Wiki
|
||||
|
||||
Official product documentation for the ESP32-S3-Touch-LCD-5 family. Covers four SKUs; ours is **28151 (ESP32-S3-Touch-LCD-5B)** — the touch version. All facts below are `(source: waveshare-wiki)`.
|
||||
|
||||
## Key facts
|
||||
|
||||
**Power — big one for this project:**
|
||||
- Two supply options: USB Type-C 5 V, or a **7–36 V DC wide-input terminal** — vehicle 12 V can feed the board directly, no external regulator needed.
|
||||
- Consumption: ~450 mA @ 5 V (~2.3 W).
|
||||
- Optional 3.7 V single-cell LiPo (MX1.25 connector, CS8501 boost/charge chip, 580 mA charge current, battery connect switch).
|
||||
|
||||
**CAN — answers our transceiver question:**
|
||||
- Onboard CAN interface, CAN 2.0 compliant, brought out on a 3.5 mm terminal block.
|
||||
- Transceiver chip: **TJA1051T/3/1J** (NXP, high-speed CAN) — no external transceiver needed; wire CAN-H/CAN-L straight to the terminal block.
|
||||
- **120 Ω termination resistor switch, OFF by default** — correct setting for tapping into an existing, already-terminated vehicle bus; leave it off.
|
||||
|
||||
**Other onboard peripherals:**
|
||||
- RS485 via SP3485, automatic TX/RX direction switching (this is the terminal block the firmware uses for UART1 → Controller B `(repo)`).
|
||||
- Optocoupler-isolated digital I/O: inputs 5–36 V (dry/wet contact, NPN or PNP), open-drain outputs sinking up to 450 mA/channel.
|
||||
- PCF85063 RTC with CR927 coin-cell holder.
|
||||
- TF card slot (SD_CS must be driven via CH422G EXIO4).
|
||||
- **CH422G I2C IO expander** — the screen eats most GPIOs, so reset/backlight/etc. go through it. Occupied I2C addresses: 0x20–0x27 and 0x30–0x3F (CH422G), 0x5D (GT911 touch). Avoid conflicts when adding I2C devices.
|
||||
- SGM2212-3.3 LDO (800 mA), AP3032 backlight boost.
|
||||
|
||||
**Display:** 5" IPS, 1024×600 (5B) or 800×480 (5), 65K colors (16-bit), 550 cd/m², 160° viewing angle, GT911 5-point capacitive touch, tempered glass.
|
||||
|
||||
**Operational notes:**
|
||||
- Flashing: Type-C port labeled UART, auto-download circuit; hold BOOT while connecting if the port isn't recognized.
|
||||
- Keep metal/plastic away from the PCB antenna area.
|
||||
|
||||
> [!warning] Operating temperature: 0 °C to 65 °C
|
||||
> Marginal for automotive use — an interior can drop well below 0 °C in winter and a dash in direct sun can exceed 65 °C. Filed under [[open-questions]].
|
||||
|
||||
## Relevance
|
||||
|
||||
Resolved open questions #6 (CAN transceiver — onboard TJA1051) and largely #7 (power — 7–36 V input takes vehicle 12 V directly; transient protection still worth a look). Raised a new one: operating temperature range. Updated: [[esp32-s3-touch-lcd-5b]], [[open-questions]].
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
type: source
|
||||
tags: [arduino, e46, obd, technique-reference]
|
||||
updated: 2026-07-15
|
||||
raw: "raw/Listen_and_send_PID_009c/"
|
||||
origin: Arduino sketch "Listen_and_sendPID" v009, Dec 2013 (MCP2515 + ELM327)
|
||||
---
|
||||
|
||||
# Source: Listen_and_send_PID_009c (Arduino sketch)
|
||||
|
||||
A 2013 Arduino project that does the **reverse** of our data flow: it *requests* engine data from any OBD-compliant ECU via an ELM327 clone (standard PIDs: RPM `((A×256)+B)/4`, coolant temp, etc.) and then **transmits E46-generation cluster frames** so a BMW E46 instrument cluster shows the data — `0x316` (RPM), `0x329` (temp + throttle), `0x545` (MIL/overheat/MPG/cruise), listening to `0x613` from the cluster/IKE. All claims `(source: listen-and-send-pid)`.
|
||||
|
||||
## Why it's in the collection (technique reference, not ID evidence)
|
||||
|
||||
- **Not evidence for our E60 map** — its BMW IDs are the E46 *cluster input* dialect, and its ECU-side data comes from OBD PID polling, not passive DDE broadcasts.
|
||||
- **Blueprint for the fault-code fallback**: it demonstrates the request/response pattern (poll PIDs → use data) that our display would need if we ever want DTCs or signals that aren't broadcast — the same conclusion as the dieslg8 finding (active requests on 0x6F1/0x612) in [[can-id-candidates]].
|
||||
- **E46 cluster needle calibration table**: temp-gauge byte values (0x56 = needle starts, 0x5D–0x80 = blue zone, 0xE6 = red zone start, 0xFE = pegged) — useful only if the Patrol build ever drives an OEM BMW gauge directly.
|
||||
- Practical MCP2515 + ELM327 wiring/timing patterns (15 ms inter-frame spacing, timer-driven sends).
|
||||
|
||||
## Relevance
|
||||
|
||||
Filed as a technique reference for a possible future "diagnostic request mode" (fault codes, non-broadcast signals). No changes to the candidate ID map.
|
||||
Reference in New Issue
Block a user