TWAI Acceptance code & mask

glionx
Posts: 2
Joined: Wed Jul 06, 2022 9:16 pm

TWAI Acceptance code & mask

Postby glionx » Mon Nov 06, 2023 9:38 am

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.

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: TWAI Acceptance code & mask

Postby MicroController » Wed Nov 08, 2023 1:44 pm

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.

Who is online

Users browsing this forum: Google [Bot] and 102 guests