2009-04-22 08:25 AM
CAN Filter Setting
2011-05-17 04:09 AM
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;2011-05-17 04:09 AM
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);2019-03-13 09:47 PM
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);
2019-03-13 10:02 PM
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.
2019-03-13 10:07 PM
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.