cancel
Showing results for 
Search instead for 
Did you mean: 

CAN ExtID filter for exactly two IDs

Anno
Associate II

Dear Community,

 

even after reading what feels like 100 posts, I still can't manage to set the filter so that exclusively 2 IDs are let through.

I use the extendet ID, 1 Byte IDs and have managed to let exactly one ID through with the MASK_MODE, as you can see here:

 

canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
canfilterconfig.FilterBank = 1;
canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;

canfilterconfig.FilterIdHigh = CAN_ModuleAddr<<3;
canfilterconfig.FilterIdLow = 0;

canfilterconfig.FilterMaskIdHigh = 0xF<<3; //Only the Address Bits will be compared
canfilterconfig.FilterMaskIdLow = 0x0000;

canfilterconfig.FilterFIFOAssignment = CAN_RX_FIFO0;
canfilterconfig.SlaveStartFilterBank = 1;

 

Now I not only want to let the CAN_ModuleAddr through, but also the ID 0xFF.

I would be infinitely grateful for any tips, illustrative material or further help.

 

Warmest regards
Anno

 

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Hello,

It works well on an STM32F769 NUCLEO board:

This is my IAR screenshot and I'm receiving the two IDs:

SofLit_0-1702647610220.png

Attached the project with which I got this result.

So please double check your CAN config as well as your filter config. Are you using CAN2?

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.

View solution in original post

8 REPLIES 8
SofLit
ST Employee

Hello @Anno ,

Here you need to configure the filter in ID list mode.

One ID: Mask mode. More than one specific ID:  ID list.

See this thread.

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.
SofLit
ST Employee

I didn't test it, but try it:

#define REMOTE_FRAME   0 /* If = 1 the frame should be a remote frame. If = 0 the frame will be a data frame */
#define EXTID          1 /* If = 0 the frame should be a frame with standard ID. If = 1 the frame should be a frame with extended ID */

#define ID1   0x12345678
#define ID2   0x1ABCDEF0

#define FILTER_ID    ((ID1 << 3) | (REMOTE_FRAME<<1) | (EXTID <<2))  // ID1 = 0x12345678 (FxFR1[31:0])
#define FILTER_MASK  ((ID2 << 3) | (REMOTE_FRAME<<1) | (EXTID <<2))  // ID2 = 0x1ABCDEF0 (FxFR2[31:0])
  
  sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
  sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
  sFilterConfig.FilterIdHigh = (FILTER_ID >> 16);          // Filter ID2 LSB   (FxFR2[0:15])
  sFilterConfig.FilterIdLow = (FILTER_ID & 0xFFFF);        // Filter ID1 LSB   (FxFR1[0:15])
  sFilterConfig.FilterMaskIdHigh = (FILTER_MASK >> 16);    // Filter ID2 MSB   (FxFR2[16:31])
  sFilterConfig.FilterMaskIdLow = (FILTER_MASK & 0xFFFF);  // Filter ID1 MSB   (FxFR1[16:31])

 It receives two extended IDs: 0x12345678 and 0x1ABCDEF0

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.
Anno
Associate II

Hey, thank you for your fast reply.

I tested your code and it is not working. Sending messages to 0x12345678 or 0x1ABCDEF0 won't interrupt through the callback function.

 

I use the other Bits of the Extendet ID as commands, as follow 

            |ID             | |Command                          |
|0|0|0|0|0| |0|0|0|0|0|0|0|0| |0|0|0|0|0|0|0|0| |0|0|0|0|0|0|0|0|

These are variable. Wouldn't I have to put a mask over the list so that only the ID bits are taken into account?

 

 

SofLit
ST Employee

Hello,

It works well on an STM32F769 NUCLEO board:

This is my IAR screenshot and I'm receiving the two IDs:

SofLit_0-1702647610220.png

Attached the project with which I got this result.

So please double check your CAN config as well as your filter config. Are you using CAN2?

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.

Thank you, I will have a look.

 

Yes I am using CAN2 and can not change it.

SofLit
ST Employee

Using CAN2 is another story ..

1- You need to enable CAN1 RCC clock (__HAL_RCC_CAN1_CLK_ENABLE()) even if it was not used.

2- Regarding the filtering you need to take care about these two parameters:

.SlaveStartFilterBank and .FilterBank.

Please read the attached text file.

 

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.

With your explanation and the knowledge that the behavior is different with CAN2, I tried the example you gave above and it works. Many thanks for that!

Only the two extended IDs are really allowed through here. How can I adjust the filter here so that only a certain area of the bits is looked at? Just as I mentioned at the beginning.

No matter how I adjust the filter mask, it doesn't work. Is there something I'm missing?
Do I have to put a submask over it again at the end?

 

Many thanks for your help and a happy new year

As your first question was answered this thread is closed, please open a new thread for your latest question.

Thank you for your understanding.

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.