View previous topic :: View next topic |
Author |
Message |
championx
Joined: 28 Feb 2006 Posts: 151
|
CAN BUS - RX length |
Posted: Wed Jan 05, 2011 9:13 am |
|
|
Hi! I have a question about CanBus.
I logged data from a vehicle, and I got some strings where the rx_len byte is bigger than 8... So.. my question is: it is possible that the ecu transmits more than 8 bytes of data in one string?
Here is the logged data:
| ID | b1 b2 b3 b4 b5 b6 b7 b8 | rx_len byte
Data: | 373854793 | 074 094 000 000 000 000 000 000 | 02 ***
Data: | 373854793 | 078 010 000 000 000 000 000 000 | 02 ***
Data: | 00001684 | 074 094 036 157 071 249 109 124 | 09 ***
Data: | 00001684 | 079 010 036 188 191 000 000 014 | 15 ***
Data: | 00001684 | 075 126 036 157 071 249 109 124 | 08 ***
Data: | 00001684 | 074 094 036 188 191 000 000 014 | 14 ***
Data: | 00001684 | 078 010 036 157 071 249 109 124 | 08 *** |
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
Re: CAN BUS - RX length |
Posted: Wed Jan 05, 2011 9:29 am |
|
|
championx wrote: | Hi! I have a question about CanBus.
I logged data from a vehicle, and I got some strings where the rx_len byte is bigger than 8... So.. my question is: it is possible that the ecu transmits more than 8 bytes of data in one string?
|
No, those values are what is known in the industry as "filthy lies." ;-) One cannot send more than 8 data bytes in a canbus frame. One can, however, say that they are sending 0-15 bytes. It's just not true if it's 9-15. I have no idea why your ECU is lying like that. It might mean something to the other components but it's not standard. |
|
|
championx
Joined: 28 Feb 2006 Posts: 151
|
|
Posted: Wed Jan 05, 2011 9:32 am |
|
|
Thanks for your reply! So, you think this code is ok?
Code: |
lectura_can()
{
struct rx_stat rxstat;
int32 rx_id;
int8 rx_len;
int8 buffer[8]={0};
if(can_kbhit()==true)
{
if(can_getd(rx_id, &buffer[0], rx_len, rxstat))
{
fprintf(PC,"\n\rData: | %08lu | %03u %03u %03u %03u %03u %03u %03u %03u | %02u",rx_id,buffer[0],buffer[1],buffer[2],buffer[3],buffer[4],buffer[5],buffer[6],buffer[7],rx_len);
}
}
return;
} |
|
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
|
Posted: Wed Jan 05, 2011 9:34 am |
|
|
Yeah that's pretty much how it should look. |
|
|
championx
Joined: 28 Feb 2006 Posts: 151
|
|
Posted: Wed Jan 05, 2011 9:35 am |
|
|
Thanks collink! so you have any experience on automotive can bus?? |
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
|
Posted: Wed Jan 05, 2011 10:00 am |
|
|
championx wrote: | Thanks collink! so you have any experience on automotive can bus?? |
Well, if you are talking about internal combustion engine cars then some. Mostly I have experience with electric vehicle canbus. It's somewhat the same thing but a lot of EV hardware does not use quite as complicated of a protocol as ICE cars use. |
|
|
championx
Joined: 28 Feb 2006 Posts: 151
|
|
Posted: Wed Jan 05, 2011 11:21 am |
|
|
thats great! do you have some example code to read rpm, fuel level or some other PIDs?
thanks! |
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
|
Posted: Wed Jan 05, 2011 11:39 am |
|
|
championx wrote: | thats great! do you have some example code to read rpm, fuel level o some other PIDs?
thanks! |
No, but if you've already got canbus working then you should be able to figure it out my looking at a resource like:
http://en.wikipedia.org/wiki/OBD-II_PIDs
That shows the canbus ID to send to (0x7DF), the address it should respond from (0x7E9-0x7EB typically), the way to format the frames, etc.
For instance: To ask the car what the current RPM reading is you do this:
Send to canbus ID 0x7DF a packet with 8 data bytes. For whatever reason you'd basically always say you are sending 8 bytes even if you aren't. You really only need three bytes for this request (the other 5 can be). The three are:
0x02 (the number of additional bytes)
0x01 (mode 1)
0x0C (RPM reading)
Upon receiving this request the car should respond (likely from address 0x7E8 as that's the main ECU) with an 8 byte frame that has the following data bytes:
0x04 (sending three bytes after this one)
0x41 (responding to a mode 0x01 request)
0x0c (The request was for RPMs)
0x?? (the two data bytes for the RPM value)
0x?? (The first one is the MSB, this one is LSB. The whole thing gets / 4)
Make sense? |
|
|
|