This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1294NCPDT: How to discard CAN messages from a particular ID

Part Number: TM4C1294NCPDT

Dear all,

Using the following settings, I am able to get only messages from ID 2, But I need opposite. I need to reject ID 2 and receive all other messages in 11 bit configuration.

Please help me with the settings

/ Setup obj 2 as rx with acceptance filter
ptr->IF1CMSK = B7 | B6 | B5 | B4 | B1 | B0;

// Enable the use of XTD and DIR for acceptance filtering by setting UMASK
ptr->IF1MCTL |= B12;

// Set the filter mask for the lower 11 bits of the 11-bit standard ID in CANIFnMSK2
ptr->IF1MSK2 = B14 | B12 | B11 | B10 | B9 | B8 | B7 | B6 | B5 | B4 | B3 | B2;

// Set the expected ID to the ID you want to reject in CANIFnARB2
ptr->IF1ARB2 = ((0x2) << 2) | B15; // Set direction and valid bit for ID 2

// Enable rx interrupts
ptr->IF1MCTL = B12 | B10 | B7 | B6; // Set UMASK to enable mask for acceptance filtering

  • Hi,

      Below is example to receive CAN messages with ID 0x1001 only and filter out all others. 

    /* Initialize a message object to receive CAN messages with ID 0x1001.
    * The expected ID must be set along with the mask to indicate that all
    * bits in the ID must match. */
    sCANMessage.ui32MsgID = 0x1001;
    sCANMessage.ui32MsgIDMask = 0xfffff;
    sCANMessage.ui32Flags = (MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER |
    MSG_OBJ_EXTENDED_ID);

    If you want to exclude ID 0x2 then you would set the ID to 0x00000000 and the mask to 0x00000002. Bear in mind that filtering is applied by masking the specified bit(s) from comparison. It is not a equality comparison. Say for example that the CAN ID field is only three bits instead of 11 bits. If you specify ID equal to 0x0 and the mask equal to 0x2 then the ID 0x2 will be filtered out but also ID 0x3, 0x6 and 0x7. 

  • " If you specify ID equal to 0x0 and the mask equal to 0x2 then the ID 0x2 will be filtered out but also ID 0x3, 0x6 and 0x7. "

    Can u please explain why 3,6,7 is getting filtered out and where it is mentioned in reference manual.

  • If the mask is equal to 0x2 as in 010b then bit 1 is used for acceptance filtering. If you specify an ID of 0x0 as in 000b for which bit 1 is equal to 0, any IDs that has bit 1 equal to 1 will be filtered out. Only IDs with bit 1 equal to 0 will be accepted. Look at a three-bit ID example, this means 010, 011, 110 and 111 will be filtered out because for these four IDs their bit 1 is equal to 1. This is what I mean not only an ID of 0x2 is filtered out but also 0x3, 0x6 and 0x7. If you want to filter out only ID=0x2 and pass everything else, why don't you consider disabling the acceptance filtering but in your ISR, check for the incoming ID equal to 0x2 and ignore the processing of it. 

  • I need to reduce overflow in my recieve Buffer so would have to discard it before recieving

  • I have explained how the hardware works. Below thread has the similar discussion. it is up to you how you want to implement it. I have no other suggestions.

    https://electronics.stackexchange.com/questions/240278/controller-area-network-received-message-filtering-mechanism

  • Hi Charles,

    Below was our understanding,

    ARB ID- 000
    (Bitwise OR)
    Mask - 010
    = 010


    Node ID 1 - 001 - 000(AND) - Don't filter

    Node ID 2 - 010 - 010(AND) - Filter

    Node ID 3 - 011 - 010(AND) - Filter

    Node ID 4 - 100 - 000(AND) - Don't filter

    Node ID 5 - 101 - 000(AND) - Don't filter

    Node ID 6 - 110 - 010(AND) - Filter

    Node ID 7 - 111 - 010(AND) - Filter

    -----------------------------------------------------------------------------------------------------------------------------

    If output of AND operation is 0, don't filter the received CAN message else filter the receive

    -----------------------------------------------------------------------------------------------------------------------------
    But when we tried with below combination that understanding didnt work

    ARB ID - 010
    (Bitwise OR)
    Mask - 111
    = 111

    Node ID 1 - 001 - 001(AND) - Filter

    Node ID 2 - 010 - 010(AND) - Filter But it didnt Filter

    Node ID 3 - 011 - 010(AND) - Filter

    Node ID 4 - 100 - 000(AND) - Filter

    Node ID 5 - 101 - 000(AND) - Filter

    Node ID 6 - 110 - 010(AND) - Filter

    Node ID 7 - 111 - 010(AND) - Filter

    Please help me to understand.

  • For the mask bit that is equal to 1, it is like doing a XOR logic between the incoming ID on the bus with the specified ID stored in the sCANMessage.ui32MsgID for the corresponding bit. The result of the XOR must be equal to 1. For the mask bit(s) that is equal to 0, you do not need to compare. 

  • so if the result of the XOR is equal to 1 then the filter, otherwise do not filter?

  • You first do a XOR between between the incoming ID with what you specify in the sCANMessage.ui32MsgID. The result of the XOR is again XOR with the mask you store in sCANMessage.ui32MsgIDMask. The individual bits of that XOR result is then NOR to determine if a incoming ID should be filtered or not. 

    Take you own example 1:

    ARB ID- 000
    Mask - 010

    First take XOR between the incoming ID (there are 8 combinations using a 3bit ID example) and ARB ID (000 as in your example)

    Incoming ID     Result1 (XOR result with 000)

    000                  111

    001                  110

    010                  101

    011                   100

    100                   011

    101                  010

    110                  001

    111                   000

    Now take the XOR result of the above with the mask (010 as you specify in your example)

    Result1            Result2 (XOR result with the mask 010)

    111                     010                                    

    110                    010

    101                    000

    100                    000

    011                    010

    010                    010

    001                    000

    000                    000

    Result2             Result3 (OR of all three bits)

    010                   1

    010                   1

    000                   0

    000                   0

    010                   1

    010                    1

    000                    0

    000                    0

    Incoming ID   Result3 

    000                1               Passed through

    001                1               Passed through

    010                0               Filtered out

    011                0               Filtered out

    100                1                Passed through

    101                1               Passed through

    110                 0               Filtered out

    111                  0              Filtered out

    Why don't you write some code to see if this is what you are getting when you apply ARB=000 and Mask=010 and inject the 8 different combinations of message IDs on the bus. 

  • Hi,

      Are you clear with my explanation now?

  • Hi,

     Do you have any update as I have not heard back from you?

  • Hi,

     I have checked back with you several times but I have not heard back from you. I will close the thread for now. If you have any question, you can write back and the thread will automatically reopen.