2023-12-15 3:35 AM
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
Solved! Go to Solution.
2023-12-15 5:42 AM
Hello,
It works well on an STM32F769 NUCLEO board:
This is my IAR screenshot and I'm receiving the two IDs:
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?
2023-12-15 3:45 AM
2023-12-15 3:56 AM
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
2023-12-15 4:42 AM
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?
2023-12-15 5:42 AM
Hello,
It works well on an STM32F769 NUCLEO board:
This is my IAR screenshot and I'm receiving the two IDs:
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?
2023-12-15 5:45 AM
Thank you, I will have a look.
Yes I am using CAN2 and can not change it.
2023-12-15 6:01 AM - edited 2023-12-15 6:02 AM
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.
2024-01-03 2:25 AM
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
2024-01-03 7:08 AM
As your first question was answered this thread is closed, please open a new thread for your latest question.
Thank you for your understanding.