cancel
Showing results for 
Search instead for 
Did you mean: 

bxCAN acceptance filter configuration.

DKarc
Associate II

Hi,

I'm using CubeMX to init CAN module, everything is working, I can send and receive messages.

Now I would like to configure filter to accept only message with specified ID.

So, I have this piece of code generated by CUBE:

//sFilterConfig.FilterNumber = 0;

sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

sFilterConfig.FilterIdHigh = 0x0000;

sFilterConfig.FilterIdLow = 0x0000;

sFilterConfig.FilterMaskIdHigh = 0x0000;

sFilterConfig.FilterMaskIdLow = 0x0000;

sFilterConfig.FilterFIFOAssignment = 0;

sFilterConfig.FilterActivation = ENABLE;

//sFilterConfig.BankNumber = 0;

sFilterConfig.FilterBank = 0;

sFilterConfig.SlaveStartFilterBank = 0;

HAL_CAN_ConfigFilter(&hcan, &sFilterConfig);

When I'm using this code I can accept all frames.

Like I said I need to accept only messages with specified, extended ID, for example 0x12F0AAAA, so I'm changing this lines:

sFilterConfig.FilterIdHigh = 0x12F0;

sFilterConfig.FilterIdLow = 0xAAAA;

sFilterConfig.FilterMaskIdHigh = 0x1FFF;

sFilterConfig.FilterMaskIdLow = 0xFFFF;

but when I configure filter like that I can not receive this message.

Can somebody help me with this case, I have checked web and documentation but everything seems to be ok.

Thanks, Daniel

1 REPLY 1
SVolo
Associate II

Hello.

It doesn’t work out.

If you only accept 0x12F0AAAA then

//============================

#define filter_id   0x12F0AAAA

#define filter_mask  0x1FFFFFFF

sFilterConfig.FilterIdHigh = (uint16_t) (filter_id>>13);

sFilterConfig.FilterIdLow = (uint16_t) (filter_id<<3);

sFilterConfig.FilterMaskIdHigh = (uint16_t) (filter_mask>>13);

sFilterConfig.FilterMaskIdLow = (uint16_t) (filter_mask<<3);

//============================================