wiki: Ingest E60 VFL CAN spreadsheet + PID-request Arduino reference

This commit is contained in:
2026-07-15 17:16:27 +02:00
parent 6770bf111b
commit 662266e875
16 changed files with 1834 additions and 4 deletions
+2
View File
@@ -26,3 +26,5 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
## Sources
- [[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
+4
View File
@@ -10,6 +10,10 @@ Created schema (`CLAUDE.md`), `index.md`, `log.md`, and five seed pages built fr
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.
+7 -4
View File
@@ -12,12 +12,12 @@ Findings from the 2026-07-15 deep-research run (95 claims extracted from ~15 sou
| Signal | CAN ID | Bytes | Scaling | Sender | Rate | Confidence |
|--------|--------|-------|---------|--------|------|------------|
| Coolant temp | **0x1D0** | byte 0 | °C = raw − 48 | DME/DDE | 100 ms | **High** — verified verbatim in E65 docs, present in E90-gen DBC, confirmed live on a real E60 545i, and an E60 tool32 table lists 0x1D0 "Motordaten" from DDE1 (diesel!) |
| 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 "Status Gang" (event-driven, from E60 tool32 table) |
| 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 confirms, sender DDE1), layout must be settled on bench |
| 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 |
@@ -42,6 +42,8 @@ Also useful: an E60 forum claim `(unverified)` that arbitration IDs are identica
## 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
@@ -52,7 +54,8 @@ Also useful: an E60 forum claim `(unverified)` that arbitration IDs are identica
## 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) and the M57 dieslg8 project (different chassis generation). Engine-side layouts are inferred from petrol DME captures of the same bus generation.
- 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.
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
@@ -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
*/
+36
View File
@@ -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,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.