user2516265
user2516265

Reputation: 61

How can calculate the software acceptance Mask value

I would like to know how can we calculate the software acceptance filter mask for some set of standard CAN id.It would be great if some one can explain this with example. And also please suggest some links/materials to learn the CAN stack software implementation.

Thanks in advance.

Upvotes: 3

Views: 13206

Answers (2)

sats
sats

Reputation: 159

Let me explain this with an example:

Suppose the user wants to receive the messages only with IDs 0x8Z (where Z = 1,3,5,7) then here is how the value of Mask register and Acceptance register can be calculated:

  • 0x81 = 1000 0001
  • 0x83 = 1000 0011
  • 0x85 = 1000 0101
  • 0x87 = 1000 0111

Mask Register = 1111 1001

First compare the 0th bits of all the IDs, if its same then the corresponding bit for mask register will be "1" else it will be "0". Then compare the 1st bits, then 2nd bits and so on...

In our case only the 5th and 6th bits differ in all the IDs. This explains how we got "Mask Register" value.

For Acceptance register value, take any of the allowed message IDs and that will be the value of the Acceptance register value. In our case it could be 0x81 or 0x83 or 0x85 or 0x87

C code to check this could look like this:

if((Incoming_ID & Mask_Register) == (Acceptance register & Mask_Register))
{
    //Receive Message
}
else
{
     //Discard Message
}

Hope it helps.

Upvotes: 5

LogicG8
LogicG8

Reputation: 1757

Since this filtering is done in hardware it is fairly primitive. Usually the calculation involves two registers a mask and a filter. The equivalent logic in C would be:

/* dsPIC style; mask specifies "do care" bits */
if ((arbitrationId & mask) == filter) {
    /* Message accepted; rx interrupt triggered */
}

/* Accept all */
mask = 0;
filter = 0;

/* Accept CANopen default connection set (excluding SYNC and NMT) */
mask = 0x7F;
filter = node_id;

Or

/* SJA 1000 style; mask specifies "do not care" bits */
if ((arbitrationId & ~mask) == filter) {
    /* Message accepted; rx interrupt triggered */
}

/* Accept all */
mask = ~0;
filter = 0;

/* Accept CANopen default connection set (excluding SYNC and NMT) */
mask = ~0x7F;
filter = node_id;

The number of masks, the number of filters, if and how the filters are enabled, and the arrangement of ID bits within registers is all hardware dependent. To give you a more concrete answer would require details about the specific hardware being used.

Basic information on CANbus can be found here:

Upvotes: 3

Related Questions