-
-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter for multiple CAN frame ids/masks #19
Comments
I can confirm on the MCP2515. If you look at the code, the MCP routine just loops 6 times and writes to all registers. I have changed the (my) function to support multiple IDs and masks. There are only two mask filters on the MCP which must be set. EDIT:
to make it work. |
looking at the MCP2515 SPI manuel, you are absolutely right. But maybe a macro like this allows to use the old code without changes? #define REG_RXFnSIDH(n) ((n) < 3 ? (0x00 + (n) * 4) : (0x10 + ((n) - 3) * 4)
#define REG_RXFnSIDL(n) ((n) < 3 ? (0x01 + (n) * 4) : (0x11 + ((n) - 3) * 4)
#define REG_RXFnEID8(n) ((n) < 3 ? (0x02 + (n) * 4) : (0x12 + ((n) - 3) * 4)
#define REG_RXFnEID0(n) ((n) < 3 ? (0x03 + (n) * 4) : (0x13 + ((n) - 3) * 4) of course you need to make sure, that |
Perfect :-) I have not testet yet but this looks like the way to go. I will implement and let you know. |
That runs on my side. But you have to change the old code in any case, because it does not allow to set individual masks or filters. The old code just fills both masks withe one value and also fills all six filters with only one value. |
I've sent a PR a week ago which implements mostly the same but also handles the case when the amount of ids > 6 (in your code when see #20 I still have to add the updated register macros and test it with my hardware. |
There is more. My above code changes has only effect if the control bits within some registers are set correctly. The above code has a sequence take from the origin:
In fact, this is nonsense here. Replace it with the following code:
What does it do? At first it clears the bits within the control registers for the RX buffers 0 and 1 to allow the usage of filtering. Without setting any filters or masks it does not make any sense. |
Sent a PR #47 |
Hey,
Im not sure about the SJA1000 but the MCP2515 supports multiple filters, however the api of this library does not support multiple filters.
Maybe a macro constant like
MAX_FILTERS
and a functionmultiFilter(int *ids, int *masks, size_t count)
would be possible?I'm using this library together with an Arduino MKR WAN and a MKR CAN shield to read data from a Renault Twizy. Bitwise anding together all the CAN IDs I need results in 0, so using a single filter is not possible.
The text was updated successfully, but these errors were encountered: