Hello,
I am working on an old code based on esp idf 4.3. I have TWAI already setup with acceptance code ~(0x100 << 21) and acceptance mask of ~(0x100 << 21).
But this mask blocks a new frame in my system which is 0x130.
Basically my systems needs these frames :
0x18
0x20
0x130
0x600
0x610
0x618
0x620
0x627
0x640
I know I can't filter only these frames. But I do need to change my mask. I have tried various mask following advice on this forum, in the doc or on some git repo, but with no success. The one I though will work was ~(0x7FF << 21) for the mask and (0x600 << 21) for the code. But this filter blocks every frame.
Because this is not spicy enough, if I set the twai filter to accept all, some random CAN frames appear, my peakcan do not see any of these new frames. Is it normal ?
Does someone know how I can set up a new twai filter ? And what is the correct way to compute it ?
How to configure TWAI MASK and CODE
-
- Posts: 2046
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: How to configure TWAI MASK and CODE
Common to all your IDs of interest is only that bit #7 (0x80) is 0. So I think code = mask = ~0x80 is the best you can do to have all frames pass with only one filter. (Without ID 0x130, code = mask = ~0x180 would be best.)
Calculation:
uint16_t common1 = 0x18 & 0x20 & 0x130 & ... & 0x640; // common1 = mask of all bits which are '1' in *all* IDs
uint16_t common0 = ~(0x18 | 0x20 | 0x130 | ... | 0x640); // common0 = mask of all bits which are '0' in *all* IDs
->
code = common1; // Only set the '1' bits, just leave the rest at '0'.
mask = ~(common1 | common0) & 0x7ff; // make the filter ignore all bits which are not 0 or 1 in *all* IDs
Calculation:
uint16_t common1 = 0x18 & 0x20 & 0x130 & ... & 0x640; // common1 = mask of all bits which are '1' in *all* IDs
uint16_t common0 = ~(0x18 | 0x20 | 0x130 | ... | 0x640); // common0 = mask of all bits which are '0' in *all* IDs
->
code = common1; // Only set the '1' bits, just leave the rest at '0'.
mask = ~(common1 | common0) & 0x7ff; // make the filter ignore all bits which are not 0 or 1 in *all* IDs
Who is online
Users browsing this forum: No registered users and 111 guests