Page 1 of 1

TWAI Acceptance code & mask

Posted: Mon Nov 06, 2023 9:38 am
by glionx
I see the acceptance code is Right side msb in the documentation

I want to filter on ID's in the 0x700 range

0x700 = 0111 0000 0000 left side msb

Image

I've tried the following without luck....

acceptance_code = 0x700 << 21; // 0x38000000 = 0011 1000 0000 0000 0000 0000 0000 0000
acceptance_mask = 0b00000000111000000000000000000000; // 0x01800000

Any help? wanting id's in the 0x7xx range.

Re: TWAI Acceptance code & mask

Posted: Wed Nov 08, 2023 1:44 pm
by MicroController
Try

Code: Select all

acceptance_code = 0xE0000000; // (0x700 << 21) = 0b1110000...
acceptance_mask = 0xE0000000; // same as code
Note that the MSB of the code/mask value is matched against the first bit of the message (MSB of ID). With 11-bit IDs, the maximum ID is 0x7ff, so the MSB in the filter (0x80000...) corresponds to the 0x400 bit of the ID. And the mask bits indicate which bits of the code are used for filtering; a 1-bit in the code without the corresponding 1 in the mask does nothing and is a likely indicator of an unintended mismatch of mask and code.