Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Having issues with setting filters with the FlexCAN library!

  1. #1
    Junior Member
    Join Date
    Apr 2019
    Posts
    2

    Having issues with setting filters with the FlexCAN library!

    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,

  2. #2
    Junior Member
    Join Date
    Apr 2019
    Posts
    2
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •