Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read the dtc codes #10

Open
shivpj opened this issue Aug 12, 2021 · 9 comments
Open

How to read the dtc codes #10

shivpj opened this issue Aug 12, 2021 · 9 comments

Comments

@shivpj
Copy link

shivpj commented Aug 12, 2021

Hello,
How to read the dtc codes?

int OBD2Class::ReadDtcs(uint8_t mode, void* data, int length)
{
// make sure at least 60 ms have passed since the last response
unsigned long lastResponseDelta = millis() - _lastPidResponseMillis;
if (lastResponseDelta < 60) {
delay(60 - lastResponseDelta);
}
for (int retries = 10; retries > 0; retries--) {
if (_useExtendedAddressing) {
CAN.beginExtendedPacket(0x18db33f1, 8);
} else {
CAN.beginPacket(0x7df, 8);
}
CAN.write(0x02); // number of additional bytes
CAN.write(mode);
//CAN.write(pid);
if (CAN.endPacket()) {
// send success
break;
} else if (retries <= 1) {
return 0;
}
}
bool splitResponse = (length > 5);
for (unsigned long start = millis(); (millis() - start) < _responseTimeout;) {
if (CAN.parsePacket() != 0 &&
(splitResponse ? (CAN.read() == 0x10 && CAN.read()) : CAN.read()) &&
(CAN.read() == (mode | 0x40))) {

  _lastPidResponseMillis = millis();

  // got a response
  if (!splitResponse) {
    return CAN.readBytes((uint8_t*)data, length);
  }
  int read = CAN.readBytes((uint8_t*)data, 3);
  for (int i = 0; read < length; i++) {
    delay(60);

    // send the request for the next chunk
    if (_useExtendedAddressing) {
      CAN.beginExtendedPacket(0x18db33f1, 8);
    } else {
      CAN.beginPacket(0x7df, 8);
    }
    CAN.write(0x30);
    CAN.endPacket();
    // wait for response
    while (CAN.parsePacket() == 0 ||
           CAN.read() != (0x21 + i)); // correct sequence number
    while (CAN.available()) {
      ((uint8_t*)data)[read++] = CAN.read();
    }
  }
  _lastPidResponseMillis = millis();
  return read;
}

}

return 0;
}

I have added a function like this. While running this function, there is no output. could you please suggest any changes.

Thanks

@shivpj
Copy link
Author

shivpj commented Aug 13, 2021

Hello,
Is the above code is correct to read the stored dtc codes?

@se-pulvirenti
Copy link

hi,
you removed the pids byte, try the following:
CAN.write(0x01); // number of additional bytes

@shivpj
Copy link
Author

shivpj commented Sep 5, 2021

hi,
you removed the pids byte, try the following:
CAN.write(0x01); // number of additional bytes

Thanks for the response, I tried but the above function returned zero (0). I used this PID to get the status of the DTC codes.
Capture3
It returned "516352" value. As per below table.
image
How should I encode this value.

@se-pulvirenti
Copy link

Hi,
I tried on my car, it returns 0 but actually I don't have DTC code, like in your case:
516352 = binary 00000000 00000111 11100001 00000000
A = 00000000
B = 00000111
C = 11100001
D = 00000000
A7 is 0 (it means that the warning light on the dashboard is off)
A6-A0 is 0 (no DTCs)

@fsu-icx
Copy link

fsu-icx commented Jul 5, 2023

Hi,
Could you please provide an example as to how this function can be used to read DTCs?
I don't understand the arguments I have to pass, besides 0x03 to select mode 3.

Thanks !

@skndungu
Copy link

skndungu commented Jul 6, 2023

That function is incomplete to read DTCs you have to do more work than what is done there

@fsu-icx
Copy link

fsu-icx commented Jul 6, 2023

Thank you for the reply!

Yes this is what I suspected, sadly I don't have the skill to complete the function, I tried but I'm too far off :)

Too bad Sandeep's great library doesn't provide this feature though.

Cheers!

@BenjaminMuslic
Copy link

Can someone look into implementing reading DTCs?

@skndungu
Copy link

skndungu commented Oct 7, 2024

@BenjaminMuslic it's way complicated that it seems and more so custom to each vehicle make, apart from OBD2 emmission related DTCs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants