cannot read exteneded CANBus frames in FlexCAN

Status
Not open for further replies.

bobobobo

Member
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:View attachment CANTest1e.ino

My code to (primarily) writes the frames is in CANTest2e:View attachment 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.
 
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
 
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!
 
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:
Hi tonton81,
I'm using FlexCan Library for some time now, communicating with all kinds of ECU, Standard-CAN and CAN_FD. There are several ECU that send lots of different messages, 11bit and 19bit ID mixed. Is there any way to filter MB0 recveiving with three ID at once,
i.E. 0x0AD, 0x17FE0077 and 0x1C420077? Because receiving all the other frames jams my application sometimes.

Thanks in advance!
 
@Ralsi , it may be possible on that library but not everyone got it working with filters, I suggest you use FlexCAN_T4 and the setMBFilter() to assign an ID to a mailbox. Those 3 IDs are far apart you will get many if not all other frames in as well so better to put them in a separate mailbox. Define jam? are you using events()? if you use events() and your loop had delays or slow code you will certainly loose frames if the queue overflows, not using events() makes it run the fastest
 
Status
Not open for further replies.
Back
Top