cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L433 CAN filtering using mask mode

agennart
Associate

Hello,

I am currently using a STM32l433 with the following configuration:

        CAN_FilterTypeDef  CAN_FilterInitStructure = {0};
        CAN_FilterInitStructure.FilterBank = filterNum;
        CAN_FilterInitStructure.FilterScale = CAN_FILTERSCALE_16BIT;

        // 11-bits StdId left-aligned on the 32-bits word register
        CAN_FilterInitStructure.FilterIdHigh = id << 5;
        CAN_FilterInitStructure.FilterIdLow = 0;
        CAN_FilterInitStructure.FilterMaskIdHigh = mask << 5;
        CAN_FilterInitStructure.FilterMaskIdLow = 0;

        CAN_FilterInitStructure.FilterFIFOAssignment = CAN_FILTER_FIFO0;
        CAN_FilterInitStructure.FilterMode = CAN_FILTERMODE_IDMASK;

 

It globally works. So if my ID is 0x701 and my mask 0xFFFF, the callback will be called for every message ID 0x701.

However, when I change the mask, for exaple to a value like 0x700, in order to only get the '7' from the standard ID, my callback is not called for every message with ID 0x7__.

I also notice the that the 16bit filter lenght require the RTR, IDE and EXID (see picture below). In my case everything is set to 0. Could it be those settings are wrong ?

 

Could it be that there is something wrong with the configuration that makes the mask invalid ?

Any help is appreciated !

Thanks

agennart_0-1744871209560.png

 

10 REPLIES 10

I don't know how you are receiving only 0x702 with this filter config:

    sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
    sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT;
    sFilterConfig.FilterIdHigh = 0x0702<<5;
    sFilterConfig.FilterIdLow = 0;
    sFilterConfig.FilterMaskIdHigh = 0x704<<5;
    sFilterConfig.FilterMaskIdLow = 0;

With this config you will receive all the IDs from 0x000 to 0x7FF because you have the second configuration is set to 0:

sFilterConfig.FilterMaskIdHigh = 0;
sFilterConfig.FilterMaskIdLow = 0;

I'm suspecting something in your code. If you have other filter configs please remove them and keep only this one:

    sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
    sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT;
    sFilterConfig.FilterIdHigh = 0x0700<<5;
    sFilterConfig.FilterIdLow = 0x0700<<5;
    sFilterConfig.FilterMaskIdHigh = 0x0F00<<5;
    sFilterConfig.FilterMaskIdLow = 0x0F00<<5;

With this config you will receive only the IDs from 0x700 to 0x7FF. Use loopback mode if it was not the case.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.