Communication with the ELM327¶
The ELM327 is a translator between a serial text interface and the OBD-II buses of the
vehicle. obd-diag sends it text commands and reads its responses up to the prompt >.
The basis is the datasheet ELM327DSJ (firmware v2.1, Sources).
Line¶
Serial, 8 data bits, no parity, 1 stop bit; 38400 or 115200 baud.
Every command is upper-case ASCII without spaces and ends with exactly one CR (
\r). A lone CR would repeat the last command and is therefore forbidden (datasheet p. 9, Command reference).The adapter answers with lines separated by CR and finishes with
>.Before every write,
SerialTransportempties the input buffer so that no old response is taken for the new one.
Course of a session¶
sequenceDiagram
participant T as obd-diag
participant E as ELM327
participant F as Vehicle
T->>E: ATZ
E-->>T: ELM327 v1.5 >
T->>E: ATE0, ATL0, ATS0, ATH0, ATSP0
E-->>T: OK > (per command)
T->>E: 0100 (up to 30 s)
E->>F: protocol search, then 01 00
F-->>E: 41 00 …
E-->>T: SEARCHING... 4100BE3FA813 >
T->>E: ATDPN, ATDP
E-->>T: A6 > / AUTO, ISO 15765-4 (CAN 11/500) >
T->>E: ATRV
E-->>T: 12.4V >
T->>E: 03, 07, 0A, 0101, 020200, 0902 …
Step |
Command |
Purpose |
|---|---|---|
Reset |
|
adapter as after power-on; the last response line is the identification |
Echo off |
|
the adapter no longer repeats the command |
Linefeed off |
|
only CR as line end |
Spaces off |
|
|
Headers off |
|
only the data, without CAN ID |
Protocol automatic |
|
the search starts with the first OBD request; does not write to the EEPROM |
Negotiate the protocol |
|
supported PIDs; answered by every OBD-II vehicle |
Report the protocol |
|
number ( |
Battery voltage |
|
voltage at the OBD socket |
All commands with datasheet page and quote are listed in the Command reference.
Timeouts¶
Case |
Timeout |
Reason |
|---|---|---|
every command |
10 s |
if a control unit reports |
first |
30 s |
the protocol search tries several protocols; with K-Line a single connection setup already takes 2 to 3 s (p. 33, 36) |
trouble codes after |
keep reading up to 5 s |
without sending again |
clearing after |
keep reading up to 10 s |
mode 04 is never repeated |
Detecting the protocol¶
Whether the vehicle speaks CAN decides how trouble code responses are read
(Response formats). obd-diag asks ATDPN:
6toC(also with a leadingAfor “found automatically”) is CAN,1to5are older protocols (J1850, ISO 9141-2, KWP2000).If the adapter reports
0,?or nonsense,0100is repeated once if there was no answer, andATDPNis asked again.If the number remains unclear,
0100is sent once with headers (ATH1), and their form shows whether it is CAN 11 bit, CAN 29 bit or an older protocol. The protocol name then carries the addition “according to headers …”.
Cleaning up responses¶
Before evaluating, Elm327.command removes:
the echo of the command, also in a different spelling (
at dpnforATDPN), but only before the actual response;status lines
SEARCHING...andBUS INIT: ...OK;empty lines, null bytes and lines of pure garbage (some clones send e.g. a byte
FCafterATZ).
Then:
Response |
Result |
|---|---|
|
no control unit answered; |
|
the adapter does not know the command ( |
|
|
|
|
hex data |
on to Response formats |
An unplugged adapter (input/output error) becomes TransportError (“Connection to …
lost”), missing responses become TransportTimeout. Both abort the procedure; after
that nothing more is sent.