Skip to main content
vinicius_acvasconcelos
Associate III
April 22, 2009
Question

CAN Filter Setting

  • April 22, 2009
  • 5 replies
  • 1216 views
Posted on April 22, 2009 at 17:25

CAN Filter Setting

    This topic has been closed for replies.

    5 replies

    vinicius_acvasconcelos
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:09

    I solved the to problem to filter only the 0x2222 id messages:

    /* CAN filter init */

    CAN_FilterInitStructure.CAN_FilterNumber=0;

    CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;

    CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;

    CAN_FilterInitStructure.CAN_FilterIdHigh=( (0x2222 << 3) >> 16);

    CAN_FilterInitStructure.CAN_FilterIdLow=( (0x2222 << 3) & 0xFFFF);

    CAN_FilterInitStructure.CAN_FilterMaskIdHigh= ( (0xFFFFFFFF>>3)>>16);

    CAN_FilterInitStructure.CAN_FilterMaskIdLow= ( (0xFFFFFFFF << 3) & 0xFFFF);

    CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0;

    CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;

    CAN_FilterInit(&CAN_FilterInitStructure);

    vinicius_acvasconcelos
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:09

    I'm sending a message by CAN using a Extend Id 0x2222. What the configuration I have to use in the Filter to receive only this Extend Id messages, setting the IDList filter?

    I tried to configurate the Filter Low with 0x2222, but didn't works.

    CAN_FilterInitStructure.CAN_FilterNumber=0;

    CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;

    CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;

    CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000;

    CAN_FilterInitStructure.CAN_FilterIdLow=0x2222;

    CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;

    CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;

    CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0;

    CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;

    CAN_FilterInit(&CAN_FilterInitStructure);

    TxMessage.StdId=0x00;

    TxMessage.ExtId=0x2222;

    TxMessage.IDE=CAN_ID_EXT;

    Andrew Hazelton
    Associate III
    March 14, 2019

    Hi Vinicius.

    Thanks for that this helped me get this working. For the below, what is the purpose of the "<<3" bitwise move? I cannot see the need for this in the reference manual.

    Nevertheless is works on my MCU. :)

    CAN_FilterInitStructure.CAN_FilterIdHigh=( (0x2222 << 3) >> 16);
    CAN_FilterInitStructure.CAN_FilterIdLow=( (0x2222 << 3) & 0xFFFF);
    CAN_FilterInitStructure.CAN_FilterMaskIdHigh= ( (0xFFFFFFFF>>3)>>16);
    CAN_FilterInitStructure.CAN_FilterMaskIdLow= ( (0xFFFFFFFF << 3) & 0xFFFF);

    Andrew Hazelton
    Associate III
    March 14, 2019

    Oh wait I see.... RM0385 Rev 8, Figure 449, page 1307. You have to move the EXID 3 places bitwise to the left (<<3) as the [2:0] bits of EXID are for IDE, RTR & 0. It all makes sense now.

    0690X0000087wYRQAY.png

    Tesla DeLorean
    Guru
    March 14, 2019

    Yes, exactly. Basically masking the data on the wire and then comparing the remaining bits for a match.

    The original post is nearly a decade old, the 17-May-2011 was a forum meltdown date.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..