Skip to main content
Vaclav Zajic
Associate III
April 12, 2018
Question

Help with CAN filter on stm32f767

  • April 12, 2018
  • 3 replies
  • 2220 views
Posted on April 12, 2018 at 10:21

Hello, I would like to be able to receive CAN message 0x200(CAN_ID_RX is 0x200) and I have a CAN filter configured like this:

sFilterConfig.FilterBank = 0;

sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;

sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

sFilterConfig.FilterIdHigh = CAN_ID_RX << 5;

sFilterConfig.FilterIdLow = 0x0000;

sFilterConfig.FilterMaskIdHigh = 0x0000;;

sFilterConfig.FilterMaskIdLow = 0x0000;

sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;

sFilterConfig.FilterActivation = ENABLE;

sFilterConfig.SlaveStartFilterBank = 14;

I don't receive any messages and by using debugger I found out that the function HAL_CAN_IRQHandler in stm32f7xx_hal_can.c is never called.

Can you help me?

Thanks 

Vaclav

#bxcan #can-filter #stm32f7
This topic has been closed for replies.

3 replies

Vaclav Zajic
Associate III
April 12, 2018
Posted on April 12, 2018 at 14:36

I found it out. 

sFilterConfig.FilterMode must be set to 

CAN_FILTERMODE_IDMASK in my case. Vaclav

Ben K
Senior III
April 12, 2018
Posted on April 12, 2018 at 14:51

1. Are you using CAN2 by any chance? If so, make sure that sFilterConfig.FilterBank >= sFilterConfig.SlaveStartFilterBank.

2. Keep in mind that you are configuring a filter bank, therefore each field will be used as a filter, depending on which type you use. For 32 bit list mode 1 filter bank = 2 filters, for 16 bit list mode 1 filter bank = 4 filters. Therefore leaving those fields empty will result in receiving frames with ID = 0.

So here's the correct setting for only passing 0x200 (the filter bank numbering is left for you to correct):

sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT;
sFilterConfig.FilterIdHigh = CAN_ID_RX << 5;
sFilterConfig.FilterIdLow = CAN_ID_RX << 5;
sFilterConfig.FilterMaskIdHigh = CAN_ID_RX << 5;
sFilterConfig.FilterMaskIdLow = CAN_ID_RX << 5;�?�?�?�?�?�?

or using 32 bit mode:

sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = CAN_ID_RX << 5;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = CAN_ID_RX << 5;
sFilterConfig.FilterMaskIdLow = 0x0000;�?�?�?�?�?�?

Vaclav Zajic
Associate III
April 12, 2018
Posted on April 12, 2018 at 16:04

I am using CAN1.

The filter setup is now:

FilterConfig.FilterBank = 0;

sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

sFilterConfig.FilterIdHigh = CAN_ID_RX << 5;

sFilterConfig.FilterIdLow = 0x0000;

sFilterConfig.FilterMaskIdHigh = CAN_ID_RX << 5;

sFilterConfig.FilterMaskIdLow = 0x0000;

sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;

sFilterConfig.FilterActivation = ENABLE;

sFilterConfig.SlaveStartFilterBank = 14;

I put a breakpoint in function HAL_CAN_RxFifo0MsgPendingCallback.

When I sent a message with StdID lower than 0x200, the breakpoint is not reached and when the StdID is higher than 0x200, the breakpoint is reached.   

When the breakpoint is reached, value of StdID is still shown as 0 at the watch window.

Thanks for help  

Vaclav Zajic
Associate III
April 16, 2018
Posted on April 16, 2018 at 14:06

Any ideas?

Vaclav Zajic
Associate III
April 20, 2018
Posted on April 20, 2018 at 17:26

There was a problem with the USB to CAN interface setup. I mismatched StdID and ExtID in the program for sending and receiving messages. Everything works now. Vaclav