I’ve been reading the github readme tonight and playing with filters. I’m using the FIFO example to receive my messages. The readme suggests,
myCan.setFIFOFilter(REJECT_ALL);
to reject all messages then,
myCan.setFIFOFilter(0, 0x123, STD); // Set filter0 to allow STANDARD CAN ID 0x123 to be collected by FIFO.
myCan.setFIFOFilter(1, 0x456, EXT); // Set filter1 to allow EXTENDED CAN ID 0x456 to be collected by FIFO.
I’ve tested this with my Cansniffer software and arduino sending messages to the teensy and it works fine as far as I can see. Setting a range also works.
myCan.setFIFOFilterRange(0, 0x112,0x119, STD);
for instance.
I’m not quite grasping the mailbox, FIFO thing yet, or the differences anyway.
So that’s filtering on the ID where the message is sent from, right?
@CommonRail thanks for the explanation. So you could have different mailboxes receiving based on different filters and you can trigger different code for those
I don’t understand it all either. However I know that both the FIFOs and the Mailboxes are in the chipset itself (in the Teensy’s CAN circuitry), not the library. The Mailboxes use up slots in the FIFO. FIFOs use up Mailboxes. Not quite sure what the use cases are.
According to this discussion (regarding the MK61FX512VMJ15 chip), Mailboxes are coarser filters than FIFOs. Apparently multiple filters can work on a mailbox such that messages with different CAN IDs go to the same mailbox, whereas FIFOs are fine grain, only allowing one ID per FIFO (do I have that right?). I still don’t understand it, honestly. But maybe one of you can shed light on this given the discussion I linked to. If I read it right, FIFOs are actually made from Mailboxes under the hood…
And maybe it is dependent on how the CAN stuff is implement on the chip you’re working with.
As I understand it, filtering is on the CAN ID itself, which when used with j1939 includes the source id, the destination id, and the PGN (all of that is in the 29-bit ID).
Maybe it’s more about data storage in general (nothing to do with CAN modules) like all your doing is filling a buffer to read later in both cases.
In the PLC world there is many ways to organise your buffer. LIFO, FIFO, Mailbox.
FIFO (first in, first out) if the filter lets the message through and say there was 5 messages waiting we have to get the first one (or oldest one).
Mailbox is a more organised buffer, we can add more filters to each mailbox. Then if we had 5 messages waiting we can clear/read messages from a more important mailbox first and read the less important ones when we have time.
I guess it’s always FIFO. Then default is one giant mailbox. And if you set it up you can use multiple mailbox’s to help sort everything out in a very busy system.
Another example would be if there is only one person / program doing everything mailbox is not needed.
But if there is multiple people / departments inside the program then each department can just work through messages only intended for them (in there mailbox) rather than the main program chopping and changing its logic to suit the current message, I’m not very good with computers but maybe that’s how you can split off and can run two programs at once through two computer processor cores?
Thinking about J1939 in general. So I have a message such as 0x0CFE3122 CAN ID and I’d want to filter based on the source address (34 = 0x22). So if I want to set up filter for that source address, would I filter like this?
myCan.setFIFOFilter(1, 0x22, EXT);
But if I’d want to filter on the byte 0x31 i.e. the PS field in the CAN ID, how to do that? Should it be like
myCan.setFIFOFilterRange(1,0x3100, 0x31FF, EXT);
Getting the hardware finally today, trying to get bit started up front, hence the stupid questions
I get I can filter with full ID but what I’m wanting is filter on specific part of the ID, sort of wildcards…
Once you’ve got two controllers talking to each other on the bench it is a lot easier to test what happens that’s for sure!
I’m sure there is much more capable software about but I’ve been using this simple software written by this guy. Skip to the end to see it working but interesting video on python and qt !!
With the most recent version (I think the version included in Teensyduino doesn’t have this function) of FlexCAN_T4, you can use setMBUserFilter/setFIFOUserFilter ( Masking and Filtering for J1939 Source Addresses · Issue #9 · tonton81/FlexCAN_T4 (github.com))
I’m using it like this for example: vbus.setMBUserFilter(MB0, 0x2CF0, 0xFFFF);
However, I’ve had problems with more than 16bit mask/filter or mask not being all F’s…
Oh I see. Looks like the mask is the same principle as a regular TCP/IP network mask. I understand them but don’t ask me how to compute them from scratch!
CAN messages not coming through despite matching the filter. But I have to check on that again, I might have had the FIFO to accept all, so the message landed in the FIFO and not in the mailbox i wanted it to be.
Yes, but the MCP2515 Module i bought is not working right, i can’t get any Canbus data. Although i tried about 10 different Arduino codes, but no one seems to help. So i think i should buy 2 new ones and get em to talk to each other on the bench before trying to decode our Deutz.
Before i tried to sniff the Canbus from our John Deere Machines but i didn’t get any valuable data.
Edit: What kind of module/shield would you suggest?