2023-11-16 11:55 PM
Hi
Many CAN messages are flowing on the CAN bus.
I would like to receive only ID 0x5C0 among these.
Please let me know the suitable settings to receive only 0x5C0 as a hardware filter without any software intervention, without any load on the MCU.
I wrote the code below. Naturally, I think ID mask mode is better.
I don't understand the settings for sFilterConfig.FilterMaskIdHigh and sFilterConfig.FilterMaskIdLow.
Is this correct?
Solved! Go to Solution.
2023-11-17 8:44 AM
Hello @Ukazu ,
In your case use ID list instead of ID Mask config.
Try the following:
sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT;
sFilterConfig.FilterIdHigh = canId <<5;
sFilterConfig.FilterIdLow = canId <<5;
sFilterConfig.FilterMaskIdHigh = canId <<5;
sFilterConfig.FilterMaskIdLow = canId <<5;
2023-11-17 8:44 AM
Hello @Ukazu ,
In your case use ID list instead of ID Mask config.
Try the following:
sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT;
sFilterConfig.FilterIdHigh = canId <<5;
sFilterConfig.FilterIdLow = canId <<5;
sFilterConfig.FilterMaskIdHigh = canId <<5;
sFilterConfig.FilterMaskIdLow = canId <<5;
2023-11-17 9:03 AM
void CanFilterConfig ( uint8_t filterNum, uint8_t fifoNum, uint32_t canId )
{
CAN_FilterTypeDef sFilterConfig;
sFilterConfig.FilterBank = filterNum;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = canId << 5; // Comparator
sFilterConfig.FilterIdLow = 0x00000000U;
sFilterConfig.FilterMaskIdHigh = 0x7FFU << 5; // Mask 11-bit
sFilterConfig.FilterMaskIdLow = 0;
sFilterConfig.FilterFIFOAssignment = fifoNum;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 14; // CAN1 / CAN2 split for FilterBank
(void)HAL_CAN_ConfigFilter( &hcan, &sFilterConfig );
}
2023-11-19 3:31 PM
Thank you.
An ID list is used to receive one CAN message (0x5C0) on a bus where many CAN messages flow. I've been wrong until now.
Should I use an ID list instead of an ID mask?
I received only 0x5C0
The example you advised is CAN_FILTERSCALE_16BIT, and canId <<5 is entered in FilterIdHigh and FilterIdLow.
FilterMaskIdHigh and FilterMaskIdLow are also filled with canId <<5.
What does this mean?
0x5C0 not received into two buffers?
2023-11-19 3:44 PM
Do you think it is best practice to use ID masks or ID lists?
2023-11-19 8:46 PM
When the filter scale register (CAN_FS1R) is set to 16bit in ID list mode, there are CAN_FiR1 and CAN_FiR2, so if you want to receive only one CAN message, set 0x5C0 to the upper and lower of CAN_FiR1 and the upper and lower of CAN_FiR2. That means setting it!
If 0x5C0 is set only in the upper part of CAN_FiR1, and nothing is set in the lower part of CAN_FiR1 and the upper and lower parts of CAN_FiR2, what will happen to the movement of CAN resources? Are you trying to receive 0x000?