Page 1 of 1

CAN-Bus API multiple filter configuration

Posted: Wed Aug 15, 2018 2:21 pm
by gunar.kroeger
I see that a few days ago a new commit was made to the idf that included a driver for the CAN-bus module
I already tested it and it works well but I couldn't find out how to set multiple acceptance filters

currently I am using

Code: Select all

#define CAN_FILTER_CONFIG_ACCEPT_ALL()  {.acceptance_code = 0, .acceptance_mask = 0xFFFFFFFF, .single_filter = true}
and filtering per software.

And I understand how to use a single filter based on this. But how do I implement multiple filters, for a list of ids?

could someone provide me with a small example?


Re: CAN-Bus API multiple filter configuration

Posted: Thu Aug 16, 2018 2:30 pm
by ESP_Dazz
See the Acceptance Filter section of the docs.

What essentially when you set

Code: Select all

single_filter = false
is that theacceptance_code and acceptance_mask will be interpreted differently by the CAN peripheral. Therefore instead using a 32-bit value to define a single code/mask, the each 32-bit value will be used to define two codes/masks. See the docs to see how the 32-bit code/masks are interpreted under single/dual filter mode when receiving standard/extended messages.

To filter out multiple IDs, you'll need to bit wise XNOR each of your IDs to find which bit positions of the multiple IDs conflict (where one ID has a 1 in that position, and another has a 0). Then for those bit positions, set them as don't care using the acceptance mask. Then for the non conflicting bit positions, you can set it as your acceptance code.

For example
ID1 = 101 1010 0000
ID2 = 101 1010 0001
ID3 = 101 1010 0010
ID4 = 101 1010 0100
ID5 = 101 1010 1000
ID6 = 101 1110 0000
ID7 = 101 0010 0000

The XNOR would be
XNOR = 111 0011 0000
This means the zero bits of the XNOR are places which you need to set as don't care in your acceptance mask.

Hence the acceptance mask and code would be
MASK = 000 1100 1111
CODE = 101 XX10 XXXX where X means "don't care" since those bits conflict and are hence masked out by the acceptance mask

Re: CAN-Bus API multiple filter configuration

Posted: Mon Aug 20, 2018 9:24 pm
by gunar.kroeger
And is there a way to change the acceptance filter on the fly?
Or do I have to reinstall the driver?


Re: CAN-Bus API multiple filter configuration

Posted: Wed Aug 29, 2018 11:41 am
by ESP_Dazz
Current CAN driver implementation requires the driver to be reinstalled.
On the hardware level, the CAN must enter reset mode (will disconnect CAN peripheral from the bus) before any configuration registers can be modified.

Re: CAN-Bus API multiple filter configuration

Posted: Fri Aug 31, 2018 12:33 pm
by dmaxben
Why cant you just do a simple software setup?


if (rx_frame.MsgID == 0x123)
read the message in and do something with it.

Re: CAN-Bus API multiple filter configuration

Posted: Fri Aug 31, 2018 1:21 pm
by gunar.kroeger
I want to reduce the load on the cpu as much as possible so that other tasks (like logging onto the SD card, wifi and compressing data) can utilize it more.
For now I will set hw filters for all possible message ids i could receive and software filters for every id that I want to receive.

Thanks :D