Retire .docs; move UART spec to docs/; correct stale CAN/UART facts in CLAUDE.md
- Delete .docs/CAN_BUS_INTEGRATION.md (placeholder CAN IDs, external transceiver wiring the board does not need); superseded by wiki/pages/can-id-candidates.md - Move UART_PROTOCOL.md to docs/ as the single copy of the packet spec - Move the annotated board photo into wiki/raw/ and add a source page for it - CLAUDE.md: verified 11-bit CAN ID list replaces the placeholders, TWAI_MODE_NORMAL replaces LISTEN_ONLY, UART TX is GPIO 44, dummy-data references removed - Wiki index/log updated; note the schematic PDF is missing from disk Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,604 +0,0 @@
|
||||
# CAN Bus Integration Guide
|
||||
|
||||
Complete guide for BMW CAN Bus integration with ESP32-S3-Touch-LCD-5B (Controller A).
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Overview](#overview)
|
||||
- [Hardware Setup](#hardware-setup)
|
||||
- [BMW CAN Message Specifications](#bmw-can-message-specifications)
|
||||
- [Testing with CAN Simulators](#testing-with-can-simulators)
|
||||
- [Connecting to Real BMW CAN Bus](#connecting-to-real-bmw-can-bus)
|
||||
- [Troubleshooting](#troubleshooting)
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Controller A (ESP32-S3-Touch-LCD-5B) receives BMW vehicle data via CAN Bus and transmits it to Controller B (ESP32-S3-LCD-1.3) via UART at 5Hz.
|
||||
|
||||
**Key Features:**
|
||||
- **LISTEN_ONLY mode** - Safe, non-intrusive monitoring (no transmission)
|
||||
- **500 Kbps baud rate** - Standard BMW CAN speed
|
||||
- **Real-time parsing** - Extracts temperature, gear, and voltage data
|
||||
- **Thread-safe** - Mutex-protected shared data structure
|
||||
- **Automatic fallback** - Uses dummy data when CAN is disabled
|
||||
|
||||
---
|
||||
|
||||
## Hardware Setup
|
||||
|
||||
### GPIO Pin Connections
|
||||
|
||||
```
|
||||
ESP32-S3-Touch-LCD-5B (Controller A)
|
||||
┌─────────────────────────────────┐
|
||||
│ │
|
||||
│ GPIO 15 (CAN_TX) ──────────┐ │
|
||||
│ GPIO 16 (CAN_RX) ──────────┼──► To CAN Transceiver
|
||||
│ GND ───────────────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────┘
|
||||
```
|
||||
|
||||
### CAN Transceiver Requirements
|
||||
|
||||
The ESP32-S3 TWAI peripheral requires an **external CAN transceiver** (e.g., TJA1050, MCP2551, SN65HVD230).
|
||||
|
||||
**Recommended Transceiver: SN65HVD230**
|
||||
- 3.3V compatible (ESP32-S3 logic level)
|
||||
- ISO 11898-2 compliant
|
||||
- Low power consumption
|
||||
|
||||
**Wiring Diagram:**
|
||||
|
||||
```
|
||||
ESP32-S3 SN65HVD230 BMW OBD-II / CAN Bus
|
||||
|
||||
GPIO 15 (TX) ───► D (TXD)
|
||||
GPIO 16 (RX) ◄─── R (RXD)
|
||||
3.3V ────────────► VCC
|
||||
GND ─────────────► GND
|
||||
CANH ───────────────► CAN High (Pin 6)
|
||||
CANL ───────────────► CAN Low (Pin 14)
|
||||
120Ω termination (only if at end of bus)
|
||||
```
|
||||
|
||||
**Important Notes:**
|
||||
- **Do NOT connect ESP32 GPIO pins directly to CAN bus** - you will damage the ESP32!
|
||||
- Use proper CAN transceiver rated for 12V automotive systems
|
||||
- Only add 120Ω termination resistor if you're at the physical end of the CAN bus
|
||||
- BMW OBD-II CAN is on pins 6 (CAN-H) and 14 (CAN-L)
|
||||
|
||||
---
|
||||
|
||||
## BMW CAN Message Specifications
|
||||
|
||||
These are the configured CAN message IDs and data formats for BMW vehicles.
|
||||
|
||||
### Message ID: 0x4F - Engine Coolant Temperature
|
||||
|
||||
**Format:** Standard 11-bit CAN ID
|
||||
**DLC:** 8 bytes
|
||||
**Update Rate:** ~100ms
|
||||
|
||||
| Byte | Description | Format | Example |
|
||||
|------|-------------|--------|---------|
|
||||
| 0 | Coolant Temp | Raw + 40°C offset | 0x55 = 85°C (0x55 - 40 = 45°C actual) |
|
||||
| 1-7 | Reserved | - | - |
|
||||
|
||||
**Parsing:**
|
||||
```cpp
|
||||
int16_t coolant_temp = can_to_temperature(data[0]); // Converts to 0.1°C units
|
||||
// Example: data[0] = 0x55 (85 raw) → (85 - 40) * 10 = 450 (45.0°C)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Message ID: 0x55 - Engine Oil Temperature
|
||||
|
||||
**Format:** Standard 11-bit CAN ID
|
||||
**DLC:** 8 bytes
|
||||
**Update Rate:** ~200ms
|
||||
|
||||
| Byte | Description | Format | Example |
|
||||
|------|-------------|--------|---------|
|
||||
| 0-6 | Reserved | - | - |
|
||||
| 7 | Oil Temp | Raw + 40°C offset | 0x84 = 132°C (92°C actual) |
|
||||
|
||||
**Parsing:**
|
||||
```cpp
|
||||
int16_t engine_oil_temp = can_to_temperature(data[7]);
|
||||
// Example: data[7] = 0x84 (132 raw) → (132 - 40) * 10 = 920 (92.0°C)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Message ID: 0x201 - Gearbox Oil Temperature
|
||||
|
||||
**Format:** Standard 11-bit CAN ID
|
||||
**DLC:** 8 bytes
|
||||
**Update Rate:** ~200ms
|
||||
|
||||
| Byte | Description | Format | Example |
|
||||
|------|-------------|--------|---------|
|
||||
| 0-2 | Reserved | - | - |
|
||||
| 3 | Gearbox Oil Temp | Raw + 40°C offset | 0x7D = 125°C (85°C actual) |
|
||||
| 4-7 | Reserved | - | - |
|
||||
|
||||
**Parsing:**
|
||||
```cpp
|
||||
int16_t gearbox_oil_temp = can_to_temperature(data[3]);
|
||||
// Example: data[3] = 0x7D (125 raw) → (125 - 40) * 10 = 850 (85.0°C)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Message ID: 0x1001 - Gearbox Data (Extended)
|
||||
|
||||
**Format:** Extended 29-bit CAN ID
|
||||
**DLC:** 8 bytes
|
||||
**Update Rate:** ~50ms
|
||||
|
||||
| Byte | Description | Values | Notes |
|
||||
|------|-------------|--------|-------|
|
||||
| 0 | Gear Position | 0=P, 1=R, 2=N, 3=D, 4-9=M1-M6 | Current selector position |
|
||||
| 1 | Current Gear | 1-8 | Actual engaged gear (0 if neutral) |
|
||||
| 2-7 | Reserved | - | - |
|
||||
|
||||
**Parsing:**
|
||||
```cpp
|
||||
uint8_t gear_position = data[0]; // P/R/N/D/M selector
|
||||
uint8_t current_gear = data[1]; // 1-8 for manual mode
|
||||
```
|
||||
|
||||
**Gear Position Enum:**
|
||||
```cpp
|
||||
typedef enum {
|
||||
GEAR_PARK = 0,
|
||||
GEAR_REVERSE = 1,
|
||||
GEAR_NEUTRAL = 2,
|
||||
GEAR_DRIVE = 3,
|
||||
GEAR_MANUAL_1 = 4,
|
||||
GEAR_MANUAL_2 = 5,
|
||||
GEAR_MANUAL_3 = 6,
|
||||
GEAR_MANUAL_4 = 7,
|
||||
GEAR_MANUAL_5 = 8,
|
||||
GEAR_MANUAL_6 = 9
|
||||
} gear_position_t;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Message ID: 0x101F - Battery Voltage (Extended)
|
||||
|
||||
**Format:** Extended 29-bit CAN ID
|
||||
**DLC:** 8 bytes
|
||||
**Update Rate:** ~1000ms
|
||||
|
||||
| Byte | Description | Format | Example |
|
||||
|------|-------------|--------|---------|
|
||||
| 0 | Voltage High Byte | MSB of 16-bit value | 0x04 |
|
||||
| 1 | Voltage Low Byte | LSB of 16-bit value | 0xD2 |
|
||||
| 2-7 | Reserved | - | - |
|
||||
|
||||
**Parsing:**
|
||||
```cpp
|
||||
uint16_t raw_voltage = (data[0] << 8) | data[1]; // Big-endian
|
||||
uint16_t battery_voltage = raw_voltage * 10; // Convert to 0.01V units
|
||||
// Example: data = [0x04, 0xD2] → 0x04D2 = 1234 raw → 12340 (12.34V)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Testing with CAN Simulators
|
||||
|
||||
Before connecting to a real vehicle, test the CAN Bus receiver using simulation tools.
|
||||
|
||||
### Option 1: Python-CAN with Virtual CAN (Linux)
|
||||
|
||||
**Setup Virtual CAN Interface:**
|
||||
|
||||
```bash
|
||||
# Load virtual CAN kernel module
|
||||
sudo modprobe vcan
|
||||
|
||||
# Create virtual CAN interface
|
||||
sudo ip link add dev vcan0 type vcan
|
||||
sudo ip link set up vcan0
|
||||
|
||||
# Verify interface
|
||||
ip link show vcan0
|
||||
```
|
||||
|
||||
**Python Test Script:**
|
||||
|
||||
Save as `bmw_can_simulator.py`:
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
BMW CAN Bus Simulator for ESP32-S3-Touch-LCD-5B Testing
|
||||
Sends realistic BMW CAN messages to test the receiver
|
||||
"""
|
||||
|
||||
import can
|
||||
import time
|
||||
import random
|
||||
|
||||
# Create virtual CAN bus
|
||||
bus = can.interface.Bus(channel='vcan0', bustype='socketcan')
|
||||
|
||||
def send_coolant_temp(temp_celsius=85):
|
||||
"""Send engine coolant temperature (CAN ID 0x4F)"""
|
||||
raw_value = int(temp_celsius + 40) # Add 40°C offset
|
||||
msg = can.Message(
|
||||
arbitration_id=0x4F,
|
||||
data=[raw_value, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
|
||||
is_extended_id=False
|
||||
)
|
||||
bus.send(msg)
|
||||
print(f"[0x4F] Coolant Temp: {temp_celsius}°C (raw: 0x{raw_value:02X})")
|
||||
|
||||
def send_engine_oil_temp(temp_celsius=92):
|
||||
"""Send engine oil temperature (CAN ID 0x55)"""
|
||||
raw_value = int(temp_celsius + 40)
|
||||
msg = can.Message(
|
||||
arbitration_id=0x55,
|
||||
data=[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, raw_value],
|
||||
is_extended_id=False
|
||||
)
|
||||
bus.send(msg)
|
||||
print(f"[0x55] Oil Temp: {temp_celsius}°C (raw: 0x{raw_value:02X})")
|
||||
|
||||
def send_gearbox_temp(temp_celsius=85):
|
||||
"""Send gearbox oil temperature (CAN ID 0x201)"""
|
||||
raw_value = int(temp_celsius + 40)
|
||||
msg = can.Message(
|
||||
arbitration_id=0x201,
|
||||
data=[0x00, 0x00, 0x00, raw_value, 0x00, 0x00, 0x00, 0x00],
|
||||
is_extended_id=False
|
||||
)
|
||||
bus.send(msg)
|
||||
print(f"[0x201] Gearbox Temp: {temp_celsius}°C (raw: 0x{raw_value:02X})")
|
||||
|
||||
def send_gear_position(position=3, current_gear=4):
|
||||
"""Send gearbox position and current gear (CAN ID 0x1001)"""
|
||||
msg = can.Message(
|
||||
arbitration_id=0x1001,
|
||||
data=[position, current_gear, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
|
||||
is_extended_id=True # Extended 29-bit ID
|
||||
)
|
||||
gear_names = ['P', 'R', 'N', 'D', '1', '2', '3', '4', '5', '6']
|
||||
print(f"[0x1001] Gear: {gear_names[position]}, Current: {current_gear}")
|
||||
bus.send(msg)
|
||||
|
||||
def send_battery_voltage(voltage_v=12.45):
|
||||
"""Send battery voltage (CAN ID 0x101F)"""
|
||||
raw_value = int(voltage_v * 100) # Convert to 0.01V units
|
||||
high_byte = (raw_value >> 8) & 0xFF
|
||||
low_byte = raw_value & 0xFF
|
||||
msg = can.Message(
|
||||
arbitration_id=0x101F,
|
||||
data=[high_byte, low_byte, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
|
||||
is_extended_id=True # Extended 29-bit ID
|
||||
)
|
||||
bus.send(msg)
|
||||
print(f"[0x101F] Battery: {voltage_v}V (raw: 0x{raw_value:04X})")
|
||||
|
||||
def main():
|
||||
"""Main simulation loop"""
|
||||
print("BMW CAN Simulator Started - Press Ctrl+C to stop")
|
||||
print("Configure ESP32 CAN interface to connect to vcan0 via USB-CAN adapter")
|
||||
print("-" * 60)
|
||||
|
||||
try:
|
||||
iteration = 0
|
||||
while True:
|
||||
iteration += 1
|
||||
print(f"\n[Iteration {iteration}]")
|
||||
|
||||
# Simulate realistic temperature variations
|
||||
coolant = 85 + random.randint(-3, 3)
|
||||
oil = 92 + random.randint(-2, 2)
|
||||
gearbox = 85 + random.randint(-2, 2)
|
||||
voltage = 12.45 + random.uniform(-0.2, 0.2)
|
||||
|
||||
# Send all messages
|
||||
send_coolant_temp(coolant)
|
||||
time.sleep(0.01)
|
||||
send_engine_oil_temp(oil)
|
||||
time.sleep(0.01)
|
||||
send_gearbox_temp(gearbox)
|
||||
time.sleep(0.01)
|
||||
send_gear_position(3, 4) # Drive, 4th gear
|
||||
time.sleep(0.01)
|
||||
send_battery_voltage(voltage)
|
||||
|
||||
# Update every 200ms (5Hz like UART transmission)
|
||||
time.sleep(0.2)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n\nSimulator stopped")
|
||||
bus.shutdown()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
**Run Simulator:**
|
||||
|
||||
```bash
|
||||
# Install python-can
|
||||
pip3 install python-can
|
||||
|
||||
# Run simulator
|
||||
python3 bmw_can_simulator.py
|
||||
```
|
||||
|
||||
**Connect ESP32 to Virtual CAN:**
|
||||
|
||||
You'll need a USB-CAN adapter (e.g., CANable, PCAN-USB) to bridge the virtual CAN to the ESP32's physical CAN pins.
|
||||
|
||||
---
|
||||
|
||||
### Option 2: Arduino CAN Transmitter
|
||||
|
||||
Use a second ESP32 or Arduino with CAN shield as a transmitter:
|
||||
|
||||
```cpp
|
||||
#include <driver/twai.h>
|
||||
|
||||
#define TX_PIN GPIO_NUM_5
|
||||
#define RX_PIN GPIO_NUM_4
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Configure TWAI for transmission
|
||||
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_PIN, RX_PIN, TWAI_MODE_NORMAL);
|
||||
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_500KBITS();
|
||||
twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
|
||||
|
||||
twai_driver_install(&g_config, &t_config, &f_config);
|
||||
twai_start();
|
||||
|
||||
Serial.println("CAN Transmitter Ready");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Send coolant temperature (85°C)
|
||||
twai_message_t msg1;
|
||||
msg1.identifier = 0x4F;
|
||||
msg1.data_length_code = 8;
|
||||
msg1.data[0] = 125; // 85 + 40 offset
|
||||
twai_transmit(&msg1, pdMS_TO_TICKS(100));
|
||||
|
||||
// Send engine oil temp (92°C)
|
||||
twai_message_t msg2;
|
||||
msg2.identifier = 0x55;
|
||||
msg2.data_length_code = 8;
|
||||
msg2.data[7] = 132; // 92 + 40 offset
|
||||
twai_transmit(&msg2, pdMS_TO_TICKS(100));
|
||||
|
||||
// Send gearbox temp (85°C)
|
||||
twai_message_t msg3;
|
||||
msg3.identifier = 0x201;
|
||||
msg3.data_length_code = 8;
|
||||
msg3.data[3] = 125; // 85 + 40 offset
|
||||
twai_transmit(&msg3, pdMS_TO_TICKS(100));
|
||||
|
||||
// Send gear position (Drive, 4th gear)
|
||||
twai_message_t msg4;
|
||||
msg4.identifier = 0x1001;
|
||||
msg4.extd = 1; // Extended ID
|
||||
msg4.data_length_code = 8;
|
||||
msg4.data[0] = 3; // Drive
|
||||
msg4.data[1] = 4; // 4th gear
|
||||
twai_transmit(&msg4, pdMS_TO_TICKS(100));
|
||||
|
||||
// Send battery voltage (12.45V)
|
||||
twai_message_t msg5;
|
||||
msg5.identifier = 0x101F;
|
||||
msg5.extd = 1; // Extended ID
|
||||
msg5.data_length_code = 8;
|
||||
msg5.data[0] = 0x04; // High byte
|
||||
msg5.data[1] = 0xD2; // Low byte (1234 = 12.34V)
|
||||
twai_transmit(&msg5, pdMS_TO_TICKS(100));
|
||||
|
||||
Serial.println("Sent CAN test messages");
|
||||
delay(200); // 5Hz update rate
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Connecting to Real BMW CAN Bus
|
||||
|
||||
### OBD-II Port Connection
|
||||
|
||||
**BMW OBD-II Pinout:**
|
||||
|
||||
```
|
||||
┌─────────────┐
|
||||
│ 1 2 3 4 │ Top Row
|
||||
└─────────────┘
|
||||
┌─────────────────┐
|
||||
│ 5 6 7 8 9 │ Bottom Row
|
||||
└─────────────────┘
|
||||
```
|
||||
|
||||
| Pin | Signal | Description |
|
||||
|-----|--------|-------------|
|
||||
| 6 | CAN-H | CAN Bus High (connect to transceiver CANH) |
|
||||
| 14 | CAN-L | CAN Bus Low (connect to transceiver CANL) |
|
||||
| 4, 5 | GND | Ground (connect to transceiver GND) |
|
||||
| 16 | +12V | Battery voltage (optional, can power CAN transceiver) |
|
||||
|
||||
**Connection Diagram:**
|
||||
|
||||
```
|
||||
BMW OBD-II Port CAN Transceiver ESP32-S3
|
||||
┌──────────────┐ ┌──────────────┐ ┌──────────┐
|
||||
│ │ │ │ │ │
|
||||
│ Pin 6 (CAN-H)│────────►│ CANH │ │ │
|
||||
│ │ │ │ │ │
|
||||
│ Pin 14(CAN-L)│────────►│ CANL │ │ │
|
||||
│ │ │ │ │ │
|
||||
│ Pin 4/5 (GND)│────────►│ GND ─────────┼────────►│ GND │
|
||||
│ │ │ │ │ │
|
||||
│ │ │ TXD ◄────────┼────────►│ GPIO 15 │
|
||||
│ │ │ │ │ │
|
||||
│ │ │ RXD ─────────┼────────►│ GPIO 16 │
|
||||
│ │ │ │ │ │
|
||||
│ │ │ VCC ◄────────┼────────►│ 3.3V │
|
||||
└──────────────┘ └──────────────┘ └──────────┘
|
||||
```
|
||||
|
||||
**Safety Checklist:**
|
||||
|
||||
- [ ] Use proper CAN transceiver (SN65HVD230 or TJA1050)
|
||||
- [ ] Verify 500 Kbps baud rate setting
|
||||
- [ ] Ensure LISTEN_ONLY mode is active (code already configured)
|
||||
- [ ] Double-check wiring before connecting to vehicle
|
||||
- [ ] Test with CAN simulator first
|
||||
- [ ] Monitor serial output for errors during initial connection
|
||||
|
||||
**Enabling CAN on ESP32:**
|
||||
|
||||
1. Power on ESP32-S3-Touch-LCD-5B
|
||||
2. Navigate to Settings screen
|
||||
3. Toggle **"Enable CAN Bus"** switch to ON
|
||||
4. Monitor serial output (115200 baud):
|
||||
|
||||
```
|
||||
[CANDrv] Initializing CAN subsystem...
|
||||
[CANDrv] CAN task created successfully on Core 0
|
||||
[CANTask] CAN task started on Core 0
|
||||
[CANTask] Starting CAN reception...
|
||||
[CANDrv] TWAI driver installed (GPIO15/GPIO16, 500Kbps, LISTEN_ONLY)
|
||||
[CANDrv] TWAI driver started
|
||||
[CANDrv] CAN alerts configured
|
||||
[CANTask] CAN reception active
|
||||
[CANDrv] ✓ Parsed CAN ID=0x4F (Standard format) [1/1 msgs parsed]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### No CAN Messages Received
|
||||
|
||||
**Symptoms:** CAN toggle is ON, but no messages appear in serial monitor.
|
||||
|
||||
**Solutions:**
|
||||
1. **Check Wiring:**
|
||||
- Verify CAN-H and CAN-L are not swapped
|
||||
- Check transceiver power (3.3V to VCC)
|
||||
- Ensure ground connection
|
||||
|
||||
2. **Verify Baud Rate:**
|
||||
- Confirm BMW CAN is 500 Kbps (most common)
|
||||
- Some older BMWs use 125 Kbps - try changing in `can_driver.h`:
|
||||
```cpp
|
||||
#define CAN_BAUD_RATE TWAI_TIMING_CONFIG_125KBITS()
|
||||
```
|
||||
|
||||
3. **Check Transceiver:**
|
||||
- Measure voltages: CAN-H ~3.5V, CAN-L ~1.5V (recessive state)
|
||||
- During activity: CAN-H/CAN-L should oscillate
|
||||
|
||||
4. **Serial Monitor Filtering:**
|
||||
- Only BMW-specific IDs are logged
|
||||
- Use `output_mode: content` in serial monitor to see all TWAI alerts
|
||||
|
||||
---
|
||||
|
||||
### CAN Bus Errors
|
||||
|
||||
**Symptoms:** Log shows bus errors or passive errors.
|
||||
|
||||
```
|
||||
[CANTask] Bus error detected (count: 128)
|
||||
[CANTask] TWAI controller has become error passive
|
||||
```
|
||||
|
||||
**Solutions:**
|
||||
1. **Check Termination:**
|
||||
- Remove 120Ω resistor if you're NOT at the end of the CAN bus
|
||||
- BMW CAN bus should already have termination
|
||||
|
||||
2. **Verify Logic Levels:**
|
||||
- ESP32 GPIO is 3.3V - ensure transceiver is 3.3V compatible
|
||||
- Do NOT use 5V transceiver without level shifters
|
||||
|
||||
3. **Inspect Physical Layer:**
|
||||
- Check for loose connections
|
||||
- Ensure twisted pair for CAN-H/CAN-L if using long wires
|
||||
- Keep wiring away from high-current circuits
|
||||
|
||||
---
|
||||
|
||||
### Wrong Data Values
|
||||
|
||||
**Symptoms:** Temperatures or voltages are incorrect.
|
||||
|
||||
**Solutions:**
|
||||
1. **Verify Message Format:**
|
||||
- BMW CAN data may use different scaling factors
|
||||
- Use CAN logger to inspect raw hex values
|
||||
- Compare with known good values from OBD-II scanner
|
||||
|
||||
2. **Check Endianness:**
|
||||
- Current implementation assumes big-endian for voltage
|
||||
- If values are way off, try little-endian:
|
||||
```cpp
|
||||
uint16_t raw_voltage = data[1] << 8 | data[0]; // Little-endian
|
||||
```
|
||||
|
||||
3. **Update Offsets:**
|
||||
- Temperature offset may vary by vehicle year
|
||||
- If temps are consistently off by a fixed amount, adjust in `automotive_data.h`:
|
||||
```cpp
|
||||
static inline int16_t can_to_temperature(uint8_t can_value, int16_t offset = -48) {
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Memory Issues
|
||||
|
||||
**Symptoms:** ESP32 crashes, resets, or CAN stops working after some time.
|
||||
|
||||
**Solutions:**
|
||||
1. **Check Heap:**
|
||||
- Monitor free heap: `ESP.getFreeHeap()`
|
||||
- Reduce CAN RX queue size if needed (currently unlimited)
|
||||
|
||||
2. **Stack Overflow:**
|
||||
- Increase CAN task stack size in `can_driver.h`:
|
||||
```cpp
|
||||
#define CAN_TASK_STACK_SIZE 8192 // Increase from 4096
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **Test with Simulator** - Verify CAN reception works before connecting to vehicle
|
||||
2. **Connect to OBD-II** - Use proper transceiver and safety precautions
|
||||
3. **Verify Data** - Compare readings with OBD-II scanner or instrument cluster
|
||||
4. **Tune Scaling** - Adjust temperature offsets and voltage scaling if needed
|
||||
5. **Document IDs** - Record any additional BMW CAN IDs you discover
|
||||
|
||||
---
|
||||
|
||||
## References
|
||||
|
||||
- ESP32 TWAI Driver: [Espressif Documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/twai.html)
|
||||
- ISO 11898-2: CAN Bus Physical Layer Standard
|
||||
- BMW CAN Bus: Check BMW TIS (Technical Information System) for your specific model year
|
||||
|
||||
---
|
||||
|
||||
**Last Updated:** 2025-01-09
|
||||
**Tested On:** ESP32-S3-Touch-LCD-5B with SN65HVD230 transceiver
|
||||
@@ -106,13 +106,13 @@ include/
|
||||
- Defines `automotive_data_t` structure (6 sensor values: gear position, 3 temperatures, battery voltage, fault codes)
|
||||
- UART packet framing protocol: `uart_packet_t` with start/end markers (0xAA/0x55), version byte, XOR checksum
|
||||
- Helper functions: `calculate_checksum()`, `validate_packet()`, temperature/voltage formatters
|
||||
- **BMW CAN Bus ID mappings**: Real BMW CAN message IDs and byte positions (see CAN_BUS_INTEGRATION.md)
|
||||
- UART config: 115200 baud on GPIO 43 (TX) / 44 (RX)
|
||||
- **BMW CAN Bus ID mappings**: 11-bit PT-CAN IDs verified live on the swap bus (evidence: `wiki/pages/can-id-candidates.md`)
|
||||
- UART config: 115200 baud on GPIO 44 (TX) / 43 (RX, unused) — leaves the board via the SP3485 RS485 transceiver
|
||||
|
||||
**include/drivers/can_driver.h/cpp**
|
||||
- CAN Bus driver using ESP32 TWAI (Two-Wire Automotive Interface)
|
||||
- Hardware: GPIO 15 (TX), GPIO 16 (RX) - 500 Kbps baud rate
|
||||
- Mode: LISTEN_ONLY (safe, won't transmit on vehicle CAN bus)
|
||||
- Mode: TWAI_MODE_NORMAL (ACKs frames; LISTEN_ONLY caused transmitter retry-flooding). Firmware never sends data frames
|
||||
- Parses BMW-specific CAN messages and updates shared automotive data structure
|
||||
- Task runs on Core 0 with FreeRTOS queue for start/stop commands
|
||||
|
||||
@@ -168,19 +168,18 @@ Settings persist across power cycles via ESP32 NVS (Non-Volatile Storage):
|
||||
**Transmission Protocol**:
|
||||
- Packet structure: `uart_packet_t` = Start(0xAA) + Version + Length + `automotive_data_t` + Checksum(XOR) + End(0x55)
|
||||
- Transmission rate: 5Hz (every 200ms) when enabled
|
||||
- Hardware: Serial1 on GPIO 43/44 (RS485 terminal block on board)
|
||||
- Hardware: Serial1 TX GPIO 44 / RX GPIO 43 (RS485 terminal block on board)
|
||||
|
||||
**Task Flow**:
|
||||
- `uartTask()` runs on Core 0
|
||||
- Events via `g_uart_event_queue`: `UART_EVENT_START`, `UART_EVENT_STOP`, `UART_EVENT_SEND_DATA`
|
||||
- Dummy data generation: `updateDummyData()` simulates sensor variations (for testing before CAN integration)
|
||||
- Default data: `initializeDefaultData()` seeds the structure until CAN updates it; the dummy generator was removed
|
||||
- Actual transmission: `sendUARTPacket()` builds packet, calculates checksum, sends via `Serial1.write()`
|
||||
- Mutex protection: `g_data_mutex` guards `g_automotive_data` structure
|
||||
|
||||
**CAN Bus Integration**:
|
||||
- CAN driver reads BMW-specific messages and updates `g_automotive_data`
|
||||
- When CAN is enabled, real vehicle data replaces dummy data
|
||||
- When CAN is disabled, dummy data simulation continues for testing
|
||||
- UART auto-starts/stops with the CAN task (`linkToCANState()`); no dummy simulation remains
|
||||
- Shared data structure (`g_automotive_data`) is mutex-protected for thread safety
|
||||
|
||||
### CAN Bus Architecture
|
||||
@@ -189,15 +188,17 @@ Settings persist across power cycles via ESP32 NVS (Non-Volatile Storage):
|
||||
- Controller: ESP32-S3 TWAI (Two-Wire Automotive Interface)
|
||||
- Pins: GPIO 15 (TX), GPIO 16 (RX)
|
||||
- Baud Rate: 500 Kbps (BMW standard)
|
||||
- Mode: LISTEN_ONLY (safe, non-intrusive monitoring)
|
||||
- Mode: TWAI_MODE_NORMAL (ACKs frames; never transmits data frames)
|
||||
|
||||
**BMW CAN Message IDs**:
|
||||
- `0x4F` [byte 0] → Engine Coolant Temperature
|
||||
- `0x55` [byte 7] → Engine Oil Temperature
|
||||
- `0x201` [byte 3] → Gearbox Oil Temperature
|
||||
- `0x1001` [byte 0] → Gearbox Position (P/R/N/D/S/M)
|
||||
- `0x1001` [byte 1] → Current Gear Number (1-8)
|
||||
- `0x101F` [bytes 0-1] → Battery Voltage (16-bit, big-endian)
|
||||
**BMW CAN Message IDs** (all 11-bit standard frames, verified live; full decode in `wiki/pages/can-id-candidates.md`):
|
||||
- `0x1D0` [byte 0] → Coolant temperature (raw − 48 °C); [byte 1] engine oil temp (reads 0xFF on this M57N); [byte 2 bits 4-5] engine run state
|
||||
- `0x0B5` [byte 7] → Gearbox oil temperature (raw − 40 °C); [byte 4 bits 6-7] cooling demand
|
||||
- `0x1D2` [byte 0] → Gear lever (E1=P D2=R B4=N 78=D/S/M); [byte 1] engaged gear; [byte 4] drive/sport/manual mode
|
||||
- `0x0BA` [byte 0 low nibble] → Gearbox target gear incl. reverse; [bits 6-7] converter lockup; [bytes 3-4] output shaft speed (scaling open)
|
||||
- `0x1A2` [bytes 0-1] → Turbine speed
|
||||
- `0x0AA` [bytes 4-5] → Engine RPM (× 0.25); [byte 3] pedal position
|
||||
- `0x0A8` [bytes 1-2] → Available engine torque
|
||||
- `0x3B4` [12-bit LE × 0.015] → Battery voltage; [byte 2 low nibble] ignition
|
||||
|
||||
**Task Flow**:
|
||||
- `canTask()` runs on Core 0 with Priority 1
|
||||
@@ -207,12 +208,10 @@ Settings persist across power cycles via ESP32 NVS (Non-Volatile Storage):
|
||||
- Statistics tracking: Messages received, parsed, errors
|
||||
|
||||
**Safety Features**:
|
||||
- LISTEN_ONLY mode prevents accidental CAN bus writes
|
||||
- No transmission capability - read-only monitoring
|
||||
- NORMAL mode: the controller ACKs received frames; the firmware has no transmit path for data frames
|
||||
- Error detection: Bus errors, queue overflow, passive errors
|
||||
- Graceful degradation: Falls back to dummy data if CAN fails
|
||||
|
||||
**See Also**: `.docs/CAN_BUS_INTEGRATION.md` for testing and development guide
|
||||
**See Also**: `wiki/pages/can-id-candidates.md` for the verified CAN ID map and evidence, `wiki/pages/can-bus-integration.md` for integration notes
|
||||
|
||||
### UI State Synchronization
|
||||
|
||||
@@ -328,8 +327,8 @@ xTaskCreatePinnedToCore(
|
||||
|
||||
### GPIO Assignments
|
||||
|
||||
- **CAN Bus**: GPIO 15 (TX), GPIO 16 (RX) - 500 Kbps, LISTEN_ONLY mode
|
||||
- **UART1**: GPIO 43 (TX), GPIO 44 (RX) - RS485 terminal block on board, 115200 baud
|
||||
- **CAN Bus**: GPIO 15 (TX), GPIO 16 (RX) - 500 Kbps, TWAI_MODE_NORMAL, onboard TJA1051 on the terminal block
|
||||
- **UART1**: GPIO 44 (TX), GPIO 43 (RX, unused) - reaches the terminal block only as the RS485 A/B pair (SP3485), 115200 baud
|
||||
- **USB Serial**: UART0 (default Serial) - 115200 baud for debug output
|
||||
|
||||
### Display Panel
|
||||
@@ -385,5 +384,5 @@ xTaskCreatePinnedToCore(
|
||||
|
||||
- **SquareLine Studio Export**: ALWAYS export UI files to `ui/` directory, NEVER to `src/` (prevents overwriting main.cpp)
|
||||
- **Event Handler Registration**: Event handlers for SquareLine UI elements are registered in `ui_Settings_Screen.c` auto-generated code. When adding new toggles, add event callback registration via `lv_obj_add_event_cb()` and declare handler in `ui_events.h`
|
||||
- **CAN Bus Integration**: BMW CAN IDs are configured in `automotive_data.h`. CAN driver runs in LISTEN_ONLY mode for safe monitoring. See `.docs/CAN_BUS_INTEGRATION.md` for testing with CAN simulators
|
||||
- **CAN Bus Integration**: BMW CAN IDs are defined in `automotive_data.h` (all 11-bit standard frames, verified live on the swap bus). The CAN driver runs in `TWAI_MODE_NORMAL` (it ACKs frames; not LISTEN_ONLY). Evidence and confidence labels live in `wiki/pages/can-id-candidates.md`
|
||||
- **Security**: Password field (`uic_Wifi_Passkey_TB`) is cleared after connection attempt for security (line 1015, 1029)
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
---
|
||||
type: index
|
||||
updated: 2026-07-17
|
||||
updated: 2026-09-21
|
||||
---
|
||||
|
||||
# Index
|
||||
@@ -33,3 +33,4 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
|
||||
- [[gear-box-can-revealings]] — **gear fully decoded & VERIFIED** (2026-07-16/17): `0x1D2` byte0 = lever, **byte1 = engaged gear 1–6**, byte4 = Drive/Sport/Manual mode; `0x0BA` = the box's own target gear incl. **reverse**; raw at `raw/gear_box_can_revealings.csv` + `raw/gearbox_engaged_gear.csv`
|
||||
- [[can-capture-2026-07-17-drive]] — **first capture with the vehicle moving** (2026-07-17): verifies `0x0BA` gears 2nd–6th directly (making it a complete gear source), catches the lockup clutch live, and produces the ×0.125 output-shaft scaling evidence; raw at `raw/log_20260717_145930.txt`
|
||||
- [[e65-reverse-engineering-repo]] — **E65 per-ID DBC-style docs (ingested 2026-07-17)** — the highest-value source yet: settled the gearbox-temp offset (raw−40) and battery layout (12-bit ×0.015), proved the engine was running in our capture, and revealed turbine speed, output shaft, pedal position and cruise state
|
||||
- [[esp32-s3-touch-lcd-5-intro-photo]] — Waveshare annotated board photo (moved into `raw/` 2026-09-21): terminal-block signal order (VIN/GND/VOUT · SDA/SCL · CAN · RS485 A/B · DO0/DO1 · DI), shared CAN/RS485 120 Ω switch, IO0/IO3/IO4/IO46 strapping pads
|
||||
|
||||
@@ -41,3 +41,11 @@ User pointed at `HeinrichG-V12/E65_ReverseEngineering` (per-ID DBC-style docs, w
|
||||
## [2026-07-16] ingest | First live CAN capture — research map CONFIRMED
|
||||
|
||||
First real dump off the swap's bus, taken with the board's **own new raw-frame logger** (`(repo)`; USB-CDC stream, serial mutex, ~486 frame/s, ~1.4% line loss). Raw filed at `raw/can-capture-2026-07-15-gearshift.csv` (20,596 frames) → [[can-capture-2026-07-15]]. Findings: 15 IDs live incl. **all four researched signal IDs** (0x1D0, 0x1D2, 0x0B5, 0x3B4) + bonus 0x0AA/0x0BA; firmware's placeholder IDs (0x4F/0x55/0x201/0x1001/0x101F) **verified absent**; researched-but-absent: 0x130/0x304/0x192. **0x1D0 b0** drifts 0x55→0x58 (coolant −48, ~37→40 °C); **0x1D0 b1 = 0xFF** (oil temp unpopulated). **0x1D2 gear encoding resolved**: DLC 6, byte0 whole-byte codes (0xE1=P, 0xB4=N, 0x78=D seen live). **0x3B4** at ~5 s rate but payload dormant (0xFF) — engine state unconfirmed. Updated [[can-id-candidates]], [[can-bus-integration]], [[esp32-s3-touch-lcd-5b]], [[open-questions]], index. Also corrected a firmware fact across pages: driver runs **`TWAI_MODE_NORMAL` (ACKs the bus), not LISTEN_ONLY**; TJA1051 is non-isolated → must share vehicle ground. Next: cold-start + confirmed-engine-running capture to lock coolant/battery scaling; use differential (per-position) captures for gear.
|
||||
|
||||
## [2026-09-21] update | .docs folder retired; UART spec moved to docs/; board photo ingested
|
||||
|
||||
The repo's `.docs/` folder was deleted (user decision). `CAN_BUS_INTEGRATION.md` documented the dead placeholder IDs and an external transceiver the board does not need — superseded by [[can-id-candidates]] and [[can-bus-integration]]. `UART_PROTOCOL.md` (the packet spec, shared with Controller B) moved to `docs/UART_PROTOCOL.md` as the single copy; Controller B's duplicate was removed. The annotated board photo moved to `raw/` → [[esp32-s3-touch-lcd-5-intro-photo]]: confirms the terminal-block order, that GPIO 44 exits only as the RS485 A/B pair, and that one 120 Ω switch serves both CAN and RS485. Root `CLAUDE.md` corrected: verified CAN ID list replaces the placeholders, `TWAI_MODE_NORMAL` replaces "LISTEN_ONLY", UART TX is GPIO 44 (was written as 43), dummy-data references removed.
|
||||
|
||||
**Missing source**: the schematic PDF (`ESP32-S3-Touch-LCD-5-Sch.pdf`) was in `.docs/` at the start of the 2026-09-21 session and was not on disk by the time of this cleanup (never git-tracked). Its net list was read earlier that session and is reflected in [[esp32-s3-touch-lcd-5b]]; re-download it into `raw/` — still on the sourcing wishlist in [[open-questions]].
|
||||
|
||||
Sibling wiki instantiated today at `../../ESP32-S3-LCD-1.3/wiki/` for Controller B (link, redundancy, gauge outputs). Cross-references from there use the text form `(sibling: 5B wiki → page)`.
|
||||
|
||||
|
Before Width: | Height: | Size: 184 KiB After Width: | Height: | Size: 184 KiB |
@@ -0,0 +1,29 @@
|
||||
---
|
||||
type: source
|
||||
tags: [hardware, waveshare, board-layout]
|
||||
updated: 2026-09-21
|
||||
raw: raw/ESP32-S3-Touch-LCD-5-details-intro.jpg
|
||||
---
|
||||
|
||||
# Waveshare annotated board photo (ESP32-S3-Touch-LCD-5, Rev 1.1)
|
||||
|
||||
`raw/ESP32-S3-Touch-LCD-5-details-intro.jpg` — Waveshare's numbered component photo of the board's rear, moved here from the repo's former `.docs/` folder on 2026-09-21 (that folder was deleted). Board silkscreen reads "ESP32-S3-Touch-LCD-5 Rev 1.1, 800×480 / 1024×600 Pixels".
|
||||
|
||||
## What it shows (read from the image, 2026-09-21)
|
||||
|
||||
- ESP32-S3-WROOM-1 module (1), TF card slot (2), USB-C (3), BOOT (4) and RESET (5) buttons
|
||||
- **Strapping-pin solder pads** (6) labelled IO0 · IO3 · IO4 · IO46 next to a "PWM GND" pad pair — matches the schematic's strapping/backlight-PWM section
|
||||
- LCD FPC connector (8), touch FPC (7)
|
||||
- **16-way 3.5 mm terminal block** (13–19) silkscreened, left→right: `VIN GND VOUT | SDA SCL | CAN_L CAN_H | 485_B 485_A | DO0 DO1 | DI_COM GND DI0 DI1` — i.e. power, I2C, CAN, RS485, the two isolated outputs, and the two isolated inputs. This is the physical proof that **GPIO 44 leaves the board only as the RS485 A/B pair**, not as a TTL pin.
|
||||
- **120 Ω termination switch** (9) labelled "CAN / RS-485, OFF / ON" — one switch serves both buses
|
||||
- Battery switch (10) and MX1.25 battery connector (11); DONE / CHG / PWR LEDs (12); RTC coin cell (21); "2C" I2C address / voltage pads near the USB port (20)
|
||||
|
||||
## Relevance
|
||||
|
||||
- Confirms the terminal-block signal set and that the RS485 pair is the only UART1 exit → `(sibling: 1.3 wiki → controller-link)` open question #1 on how the wire to Controller B is really made
|
||||
- Confirms one shared termination switch for CAN and RS485 — keep it **OFF** when tapping the vehicle CAN bus, which also leaves the RS485 link unterminated on this end
|
||||
- Strapping pads IO0/IO3/IO4/IO46 exist as solder points — the only bare GPIO access on the board, and all four are already committed (G3, VSYNC, CTP_IRQ, HSYNC)
|
||||
|
||||
## Related
|
||||
|
||||
[[esp32-s3-touch-lcd-5b]] · [[esp32-s3-touch-lcd-5b-waveshare-wiki]] · [[dual-controller-architecture]]
|
||||
Reference in New Issue
Block a user