2015-11-11 08:50 AM
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
2020-09-08 08:07 AM
OK i found,
it's 0x7C2<<5
2021-02-03 01:42 AM
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.
2023-08-18 06:14 PM - edited 2023-08-18 06:20 PM
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.
2023-08-18 07:33 PM
DeMorgan's Theory?
(ID & 0x700) == 0x100