arduino-CAN icon indicating copy to clipboard operation
arduino-CAN copied to clipboard

ESP32 - only 1 extended filter working, is it possible to specify multiple filters?

Open rosak opened this issue 1 year ago • 13 comments

First of, thank you very much for that useful library.

Now:

CAN.filterExtended(0x04394000);
CAN.filterExtended(0x06214000);

No matter how many filters I set it only reads the last one, is it the library limitation or am I doing something wrong?

Thanks in advance.

rosak avatar Oct 12 '23 22:10 rosak

I added the dual filter.

silk-indus avatar Nov 23 '23 13:11 silk-indus

Thank you very much @silk-indus, really appreciated. I'll see what changes you made and try to add another one myself as I need at least 3.

rosak avatar Nov 24 '23 10:11 rosak

I have used the hardware support of the filtering (I only need to set hardware registers), i.e. no software check is required. The packets are filtered on the hardware level and as far as I know, data are even not stored in the module. However, I think it is possible to use more than two filters, but another software check is required. This could be done in the onReceive call.

silk-indus avatar Nov 28 '23 09:11 silk-indus

I added the dual filter.

Where?

Davi512 avatar Jan 23 '24 19:01 Davi512

I added the dual filter.

Where?

Please look on my fork: https://github.com/silk-indus/CAN-ESP32

silk-indus avatar Jan 23 '24 19:01 silk-indus

You mean this ?

"virtual int filters(int id1, int mask1, int id2, int mask2);"

SO I can use filter for 2 ID's?

What about 3 or more? Some mask?

Davi512 avatar Jan 23 '24 20:01 Davi512

Yes, exactly. Two filters are supported by the hardware, i.e., this is evaluated on hardware level, so you don't need to do anything more. If you want to have sophisticated filtering, you must do it in software way, for instance check on every message if ID match the conditions. This solution doesn't reduce the traffic and moreover reduce the computation power.

silk-indus avatar Jan 23 '24 20:01 silk-indus

Ok, what about filtering by mask? Maybe this way is better for more ID's?

Davi512 avatar Jan 23 '24 20:01 Davi512

Mask is like a pattern. The HW way is to write the pattern to the HW register, and the HW do the filtering job. If HW is unable to process more than 2 filters (doesn't have more filter registers, what is our case), you have no other ways, just to filter the packets by the SW. You can use the same patterns, but all the stuff is up to you. That means you have to check every incoming packet (OR, XOR, … whatever, depending on your imagination) if matching your criteria.

silk-indus avatar Jan 23 '24 21:01 silk-indus

I use filter because I have a lot of ID's and I lose some of them. I tried oncallback but the cpu is restart without filter

Davi512 avatar Jan 24 '24 06:01 Davi512

I think, you have a different problem. If the bus is overloaded, filtering does not solve your problem. Filtering can reduce the job of the receiving device. If the bus is ok, then most probably you are not properly receiving the packets. The good practice is to receive packets using interrupts (not by polling).

silk-indus avatar Jan 25 '24 08:01 silk-indus

I use callback and write data to LCD and is ok. But when I run sample callback receive and uart my cpu restart after moment image

Davi512 avatar Jan 25 '24 11:01 Davi512

Sorry for the delay. This error is likely connected with insufficient time for the interrupt. In other words, the next interrupt comes before the old one finishes. A general rule says to reduce interrupt instructions. A common mistake is Serial.print() instruction in the interrupt. Oh, and LCD.print as well. Please definitely avoid it.

silk-indus avatar Feb 05 '24 07:02 silk-indus