STM32-CAN總線濾波器的使用
對照下表:
我們這里全部設(shè)置成1,也就是只接受CAN_Filter中設(shè)置的節(jié)點(diǎn)的數(shù)據(jù)
STM32共有14組過濾器,用以對接收到的幀進(jìn)行過濾。每組過濾器包括了2個可配置的32位寄存器:CAN_FxR0和CAN_FxR1。對于過濾器組,可以將其配置成屏蔽位模式,這樣CAN_FxR0中保存的就是標(biāo)識符匹配值,CAN_FxR1中保存的是屏蔽碼,即CAN_FxR1中如果某一位為1,則CAN_FxR0中相應(yīng)的位必須與收到的幀的標(biāo)志符中的相應(yīng)位吻合才能通過過濾器;CAN_FxR1中為0的位表示CAN_FxR0中的相應(yīng)位可不必與收到的幀進(jìn)行匹配。過濾器組還可以被配置成標(biāo)識符列表模式,此時CAN_FxR0和CAN_FxR1中的都是要匹配的標(biāo)識符,收到的幀的標(biāo)識符必須與其中的一個吻合才能通過過濾。
CAN_FilterInitStructure.CAN_FilterNumber=0;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=(0x0635<<5);
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0xffff;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0xffff;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=1;
CAN_FilterInitStructure.CAN_FilterIdHigh=(0x06DB<<5);
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0xffff;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0xffff;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO1;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_ITConfig(CAN_IT_FMP0,ENABLE);
CAN_ITConfig(CAN_IT_FMP1,ENABLE);
評論