cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Filter Setting

vinicius_acvasconcelos
Associate II
Posted on April 22, 2009 at 17:25

CAN Filter Setting

5 REPLIES 5
vinicius_acvasconcelos
Associate II
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;

vinicius_acvasconcelos
Associate II
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);

Andrew Hazelton
Associate III

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

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

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 Up vote any posts that you find helpful, it shows what's working..