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

Thread: cannot read exteneded CANBus frames in FlexCAN

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    11

    cannot read exteneded CANBus frames in FlexCAN

    Greetings. I am running a pair of 3.2's using CollinK's latest FlexCAN implementation. I can, between these two 3.2's, exchange standard CANbus frames all day long. Both sides can happily read and write such frames.

    But...when I write an extended frame, well, the writing 3.2 happily writes it. My CANbus analyzer sees it on the bus. But the reading 3.2 device never reports the extended frame as ingested.

    I added some counters to the FlexCAN::message_isr() function. These counters increment when the ISR is invoked, and when various legs of code in the ISR are taken. The counters tell me that what should be incoming extended frames never trigger an ISR. So it's not that the receiving 3.2 gets the extended frames and discards them; it's that the 3.2 that should receive the extended frames *acts as if such frames were never emitted by the other 3.2*.

    My code to (primarily) read the frames is in CANTest1e:CANTest1e.ino

    My code to (primarily) writes the frames is in CANTest2e:CANTest2e.ino

    In both the above tests, when an extended frame is emitted, an asterisk is printed. The above tests need the Serial Monitor to be instanced in order to begin running. The manifest "HAS_rascnt" is only defined in versions of FlexCAN in which my interrupts counters exist.

    Thanks.

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,020
    the filters/masks need to be set to receive extended frames
    if you have FIFO enabled you dont need to do this step if its catching all messages with a cleared global mask (0x0) and filter(0).

    In mailbox mode, the bit on the mailbox has to be toggled to accept extended frames. The mailbox bit has nothing to do with the mask/filter, it only identifies whether it can accept extended OR standard frames.

    you can try a newer library called IFCT for teensy, which allows a greater control over all these features, plus more

  3. #3
    Junior Member
    Join Date
    Feb 2019
    Posts
    11
    I am now using the IFCT library. It's Good Stuff as it works for receiving extended frames. Thanks for the pointer.

    However, it strikes me as odd that, in order to receive extended frames using IFCT, I need to invoke the following methods at setup() time:
    enableFIFO()
    enableFIFOInterrupt()
    intervalTimer()
    Am I wrong in stating that, in order to receive extended frames, the above methods must be invoked? If not, shouldn't all frames be received as soon as Can0.begin() is called? If I am wrong, what is the preferred technique for enabling receipt of extended frames?

    Thanks again!

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,020
    ok, the FIFO by default, the way IFCT is written accepts all frames by default as the mask/filter is set to accept all traffic, and like i mentioned there is no extended bits in the FIFO it accepts both standard and extended frames based off the filter criteria, which is blank by default as set by the library.

    For the non FIFO example, you would need to configure the mailbox using:

    Can0.setMB(MB8, RX, EXT);

    this converts mailbox 8 to accept only extended frames, and filter/mask is based on extended frames only after that. You are not forced to use intervalTimer as the library has 3 ways to run, in setup(): Can0.intervalTimer() Can0.teensyThreads();, in loop: IFCT::events(); But dont run them all together, choose only 1.



    The way IFCT was written for default usage in non-FIFO environment, 4 first mailboxes were set to standard, then 4 for extended, and the remaining 8 were set to transmit mailboxes. The layout can be changed by the user via the sketch but these were the defaults I used to make it easier for the user to be up and running without issues.

    You could always play around with the automatic filters when you’ll need them.
    Code:
    Can0.setMBFilter(REJECT_ALL); // blocks all traffic from all mailboxes
    Can0.setMBFilter(ACCEPT_ALL); // accepts all traffic to mailboxes
    Can0.setMBFilter(MB8, 0x123); // accepts only ID 0x123 to be received in mailbox
    Can0.setMBFilterRange(MB8, 0x1,0x3); // accepts a range of IDs (0x1,0x2,0x3)
    Can0.setFIFOFilter(0, 0x123, 0x125); // accepts 2 IDs into FIFO filter 0. (FIFO has 8 filters 0-7 by default)
    
    Can0.mailboxStatus(); //this can show you the layout of your mailboxes/FIFO in serial monitor, to know if FIFO is used or not, and what your mailboxes are (RX/TX) and whether they accept standard or extended frames
    Can0.begin() is not part of IFCT because the configs are already done via construction of Can0. the moment you enable the interrupt and set a callback, intervaltimer will pull those frames from the input queue buffer and feed them to your callback.
    Last edited by tonton81; 04-10-2019 at 02:43 PM.

Posting Permissions

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