Teensy 3.6 CANBUS filter and mask

Status
Not open for further replies.

ted

Active member
Hi,

I want my teensy to listen only one CAN ID. I use the following code:

Code:
#include <FlexCAN.h>

void setup() {
  Can0.begin();
  Serial.begin(115200);
  CAN_filter_t test_filter;
  test_filter.id = 0x1F; //0b00011111; ID 31
  test_filter.flags.extended = 0;
  test_filter.flags.remote = 0;

  for (int c = 0; c < 14; c++) {
    Can0.setMask(0x1FFFFFFF, c);
    //Can0.setMask(0b00011111111111111111111111111111, c);
  }
  Can0.setFilter(test_filter, 0);
  Can0.setFilter(test_filter, 1); // without this does not work
}

void loop() {
  CAN_message_t inMsg;
  while (Can0.available()) {
    Can0.read(inMsg);
    print_can_message(inMsg);
  }
}


void print_can_message(CAN_message_t msg) {
  Serial.print(msg.id);
  Serial.print(": ");
  for (int i = 0; i < 8; i++) {
    Serial.print(msg.buf[i]);
    Serial.print(" ");
  }
  Serial.println();
}

My problem is that I have to set at least two mailboxes for the same filter to work. Is it a bug or why is that?
The can interface is MCP2562, with Flexcan (collin80) library.

Thanks!
 
Status
Not open for further replies.
Back
Top