Having issues with setting filters with the FlexCAN library!

Status
Not open for further replies.

tadzio93

Member
Hey guys, I've been using the FlexCAN library for some time now, but never used hardware filters. Trying to implement them now, but am having some issues.

  • Tool: Teensy 3.6
  • FlexCAN version: the one included in the most recent Teensyduino

EDIT:
My testing method is that I have a CAN2.0 device sending out a frame every 50ms with ID 0x720. I seem to always be getting these frames no matter how I set up my filter and mask.


Code:
CAN_filter_t hs_filter;
hs_filter.ext = 0;
hs_filter.rtr = 0;
hs_filter.id = 0x5FF;
 
Can0.begin(500000);

for (int c = 0; c < 14; c++) // 14 is from NUM_MAILBOXES - numTxMailboxes
{
   Can0.setMask(0xFFFF, c); // setMask takes uint32_t mask variable.  0xFFFF should only accept the one ID.
   Can0.setFilter(hs_filter, c);
}

I have also tried editing the FlexCAN.cpp. When I run the Can0.begin, it initializes with a defaultFilter of 0,0,0 for ext, rtr, and id respectively, as well as setting each mask to 0.

Code:
  CAN_filter_t defaultFilter;
  defaultFilter.ext = 0;
  defaultFilter.rtr = 0;
  defaultFilter.id = 0;
  for (int c = 0; c < NUM_MAILBOXES - numTxMailboxes; c++)
  {
     setMask(0, c);
     setFilter(defaultFilter, c);
  }

I changed this to:

Code:
CAN_filter_t defaultFilter;
defaultFilter.ext = 0;
defaultFilter.rtr = 0;
defaultFilter.id = 0x5FF;
for (int c = 0; c < NUM_MAILBOXES - numTxMailboxes; c++)
{
   setMask(0xFFFF, c);
   setFilter(defaultFilter, c);
}

Still no luck.

If anyone has any advice I would greatly appreciate it! I looked to Paul's github, but it seems to be an older version of the FlexCAN library.

Thanks, :)
 
I figured I'd reply and say I found the issue!

The mask value in setMask is uint32_t which should be 0xFFFFFFFF, NOT 0xFFFF.

Once I made this change, I was able to filter for just that ID.
 
Status
Not open for further replies.
Back
Top