STM32-CAN總線濾波器的使用
對(duì)照下表:
我們這里全部設(shè)置成1,也就是只接受CAN_Filter中設(shè)置的節(jié)點(diǎn)的數(shù)據(jù)
STM32共有14組過(guò)濾器,用以對(duì)接收到的幀進(jìn)行過(guò)濾。每組過(guò)濾器包括了2個(gè)可配置的32位寄存器:CAN_FxR0和CAN_FxR1。對(duì)于過(guò)濾器組,可以將其配置成屏蔽位模式,這樣CAN_FxR0中保存的就是標(biāo)識(shí)符匹配值,CAN_FxR1中保存的是屏蔽碼,即CAN_FxR1中如果某一位為1,則CAN_FxR0中相應(yīng)的位必須與收到的幀的標(biāo)志符中的相應(yīng)位吻合才能通過(guò)過(guò)濾器;CAN_FxR1中為0的位表示CAN_FxR0中的相應(yīng)位可不必與收到的幀進(jìn)行匹配。過(guò)濾器組還可以被配置成標(biāo)識(shí)符列表模式,此時(shí)CAN_FxR0和CAN_FxR1中的都是要匹配的標(biāo)識(shí)符,收到的幀的標(biāo)識(shí)符必須與其中的一個(gè)吻合才能通過(guò)過(guò)濾。
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);
評(píng)論