CAN-Bus API multiple filter configuration

User avatar
gunar.kroeger
Posts: 127
Joined: Fri Jul 27, 2018 6:48 pm

CAN-Bus API multiple filter configuration

Postby gunar.kroeger » Wed Aug 15, 2018 2:21 pm

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?

Thanks
"Running was invented in 1612 by Thomas Running when he tried to walk twice at the same time."

ESP_Dazz
Posts: 171
Joined: Fri Jun 02, 2017 6:50 am

Re: CAN-Bus API multiple filter configuration

Postby ESP_Dazz » Thu Aug 16, 2018 2:30 pm

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

User avatar
gunar.kroeger
Posts: 127
Joined: Fri Jul 27, 2018 6:48 pm

Re: CAN-Bus API multiple filter configuration

Postby gunar.kroeger » Mon Aug 20, 2018 9:24 pm

And is there a way to change the acceptance filter on the fly?
Or do I have to reinstall the driver?

Thanks
"Running was invented in 1612 by Thomas Running when he tried to walk twice at the same time."

ESP_Dazz
Posts: 171
Joined: Fri Jun 02, 2017 6:50 am

Re: CAN-Bus API multiple filter configuration

Postby ESP_Dazz » Wed Aug 29, 2018 11:41 am

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.

dmaxben
Posts: 57
Joined: Thu Nov 16, 2017 6:04 pm

Re: CAN-Bus API multiple filter configuration

Postby dmaxben » Fri Aug 31, 2018 12:33 pm

Why cant you just do a simple software setup?

ie

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

User avatar
gunar.kroeger
Posts: 127
Joined: Fri Jul 27, 2018 6:48 pm

Re: CAN-Bus API multiple filter configuration

Postby gunar.kroeger » Fri Aug 31, 2018 1:21 pm

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
"Running was invented in 1612 by Thomas Running when he tried to walk twice at the same time."

Who is online

Users browsing this forum: No registered users and 46 guests