Skip to main content
Associate
October 26, 2023
Solved

STM32F103C8T6 CAN filter configulation EXTENDED and STANDART the same time

Hi!

I am using an STM32F103C8T6 mikrocontroller and i program with makefile and VsCode. I use the CAN on it and i need to work with STDID and a EXTID. On the bus there is dozens of standart CAN messages and sometime exteneded messages. From the standart ID-s i just need which identifier is 0x7C1 and next to that i need the all exteneded messages too. I would like to direct the standart messages in FiFo1 and the extened to FiFo0 (or inversely doesnt matter just one FiFO for the extened and other for the standart). I have created two canfilterconfig like this:

For the exntened:

  canfilterconfig_EXT.FilterActivation = CAN_FILTER_ENABLE;
  canfilterconfig_EXT.FilterBank = 0;  
  canfilterconfig_EXT.FilterFIFOAssignment = CAN_RX_FIFO0;
  canfilterconfig_EXT.FilterIdHigh = 0x00; 
  canfilterconfig_EXT.FilterIdLow = 0x04; // IDE bit
  canfilterconfig_EXT.FilterMaskIdHigh = 0x00; 
  canfilterconfig_EXT.FilterMaskIdLow = 0x04; // IDE bit
  canfilterconfig_EXT.FilterMode = CAN_FILTERMODE_IDMASK;
  canfilterconfig_EXT.FilterScale = CAN_FILTERSCALE_32BIT;
  canfilterconfig_EXT.SlaveStartFilterBank = 0;  //has no effect
 
For the standart:
 
  canfilterconfig_STD.FilterActivation = CAN_FILTER_ENABLE;
  canfilterconfig_STD.FilterBank = 1;
  canfilterconfig_STD.FilterFIFOAssignment = CAN_RX_FIFO1;
  canfilterconfig_STD.FilterIdHigh = 0x7C1<<5;
  canfilterconfig_STD.FilterIdLow = 0x0000;
  canfilterconfig_STD.FilterMaskIdHigh = 0xFFF<<5;
  canfilterconfig_STD.FilterMaskIdLow = 0x0000;
  canfilterconfig_STD.FilterMode = CAN_FILTERMODE_IDMASK;
  canfilterconfig_STD.FilterScale = CAN_FILTERSCALE_32BIT;
  canfilterconfig_STD.SlaveStartFilterBank = 0;  //has no effect
 
  if(HAL_CAN_ConfigFilter(&hcan, &canfilterconfig_STD) != HAL_OK)
  {
    Error_Handler();
  }

  if(HAL_CAN_ConfigFilter(&hcan, &canfilterconfig_EXT) != HAL_OK)
  {
    Error_Handler();
  }
 
I have tested it and the extened messages cause interrupt (so it works well) but the 0x7C1 standart ID message doesnt cause interrupt. I tried with ListMode, the 16bit mask mode but the met same problem with it. Can you guys have any guess?
Thanks in advance!
This topic has been closed for replies.
Funky_Monkey99Best answer
Associate
October 27, 2023

i think i figured out what was the problem. I have made a new project where i just use the CAN and the filter configulation.  I configured the FiFo 0 to catch just 0x7C1 is filter list mode just like that:

  CAN_FilterTypeDef canfilterconfig_FIFO0;
  canfilterconfig_FIFO0.FilterActivation = CAN_FILTER_ENABLE;
  canfilterconfig_FIFO0.FilterBank = 0;  
  canfilterconfig_FIFO0.FilterFIFOAssignment = CAN_RX_FIFO0;
  canfilterconfig_FIFO0.FilterIdHigh = 0x7C1<<5;
  canfilterconfig_FIFO0.FilterIdLow =0x0000;
  canfilterconfig_FIFO0.FilterMaskIdHigh = 0x7C1<<5;
  canfilterconfig_FIFO0.FilterMaskIdLow = 0x0000;
  canfilterconfig_FIFO0.FilterMode = CAN_FILTERMODE_IDLIST;
  canfilterconfig_FIFO0.FilterScale = CAN_FILTERSCALE_32BIT;
  canfilterconfig_FIFO0.SlaveStartFilterBank = 0;  //has no effect

  if(HAL_CAN_ConfigFilter(&hcan, &canfilterconfig_FIFO0) != HAL_OK)
  {
    Error_Handler();
  }
 
After that i configured FiFo1 for the extened ID-s (it is the same config in the question):
 
CAN_FilterTypeDef canfilterconfig_FIFO1;

  canfilterconfig_FIFO1.FilterActivation = CAN_FILTER_ENABLE;
  canfilterconfig_FIFO1.FilterBank = 1;  
  canfilterconfig_FIFO1.FilterFIFOAssignment = CAN_RX_FIFO1;
  canfilterconfig_FIFO1.FilterIdHigh = 0x0000;
  canfilterconfig_FIFO1.FilterIdLow = 0x04; // IDE bit
  canfilterconfig_FIFO1.FilterMaskIdHigh = 0x0000;
  canfilterconfig_FIFO1.FilterMaskIdLow = 0x04; // IDE bit
  canfilterconfig_FIFO1.FilterMode = CAN_FILTERMODE_IDMASK;
  canfilterconfig_FIFO1.FilterScale = CAN_FILTERSCALE_32BIT;
  canfilterconfig_FIFO1.SlaveStartFilterBank = 0;  //has no effect

  if(HAL_CAN_ConfigFilter(&hcan, &canfilterconfig_FIFO1) != HAL_OK)
  {
    Error_Handler();
  }
 
I tried with this and now it works well. My colleague and I think that because I have made an new project with this configulation it erased the whole mikrocontroller program from the STM32 so it erased the other filterbanks which i used at the begining of the project.  (maybe filterbank 10 I cant remembered well) Next to that I configured new filterbank which in the question (filterbank 1 and 2) but the filter bank 10 stayed in the configured. So because the filter bank 10 was set (and i forgetted that) it filtered the message. So I erased the whole program from the mikrocontroller and flashed again and now it works fine. 

1 reply

Funky_Monkey99AuthorBest answer
Associate
October 27, 2023

i think i figured out what was the problem. I have made a new project where i just use the CAN and the filter configulation.  I configured the FiFo 0 to catch just 0x7C1 is filter list mode just like that:

  CAN_FilterTypeDef canfilterconfig_FIFO0;
  canfilterconfig_FIFO0.FilterActivation = CAN_FILTER_ENABLE;
  canfilterconfig_FIFO0.FilterBank = 0;  
  canfilterconfig_FIFO0.FilterFIFOAssignment = CAN_RX_FIFO0;
  canfilterconfig_FIFO0.FilterIdHigh = 0x7C1<<5;
  canfilterconfig_FIFO0.FilterIdLow =0x0000;
  canfilterconfig_FIFO0.FilterMaskIdHigh = 0x7C1<<5;
  canfilterconfig_FIFO0.FilterMaskIdLow = 0x0000;
  canfilterconfig_FIFO0.FilterMode = CAN_FILTERMODE_IDLIST;
  canfilterconfig_FIFO0.FilterScale = CAN_FILTERSCALE_32BIT;
  canfilterconfig_FIFO0.SlaveStartFilterBank = 0;  //has no effect

  if(HAL_CAN_ConfigFilter(&hcan, &canfilterconfig_FIFO0) != HAL_OK)
  {
    Error_Handler();
  }
 
After that i configured FiFo1 for the extened ID-s (it is the same config in the question):
 
CAN_FilterTypeDef canfilterconfig_FIFO1;

  canfilterconfig_FIFO1.FilterActivation = CAN_FILTER_ENABLE;
  canfilterconfig_FIFO1.FilterBank = 1;  
  canfilterconfig_FIFO1.FilterFIFOAssignment = CAN_RX_FIFO1;
  canfilterconfig_FIFO1.FilterIdHigh = 0x0000;
  canfilterconfig_FIFO1.FilterIdLow = 0x04; // IDE bit
  canfilterconfig_FIFO1.FilterMaskIdHigh = 0x0000;
  canfilterconfig_FIFO1.FilterMaskIdLow = 0x04; // IDE bit
  canfilterconfig_FIFO1.FilterMode = CAN_FILTERMODE_IDMASK;
  canfilterconfig_FIFO1.FilterScale = CAN_FILTERSCALE_32BIT;
  canfilterconfig_FIFO1.SlaveStartFilterBank = 0;  //has no effect

  if(HAL_CAN_ConfigFilter(&hcan, &canfilterconfig_FIFO1) != HAL_OK)
  {
    Error_Handler();
  }
 
I tried with this and now it works well. My colleague and I think that because I have made an new project with this configulation it erased the whole mikrocontroller program from the STM32 so it erased the other filterbanks which i used at the begining of the project.  (maybe filterbank 10 I cant remembered well) Next to that I configured new filterbank which in the question (filterbank 1 and 2) but the filter bank 10 stayed in the configured. So because the filter bank 10 was set (and i forgetted that) it filtered the message. So I erased the whole program from the mikrocontroller and flashed again and now it works fine.