AnsweredAssumed Answered

CAN filter

Question asked by Frank.Rh on Apr 20, 2012
Latest reply on Apr 23, 2012 by Frank.Rh
Hello,

i try to configure the CAN on a STM32F103R8. I would like to use the filter to block messages. Only messages with the ID 0x701, 0x581, 0x185, 0x285, 0x385, 0x485, 0x205 and 0x305 shall not be blocked.

With the following initialization, only the messages 0x701 and 0x581pass throught.

001.void CANInitIT(void){
002. 
003.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
004.    // CAN Periph clock enable
005.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
006. 
007.    GPIO_InitTypeDef GPIO_InitStructure;
008.    // Configure CAN pin: RX
009.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
010.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
011.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
012.    GPIO_Init(GPIOB, &GPIO_InitStructure);
013. 
014.    // Configure CAN pin: TX
015.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
016.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
017.    GPIO_Init(GPIOB, &GPIO_InitStructure);
018. 
019.    // Put CAN pins out on port B pins 8 and 9
020.    GPIO_PinRemapConfig(GPIO_Remap1_CAN1, ENABLE);
021. 
022.    CAN_InitTypeDef CAN_InitStructure;
023.    CAN_DeInit(CAN1);
024.    CAN_StructInit(&CAN_InitStructure);
025. 
026.    CAN_InitStructure.CAN_TTCM=DISABLE;
027.    CAN_InitStructure.CAN_ABOM=DISABLE;
028.    CAN_InitStructure.CAN_AWUM=DISABLE;
029.    CAN_InitStructure.CAN_NART=DISABLE;
030.    CAN_InitStructure.CAN_RFLM=ENABLE;
031.    CAN_InitStructure.CAN_TXFP=ENABLE;
032.    CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;
033.    CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
034.    CAN_InitStructure.CAN_BS1=CAN_BS1_12tq;
035.    CAN_InitStructure.CAN_BS2=CAN_BS2_5tq;
036.    CAN_InitStructure.CAN_Prescaler=16;
037.    CAN_Init(CAN1, &CAN_InitStructure);
038. 
039.    CAN_FilterInitTypeDef  CAN_FilterInitStructure;
040.    CAN_FilterInitStructure.CAN_FilterNumber = 0;
041.    CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList;
042.    CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
043.    // CAN_FxR1 Konfiguration
044.    CAN_FilterInitStructure.CAN_FilterIdHigh = (0x701<<5);
045.    CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
046.    // CAN_FxR2 Konfiguration
047.    CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (0x581<<5);
048.    CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
049.    CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0;
050.    CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
051.    CAN_FilterInit(&CAN_FilterInitStructure);
052. 
053.    // CAN-Filter 1 Init
054.    CAN_FilterInitStructure.CAN_FilterNumber = 1;
055.    CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList;
056.    CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
057.    // CAN_FxR1 Konfiguration
058.    CAN_FilterInitStructure.CAN_FilterIdHigh = (0x185<<5);
059.    CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
060.    // CAN_FxR2 Konfiguration
061.    CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (0x285<<5);
062.    CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
063.    CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0;
064.    CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
065.    CAN_FilterInit(&CAN_FilterInitStructure);
066. 
067. 
068.    // CAN-Filter 2 Init
069.    CAN_FilterInitStructure.CAN_FilterNumber = 2;
070.    CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList;
071.    CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
072.    // CAN_FxR1 Konfiguration
073.    CAN_FilterInitStructure.CAN_FilterIdHigh = (0x385 << 5);
074.    CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
075.    // CAN_FxR2 Konfiguration
076.    CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (0x485 << 5);
077.    CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
078.    CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0;
079.    CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
080.    CAN_FilterInit(&CAN_FilterInitStructure);
081. 
082.    // CAN-Filter 3 Init
083.    CAN_FilterInitStructure.CAN_FilterNumber = 3;
084.    CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList;
085.    CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
086.    // CAN_FxR1 Konfiguration
087.    CAN_FilterInitStructure.CAN_FilterIdHigh = (0x205 << 5);
088.    CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
089.    // CAN_FxR2 Konfiguration
090.    CAN_FilterInitStructure.CAN_FilterMaskIdHigh = (0x305 << 5);
091.    CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
092.    CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0;
093.    CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
094.    CAN_FilterInit(&CAN_FilterInitStructure);
095. 
096.    //InterruptInit
097.    NVIC_InitTypeDef  NVIC_InitStructure;
098.    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
099.    NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
100.    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
101.    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
102.    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
103.    NVIC_Init(&NVIC_InitStructure);
104. 
105.    CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
106.}

can anyone help me? Thank you very much

Outcomes