AVR(AT90CAN128)공부2010. 10. 21. 17:08


>> - socket 1: sender ID 0x7df, receiver ID 0x7e8
>> - socket 2: sender ID 0x7e8, receiver ID 0x7e0



진단기의 송신 명령 형식
머리문자 (C0 + 명령 수), 목적지 (33), 전송원 (F1), 명령(PID) ~ PID번호(0x??,,,0x??), 첵섬,
송신 코드 예는 0xC1(header, length=1), 0x33(dest), 0xF1(src), 0x81(connect request), 0x66(crc)을 송신한다, 

명령수가 1 이라면 머리문자는 C1 으로 된다. 머리문자 0xC1은 기능주소이고 0x81은 물리주소이다,
명령을 받는 장치의 주소는 0x33 이고, 보내는 장치의 주소는 0xF1 이다, 전송 내용은 0x81(통신시작을 요청)이다. 
시작명령 A(0x41)는 40을 더하면 0x81을 송신한다.  명령 0x81은 통신시작을 요청하는 식별자(ID)이다
CRC는 0x00으로 시작하여 머리문자부터 CRC를 제외한 모든 문자값을 더한 1바이트 검사자(Checksum)이다.
 
ECU의 응답 형식
머리 (80 + 데이터 수), 목적지(F1), 전송원(01), 데이터(40 + 명령0) ~ 응답(XX) xN, 첵섬(머리~명령 끝), 
응답코드 예는, 0x83(headrer), 0xF1(dest), 0x01(src), 0xC1(OK), 0xE9(kb1), 0x8F(kb2), 0xAE(crc)로 들어온다.

머리문자 0x83은 물리주소 3 이다, 받는 장치주소는 0xF1, 보내는 장치주소는 0x01의 머리문자 3개로 구성되며, 
응답 0xC1은 통신요청을 승락하는 식별자(ID)이다. 실제로 받는 전송값은 2 바이트로 KB1 =0xE9, KB2 =0x8F 이다,
실지 KB 값 0x8FE9는 일반 타이밍, 목적주소, 발송주소를 포함을 의미한다. 다른 값이면 포맷이 틀려진다.
 
예를 들면, 머리는 데이터 길이가 3이면 0x80 +3 =0x83, 차량의 고장이 없으면 OK =0xC1 , 이어서 KB1, KB2를 응답,
만일 고장이 있다면, 응답코드는 0xC1(OK)은 0x7F(FAIL)로 바뀌어 들어온다.
그외에 ECU는 0x80 (통신중지의 요청)이 들어오면, 0xC2(통신중지의 요청을 수락)로 응답한다.


명령/응답 코드의 예
머리문자 + 목적지 + 전송지 + 명령 0 + 첵섬 ---> 머리 + 목적지 + 전송지 + 응답0 + 응답1 + 응답2 + 첵섬
 C1      33           F1         81       66   --->  83        F1       01        C1        E9    8F     AE
len=1  수신자   전송자  통신시작 CRC --->len=3   수신자  전송자 통신수락  KB1  KB2   CRC  

ID는 2 바이트 이며,1 바이트는 모드, 1바이트는 ID다. 모드 01~0F는 SAE J1979 규격과 일치한다.
PID 모드 00~09 : http://www.avrtools.co.kr/technote7/board.php?board=download&command=body&no=97
PID 모드 10~85 : 참조 : http://prj.perquin.com/obdii/

Mode

 PID가 ECU로 요청하는 목적

 PID가 요청하는 데이터 혹은 목적

 10  Start Diagnostic Session 자기진단 기능을 시작한다
 11  ECU Reset ECU를 리셋한다
 12  Read Freeze Frame Data 저장된 고장코드(DTC)를 읽는다
 13  Read Diagnostic Trouble Codes 현재의 고장코드를 읽어 온다 
 14  Clear Diagnostic Information 저장된 고장코드(DTC)를 지운다 
 17  Read Status of Diagnostic Trouble Codes 고장코드(DTC)에서 Status를 읽는다
 18  Read Diagnostic Trouble Codes By Status ECU Status에서 고장코드(DTC)를 읽는다 
 1A  Read Ecu Id ECU의 ID를 읽는다 
 20  Stop Diagnostic Session 자기진단 기능을 중지한다
 21  Read Data By Local Id Local ID로 데이터를 읽는다
 22  Read Data By Common Id Common ID로 데이터를 읽는다
 23  Read Memory By Address 특정한 주소의 메모리를 읽는다
 25  Stop Repeated Data Transmission 연속 데이터 전송을 중지한다
 26  Set Data Rates 전송속도를 변경한다 
 27  Security Access 안전 잠금을 한다
 2C  Dynamically Define Local Id Local ID를 동적으로 정의 
 2E  Write Data By Common Id Common ID로 데이터를 저장한다 
 2F  Input Output Control By Common Id Common ID로 입출력을 제어한다 
 30  Input Output Control By Local Id Local ID로 입출력을 제어한다  
 31  Start Routine By Local ID Local ID로 함수를 시작한다
 32  Stop Routine By Local ID Local ID로 함수를 정지한다 
 33  Request Routine Results By Local Id Local ID로 시작한 함수의 실행결과를 요구한다
 34  Request Download ECU에서 데이터를 묶음으로 읽는다 
 35  Request Upload ECU로 데이터 묶음을 저장한다.
 36  Transfer data 데이터의 전송을 요구한다
 37  Request transfer exit 데이터 전송을 중지한다
 38  Start Routine By Address ECU를 특정 주소부터 실행한다
 39  Stop Routine By Address ECU를 특정 주소에서 정지한다
 3A  Request Routine Results By Address ECU를 특정 주소부터 실행한 결과를 요청한다
 3B  Write Data By Local Id  Local ID로 데이터를 저장한다
 3D  Write Memory By Address 특정 주소의 메모리에 전송값을 저장한다.
 3E  Tester Present  
 81  Start Communication 통신시작을 요청
 82  Stop Communication 통신중지를 요청
 83  Access Timing Parameters 타이밍 값을 요청
 85  Start Programming Mode ECU 셋업, (L-line을 사용한다) 





 



차량 진단용 OBD스케너를 WiFi 모듈을 이용하여 제작하여 OBD2WiFi 보드를 테스트 했다. Main MCU는 CAN통신도 가능하고 저렴하면서 성능좋는 STM32를 이용하였다.

OBD제작 정리
OBD 데이터를 얻기 위해 CAN통신으로 쿼리를 보내고 그에 대한 응답을 받으면 된다.
1) Host의 CAN ID를  11bit ID 0x7DF 로 설정한다.
2) CAN데이터를 PID리스트에 따라 만들어서 전송한다.
 ex) 차량 엔진온도 : 02 01 05 00 | 00 00 00 00 (데이터바이트:Show:엔진온도 PID)
3)정상적으로 전달되면 0x7E8(ECU)에서 응답이 온다.
 ex)[ID 7E8(0):00:08] : 03 41 05 41 | aa aa aa aa
 - 응답 코드에서 03은 의미있는 데이터수 이고 41은 01(mode) + 40(request) 를 의미 한다. 05는 PID값으로 엔진온도 이고, 마지막 41이 온도값을 나타낸다.


OBD 쿼리 데이터 형식



OBD 응답 형식



OBD2WiFi 테스트 결과
OBD스케너를 이용하여 차량의 속도를 연속적으로 출력 하는 예제 테스트 결과
AutoMode:
[ID 7E9(0):00:08] : 03 41 0d 00 | aa aa aa aa
[ID 7E9(0):00:08] : 03 41 0d 00 | aa aa aa aa
[ID 7E9(0):00:08] : 03 41 0d 00 | aa aa aa aa
[ID 7E9(0):00:08] : 03 41 0d 00 | aa aa aa aa
[ID 7E9(0):00:08] : 03 41 0d 00 | aa aa aa aa
[ID 7E9(0):00:08] : 03 41 0d 00 | aa aa aa aa
[ID 7E9(0):00:08] : 03 41 0d 00 | aa aa aa aa

출처 : http://nexp.tistory.com/category/%5BINTERFACE%5D/WiFi



OBD PID 모음 http://en.wikipedia.org/wiki/OBD-II_PIDs




 







SET ID 7E8 이후 Polling





Tester Commands


request and response packet diagram format:
cmd0 cmd1 ... -> result0 result1 ...   comment
Note: only the data of the request and only the result of the response are show.

yy 00 -> xx xx xx xx   bitmask of capabilities for mode yy, bit7 represents pid 1, bit6 pid 2, etc, if
data4:bit0 is set then pid 20 contains capabilities for pid 21-40


00-0F: SAE J1979 Diagnostic Test Modes
01 00 -> xx xx xx xx capabilites
01 01 -> [b7: MIL light, b0-6: dtc count] [b4-7: readiness] [b5: o2monitoring] [b0-7: readiness]
01 03 -> xx xx  Fuel System Status bitmap b0:Open, b1:Closed, b2:Open-Driving, b3:Open-Fault, b4:Closed-Fault
01 04 -> xx     Calculated Load Value % x*100.0/255
01 05 -> xx     Engine Coolant Temperature C x-40
01 06 -> xx     Short term fuel trim Bank 1 % x*(100.0/128)-100
01 07 -> xx     Long  term fuel trim Bank 1 % x*(100.0/128)-100
01 08 ->        Short term fuel trim Bank 2 % x*(100.0/128)-100
01 09 ->        Long  term fuel trim Bank 2 % x*(100.0/128)-100
01 0a ->        Fuel Pressure kPaG x*3
01 0b -> xx     Intake Manifold Pressure kPaA x
01 0c -> xx xx  Engine RPM RPM x*0.25
01 0d -> xx     Vehicle Speed km/h x
01 0e -> xx     Ignition timing advance Cyl #1 deg X*0.5-64
01 0f -> xx     Intake Air Temperature C X-40
01 10 -> xx xx  Air Flow Rate gm/s X*0.01
01 11 -> xx     Absolute Throttle Position % X*(100.0/255)
01 12 -> xx     Commanded secondary air status
01 13 -> xx     Oxygen sensor locations bitmap b0=sensor1, b1=sensor2, ..., b7=sensor8
01 14 -> xx yy  Bank 1 Sensor 1 Voltage/Trim V, % x*0.005, if y!=ff then y*(100.0/128)-100)
01 15 -> xx yy  Bank 1 Sensor 2 Voltage/Trim V, % x*0.005, if y!=ff then y*(100.0/128)-100)
01 16 ->        Bank 1 Sensor 3 Voltage/Trim V, % x*0.005, if y!=ff then y*(100.0/128)-100)
01 17 ->        Bank 1 Sensor 4 Voltage/Trim V, % x*0.005, if y!=ff then y*(100.0/128)-100)
01 18 ->        Bank 2 Sensor 1 Voltage/Trim V, % x*0.005, if y!=ff then y*(100.0/128)-100)
01 19 ->        Bank 2 Sensor 2 Voltage/Trim V, % x*0.005, if y!=ff then y*(100.0/128)-100)
01 1a ->        Bank 2 Sensor 3 Voltage/Trim V, % x*0.005, if y!=ff then y*(100.0/128)-100)
01 1b ->        Bank 2 Sensor 4 Voltage/Trim V, % x*0.005, if y!=ff then y*(100.0/128)-100)
01 1c -> xx     Auxiliary Input Status bitmap b0:PTO Active
01 20 -> xx xx xx xx capabilities
01 21 -> xx xx


02 00 00 -> xx xx xx xx capabilites SMART: 2 3 4 5 6 7 b c d
02 02 00 -> [dtc1h] [dtc1l]         DTC that caused freezeframe


03 -> [dtc1h] [dtc1l] 00 00 00 00


05 00 00 -> xx xx xx xx capabilites


06 00 -> xx xx xx xx capabilites

06 yy -> [max=01,min=81] [valH] [valL] [limitH] [limitL]  example 01 00 23 01 2c is value 23 (=35 dec)
with limit maximum 12c (=300 dec)

06 01 -> xx xx xx xx xx   ncms
06 02 -> xx xx xx xx xx   ncms
06 09 -> 01 xx xx xx xx -> 81 xx xx xx xx  ncms


07 -> 00 00 00 00 00 00   cms


08 00 00 00 00 00 00 -> xx xx xx xx capabilites SMART: none


09 00 -> 01 30 00 00 00   capabilites  5 bytes???


10 Start Diagnostic Session
11 ECU Reset
12 Read Freeze Frame Data
13 Read Diagnostic Trouble Codes
14 Clear Diagnostic Information
17 Read Status Of Diagnostic Trouble Codes
18 Read Diagnostic Trouble Codes By Status
1A Read Ecu Id
20 Stop Diagnostic Session
21 Read Data By Local Id
22 Read Data By Common Id
23 Read Memory By Address
25 Stop Repeated Data Transmission
26 Set Data Rates
27 Security Access
2C Dynamically Define Local Id
2E Write Data By Common Id
2F Input Output Control By Common Id
30 Input Output Control By Local Id
31 Start Routine By Local ID
32 Stop Routine By Local ID
33 Request Routine Results By Local Id
34 Request Download
35 Request Upload
36 Transfer data
37 Request transfer exit
38 Start Routine By Address
39 Stop Routine By Address
3A Request Routine Results By Address
3B Write Data By Local Id
3D Write Memory By Address
3E Tester Present
81 -> xx xx Start Communication
82 Stop Communication
83 Access Timing Parameters
85 Start Programming Mode


Response Failure Codes


10 General Reject
11 Service Not Supported
12 Sub Function Not Supported - Invalid Format
21 Busy - repeat Request
22 Conditions Not Correct Or Request Sequence Error
23 Routine Not Complete Or Service In Progress
31 Request Out Of Range
33 Security Access Denied - security Access Requested
35 Invalid Key
36 Exceed Number Of Attempts
37 Required Time Delay Not Expired
40 Download Not Accepted
41 Improper Download Type
42 Can Not Download To Specified Address
43 Can Not Download Number Of Bytes Requested
50 Upload Not Accepted
51 Improper Upload Type
52 Can Not Upload From Specified Address
53 Can Not Upload Number Of Bytes Requested
71 Transfer Suspended
72 Transfer Aborted
74 Illegal Address In Block Transfer
75 Illegal Byte Count In Block Transfer
76 Illegal Block Trasnfer Type
77 Block Transfer Data Checksum Error
78 Request Correcty Rcvd - Rsp Pending
79 Incorrect Byte Count During Block Transfer
80 Service Not Supported In Active Diagnostic Mode
C1 Start Comms +ve response
C2 Stop Comms +ve response
C3 Access Timing Params +ve response
81-8F Reserved
90-F9 Vehicle manufacturer specific
FA-FE System supplier specific
FF Reserved by document


Sample scan obtained of a SMART FOR TWO car


--wakeup
81 -> e9 8f
--get capabilities
01 00 -> b2 3f f8 11     capabilities service 1: 1 3 4 5 6 7 b v d e f 10 11 12 13 14 15 1c 20
01 20 -> 80 00 00 00     capabilities service 1: 21
02 00 00 -> 7e 38 00 00  capabilities service 2: 2 3 4 5 6 7 b c d
05 00 00 -> 7f 05 11     capabilities service 5: none
06 00 -> ff c0 80 00     capabilities service 6: 1 2 3 4 5 6 7 8 9 a 11
08 00 00 00 00 00 00 -> 7f 08 11    capabilities service 8: none
09 00 -> 01 30 00 00 00  ???? expected 4 byte response...
--get status
01 01 -> 01 07 69 00     MIL light off, 1 dtc, ready, no 02monotoring
--get dtc's
03 -> 07 02 00 00 00 00  dtc P0702
--scan sensors
01 03
01 04
01 05 -> 3a  engine coolant temp = 18C (3a=58 dec - 40 dec)
01 06
01 07
01 0b
01 0c
01 0d
01 0e
01 0f
01 10
01 11
01 12
01 13 -> 03   2 sensors
01 14
01 15
01 1c
01 20 -> 80 00 00 00   (always same: capabilities 21-40)
01 21 -> 00 37

Posted by 초동