cancel
Showing results for 
Search instead for 
Did you mean: 

CAN FILTERS

puneethj
Associate II
Posted on November 11, 2015 at 17:50

Hi every one, especially Mr.Clive, today i have problem with CAN FILTERS i want to allow all IDS from 100 to 1FF in other words block all messages after 0x0200

here is my code, Please help me, Thanks in advance

void CAN_FilterConfiguration(void) {
CAN_FilterInitTypeDef CAN_FilterInitStructure;
/* CAN filter configuration */
// CAN_FilterInitStructure.CAN_FilterNumber = 0; // CAN 1
CAN_FilterInitStructure.CAN_FilterNumber = 14; // CAN 2
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0; // FIFO = 0
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; // Filter mode = identifier mask based filtering
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_16bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0100 << 5;
CAN_FilterInitStructure.CAN_FilterIdLow = 0;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x01ff << 5;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
//Interrrupts
CAN_ITConfig(CAN2,CAN_IT_FMP0,ENABLE);
CAN_FilterInit(&CAN_FilterInitStructure);
}

#!stm32f4-disco #can-filter
23 REPLIES 23
Uvess.1
Associate II

OK i found,

it's 0x7C2<<5

DHurt.1
Associate

I spent some hours because not inderstanding correctly how identifiers extended is formed.

Now i know that is at right of standard. No sense to me because identifier with number 1 is in differents places depending if is standard or extended format.

I made an Excel file to help how to program the filters. I hope is helpful for others.

There are 2 sheets. The first is where config the filters. The second has some examples.

BBasn.1
Associate II

Is there any convenient method for calculating Mask value and apply to filter certain range of IDs? As in the example

void CAN_FilterConfiguration(void) {
CAN_FilterInitTypeDef CAN_FilterInitStructure;
/* CAN filter configuration */
uint16_t StartID = 0x100, endID = 0x1FF; //range of ID to allow 0x100 to 0x1FF
uint16_t maskID = (some operation???)
// CAN_FilterInitStructure.CAN_FilterNumber = 0; // CAN 1
CAN_FilterInitStructure.CAN_FilterNumber = 14; // CAN 2
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0; // FIFO = 0
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; // Filter mode = identifier mask based filtering
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_16bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = startID << 5;
CAN_FilterInitStructure.CAN_FilterIdLow = 0;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = maskID << 5;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
//Interrrupts
CAN_ITConfig(CAN2,CAN_IT_FMP0,ENABLE);
CAN_FilterInit(&CAN_FilterInitStructure);
}

Thankyou.

DeMorgan's Theory?

(ID & 0x700) == 0x100

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