handmade0octopus / ESP32-TWAI-CAN

ESP32 driver for TWAI / CAN for adruino
MIT License
38 stars 11 forks source link

ESP32C3 Super Mini + SN65HVD230 Issue #6

Closed IAmOrion closed 3 weeks ago

IAmOrion commented 2 months ago

I have an "ESP32C3 Super Mini" from AliExpress and a SN65HVD230 Module.
I commented out the send because I'm testing this setup as a can bus sniffer.

When I run this, even if I don't change any code, the RECEIVING part gets about 10-20 frames and then appears to stop responding entirely

  if(ESP32Can.readFrame(rxFrame, 1000)) {
    Serial.println(F("Data"));
      // Comment out if too many frames
      Serial.printf("Received frame: %03X  \r\n", rxFrame.identifier);
      if(rxFrame.identifier == 0x540) {   // Standard OBD2 frame responce ID
        uint8_t currentGear = (uint8_t) ( (rxFrame.data[7] & (0x0FU)) );
        Serial.print(F("-- Current Gear Selected: ")); if (currentGear == 0) { Serial.print(F("N")); } else { Serial.print(currentGear); } Serial.println(F(" --"));
      }
  } else {
    Serial.println(F("No Data"));
  }

With the above code, after receiving a handful on frames, it just stops. The sketch itself is working as the serial monitor repeats "No Data" so it's not crashed - it's just seemingly stopped receiving data.

I added a secondary monitor to check the can data and it's flowing beautifully and as expected. So I'm not sure why this library seemingly locks out. Unless it's due to something about the SN65HVD230 that I'm unaware of - but that wouldn't make sense either, since I also tested this with a can "player" so it's basically just looping a bunch of recorded can data. If I reset the SENDER (give it a few seconds before resetting) then I can see more data in the serial again before it once again stops.

It's as if there's a full queue, or the can data is too fast, or something else is causing it to get stuck like some kind of bottle neck in the library.

handmade0octopus commented 1 month ago

@IAmOrion sorry for late reply.

Seems like it may be queue being full although it shouldn't make it stop.. Have you played with it further? I don't see anything in library that may be a problem, is your termination on CAN bus ok?

Also try to comment out this line and check only for IDs that you care about:

Serial.printf("Received frame: %03X  \r\n", rxFrame.identifier);