How are the Canbus filtering settings made?

1

I want to filter with canbus. I found certain things for the filter, but what I want is not working. I created a filter like the one below. Some messages cannot pass through this filter.

What kind of change should I make in the filter to be included in the following messages? Thank you for your answers.

Passing messages

enter image description here

Messages that do not pass

enter image description here

My Filtre Code

void Can_Filter_Config(CAN_HandleTypeDef *h_can , CAN_FilterTypeDef *filterConfig , uint64_t Ex_Adress , uint8_t filterNum)
{
  filterConfig->FilterBank      = filterNum;
  filterConfig->FilterMode      = CAN_FILTERMODE_IDMASK; //CAN_FILTERMODE_IDLIST , CAN_FILTERMODE_IDMASK
  filterConfig->FilterScale         = CAN_FILTERSCALE_32BIT;
  //Working  
  filterConfig->FilterIdHigh        = (( Ex_Adress&0xFFFF0000 )   >>13) & 0xFFFF;
  filterConfig->FilterIdLow         = (((Ex_Adress&0xFFFF)<<16) >>13) & 0xFFFF;
  filterConfig->FilterMaskIdHigh    = 0x1fff0000>>13;
  filterConfig->FilterMaskIdLow     = 0xfff8;
  filterConfig->FilterFIFOAssignment    = CAN_RX_FIFO0;
  filterConfig->FilterActivation    = ENABLE;
  filterConfig->SlaveStartFilterBank    = filterNum;

  if(HAL_CAN_ConfigFilter(h_can, filterConfig) != HAL_OK){}
}

Thank you for answer.

c
filter
stm32
can-bus
asked on Stack Overflow Mar 23, 2021 by saklanmaz

1 Answer

0

CAN messages are e.g. filtered to reduce CPU interrupt load (only if a filter accepts a message an interrupt is triggered). With filters is i.e. checked if a message that is on the bus is addressed to this node, this is in detail on page 42-48 in https://www.mi.fu-berlin.de/inf/groups/ag-tech/projects/ScatterWeb/moduleComponents/CanBus_canover.pdf

CAN filters and masks are organized a bit similar to IP addressing (IP address and netmask), this is in detail in http://www.cse.dmu.ac.uk/~eg/tele/CanbusIDandMask.html or in the IP analogy in http://jodies.de/ipcalc

So in CAN filtering if you want to filter a range of addresses you use a mask :

Example 2. we wish to accept only frames with IDs of 00001560 thru to 0000156F

set filter to 00001560

set mask to 1FFFFFF0

In your code only the 0x18 is fixed the rest of the address has to be masked

answered on Stack Overflow Mar 23, 2021 by ralf htp

User contributions licensed under CC BY-SA 3.0