cancel
Showing results for 
Search instead for 
Did you mean: 

CAN filtering

ian
Associate II
Posted on October 30, 2008 at 10:50

CAN filtering

8 REPLIES 8
ian
Associate II
Posted on May 17, 2011 at 12:50

I am using the CAN on the stm32 to control a number of stepper motor drivers. Am able to send and recieve messages without may trouble. However I want to be able to filter the messages to look for range of IDs. I set the filtering set as shown:

CAN_FilterInitStructure.CAN_FilterNumber=0;

CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;

CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;

CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000;

CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;

CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;

CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;

CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;

CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;

CAN_FilterInit(&CAN_FilterInitStructure);

I can see now all the messages on the CAN bus, I want to used the CAN filters to look for a range of Extended IDs e.g. 0x1A8023XX.

I have tried various combinations of masks in both Mask and List modes but am still having no success. Can anyone offer any help

Thanks

Ian

glory_man
Associate II
Posted on December 22, 2011 at 09:34

I have the same problem with stm32f407. Reference manual says thant filter banks need to be in form STDID[10:0], EXTID[17:0], IDE bit, RTR bit, 0. I tried various filter modes and ID's, but worked only FilterIdHigh=0x0000 FilterIdLow=0x0000 FilterMaskIdHigh=0x0000 FilterMaskIdLow=0x0000. Even in mask mode , for example configured FilterID = ( (0xA<<3) | (CAN_RTR_DATA | CAN_ID_EXT) ) FilterMaskID = 0 CAN_FilterMode = CAN_FilterMode_IdMask - as far as I understand in this case all frames will received - mask = 0 all ID bits don't care. But does not have frame reception.

Where is problem?

glory_man
Associate II
Posted on December 22, 2011 at 16:28

Sorry, I found a problem in can-init  code. All works.

But I little confused with filter structure in documentation.

As far as I understand FxR1[31:21] is STD[10:0] only if IDE=0 (standard ID), if IDE = 1 (extended ID) this bits EXT[28:18]

reffahcs
Associate II
Posted on December 24, 2011 at 04:46

Agree, the documentation is a little confusing. The short answer is that the FilterIDLow and FilterIDHigh as well as MaskIDLow and MaskIDHigh don't correspond exactly to the SID/EID. The bits need to be shifted depending on the type of ID you are trying to filter. It took me several weeks to find the answer on a German website that I used google to translate. Please look at my example code below, hopefully it will be clear then.

In this example four filters are created to receive only SID 123, 124, 125 and 126. They don't have to be in order, just happened to be the numbers I picked. For a SID the numbers for the Filter/Mask IDs need to be shifted to the left by 5 bits.

CAN_FilterInitStructure.CAN_FilterNumber = 1;

CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList;

CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_16bit;        // All filters are shifted left 5 bits

CAN_FilterInitStructure.CAN_FilterIdHigh = 0x2460;          // 0x123

CAN_FilterInitStructure.CAN_FilterIdLow = 0x2480;           // 0x124

CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x24A0;      // 0x125

CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x24C0;       // 0x126

CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;

CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;

CAN_FilterInit(&CAN_FilterInitStructure);

donald2
Associate II
Posted on December 24, 2011 at 16:28

Here is the comment from my filter setup code:

/*  CAN initialization.

 * It took experimentation to fill in the missing details of the manual,

 * especially with the Rx filter.

 * Each filter is 8 bytes, and can be configured in one of four ways.

 *  Two 29 bit IDs w/ EID and RTR bits (presumably extended IDs)

 *  One 29 bit ID with a 29 bit mask

 *  Four 11 bit IDs, w/ EID and RTR bits.

 *    The lower 3 bits are ignored

 *  Two 11 bit IDs w/ EID and RTR bits, paired with two 16 bit masks

 */

geeta
Associate
Posted on February 21, 2012 at 14:15

I am working on scan tool I am trying to get diagnostic response. I have configured filter as below. Could anyone help me why is it not filtering only 0x18DAF1XX. It is receiving  all frames!

This problem is similar one mentioned in earlier discussions...

    /* CAN filter init */

#ifdef  USE_CAN1

 CAN_FilterInitStructure.CAN_FilterNumber = 1;

#else /* USE_CAN2 */

/*  CAN_FilterInitStructure.CAN_FilterNumber = 15;*/

#endif  /* USE_CAN1 */

  CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;

  CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;

  CAN_FilterInitStructure.CAN_FilterIdHigh = 0xC6D7;

  CAN_FilterInitStructure.CAN_FilterIdLow = 0x8804;

  CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFFF;

  CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xF804;

  CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0;

  CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;

  CAN_FilterInit(&CAN_FilterInitStructure);

glory_man
Associate II
Posted on February 22, 2012 at 16:22

As far as I understand this code configure FilterBank 1 or 15. But there is FilterBank 0 - which may be configured to receive all frames.

muhammaduzairafzal45
Associate III
Posted on December 19, 2012 at 15:14

According yo my knowledge,CAN filters banks numbering from 14 to 28 are only in connectivity line devices. and by default CAN2 filter numbering starts from 14 in those devices. Other device have 0 to 13 filter banks only.