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.

Ozgur Saklanmaz
  • 528
  • 3
  • 17
  • Looks like the only sensible part to mask out is the 0x18 byte. So I don't understand your code. How did you come up with the masks? – Lundin Mar 23 '21 at 15:06
  • Also, this is kind of obsolete technology. Modern CAN controllers uses mailboxes and then you'd just allocate enough of those and ignore everything else. ST apparently uses very old CAN controllers from the 1990s. And you can't even buy STM32 chips on the market currently. So if you are in the R&D phase I'd strongly recommend porting this to a better MCU. – Lundin Mar 23 '21 at 15:08
  • Unfortunately I have no chance to change the MCU. I need to make a revision on a product and a product. I'm making changes due to revision. I found the masks by doing research. I'm not sure they're healthy. – Ozgur Saklanmaz Mar 24 '21 at 07:09
  • Fair enough. Though it does kind of suck to develop for a MCU that can't be purchased. I'm stuck with a bunch of STM32 designs too. I had a good impression of ST until this part status fiasco. It's been half a year and they still haven't solved it. – Lundin Mar 24 '21 at 07:28

1 Answers1

2

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

ralf htp
  • 9,149
  • 4
  • 22
  • 34
  • Thank you. I accessed the site you mentioned. I did not get positive results. Does it differ if the Can message is standard or extended in masking? The 0x00000101 message is a standard message, others are extended messages. – Ozgur Saklanmaz Mar 24 '21 at 07:11