Skip to content

Issue with Can Bus Filter ID's #32

Closed
@Nikhil0351

Description

@Nikhil0351

Thanks, Sandeep Mistry for the Library!

I need a little help with my Code.
I am working with an ESP32 and a TCAN334. We are facing issue with Filtering Ids. we are using the sample code provided with the library.
Without filter we are getting the data over can bus. But when we apply filters we did not receive any data.
we checked with the library, and ACR registers are correctly set.

We are trying filter with 0x18daf110 (Honda Jazz)

#include <CAN.h>

const bool useStandardAddressing = false;


void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("CAN Receiver");

  // start the CAN bus at 500 kbps
  if (!CAN.begin(500E3)) {
    Serial.println("Starting CAN failed!");
    while (1);
  }


  if (useStandardAddressing) {
    CAN.filter(0x7E8);
  } else {

    CAN.filterExtended(0x18daf110  );

  }
}

void loop() {

  if (useStandardAddressing) {
    CAN.beginPacket(0x7DF, 8);
  } else {
    CAN.beginExtendedPacket(0x18db33f1, 8);
  }

  int packetSize = CAN.parsePacket();

  if (packetSize) {
    // received a packet
    Serial.print("Received ");

    if (CAN.packetExtended()) {
      Serial.print("extended ");
    }

    if (CAN.packetRtr()) {
      // Remote transmission request, packet contains no data
      Serial.print("RTR ");
    }
    Serial.print("packet with id 0x");
    Serial.print(CAN.packetId(), HEX);
    if (CAN.packetRtr()) {
      Serial.print(" and requested length ");
      Serial.println(CAN.packetDlc());
    } else {
      Serial.print(" and length ");
      Serial.println(packetSize);
      // only print packet data for non-RTR packets
      while (CAN.available()) {
        Serial.print((char)CAN.read(), HEX);
      }
      Serial.println();
    }
    Serial.println();

  }

maybe someone can help me out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions