Skip to content
szotyi007 edited this page Mar 6, 2017 · 7 revisions

If you want to receive only a specific CAN ID, you need to set the filter at least for two mailboxes:

#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();
 }

Hopefully, it will be fixed soon. Thanks!

Clone this wiki locally