Hardware manual

RX600 Series CAN Application Programming Interface
R01AN0339EU0203 Rev. 2.03 Page 19 of 29
Mar 23, 2013
R_CAN_RxSetMask
Sets the CAN ID Acceptance Masks
To accept only one ID, set mask to all ones. To accept all messages, set mask to all zeros. To accept a range of
messages, set the corresponding ID bits to zero.
Format
void R_CAN_RxSetMask( const uint32_t ch_nr,
const uint32_t mbox_nr,
const uint32_t sid_mask_value );
Arguments
ch_nr 0,1,2,3 Which CAN bus to use. 1-4 channels may be available.
mbox_nr 0-32 Which CAN mailbox to check.
sid_mask_value 0-7FF
h
Mask value.
Return Values
-
Properties
Prototyped in r_can_api.h
Implemented in r_can_api.c
Comments
Receive mailboxes can use a mask to filter out one or a range of message CAN IDs. The mask enables mailboxes to
accept a broader range of messages than just the single message ID that is set in the mailbox’s ID field.
There is one mask for mailbox 0-3, one for 4-7, … Remember therefore that changing a mask can very well affect
the behavior of adjacent mailboxes.
- Each '0' in the mask means "mask this bit", or “don't look at that bit; accept anything.
- Each '1' means check if the CAN-ID bit in this position matches the CAN-ID of the mailbox.
How to set a mask
Lets say the CAN-IDs you want to receive in a mailbox is 700-704
h
using standard 11-bit ID:
Hex representation Bit representation
0x700 011100000000b
0x701 011100000001b
0x702 011100000010b
0x703 011100000011b
0x704 011100000100b
The mailbox will only accept frames with an ID that matches the positions whose mask value is 1. If we want to
accept all of above, we set the mask as
011111111000b, or 07F8
h
.
The CAN receive filter will only look at bit positions b11 (MSB), to b3 (LSB) and whether these match the receive
ID of the mailbox.
If we then set a mailbox to receive ID 0x700 (0x700-0x707 will give the same result) it will accept IDs 0x700 to
0x707. 0x705 to 0x707 must later be ignored ‘manually’ by the application software.