CANBUS Masking and Filtering

at commandsccanembedded

I am using a module to convert CAN to UART. This module has 2 programmable masks and 6 programmable filters.

There are 13 message IDs that come in over the CAN bus and I only want 9 of them. The IDs are as follows.

The messages I dont want :

 - 0x404
 - 0x6f1
 - 0x114
 - 0x11c

The ones I do want :

 - 0x36C
 - 0x33C 
 - 0x34C 
 - 0x35C 
 - 0x314 
 - 0x31C 
 - 0x324 
 - 0x32C 
 - 0x37C

I have found masking quite confusing and I would love if someone could help me better my understanding of it. Would I set my mask to 0x3ff or 0x300? Then the 0x11c messages will come in?

Best Answer

If you want as many as 9 out of 13, then acceptance masking is pretty pointless. It is generally an overrated feature of CAN from the time before "mailbox" CAN controllers were invented. The main use of masking is when you expect a whole lot (hundreds) of identifiers on the bus that you aren't interested in.

Acceptance masking tends to make things needlessly complicated, which in turn leads to bugs. In this case you don't need to use neither masks nor mailboxes, just an identifier look-up table in software and sufficiently regular checks of the CAN rx buffers. Keep it simple.