Struggling with CAN Filter
Dear Community,
Once again I am struggling with CAN Filters for extended IDs using CAN2 on a STM32F765.
I have the ID 0x010100 and the filter should look like 0xXX0101XX where the X hex should be ignored.
One of my early approaches:
uint32_t filter_id = 0x010100;
uint32_t filter_mask = 0x1F0000FF;
CAN_FilterTypeDef can_addr_filter;
can_addr_filter.FilterActivation = CAN_FILTER_ENABLE;
can_addr_filter.FilterFIFOAssignment = CAN_FILTER_FIFO0;
can_addr_filter.FilterBank = 0;
can_addr_filter.SlaveStartFilterBank = 0;
can_addr_filter.FilterMode = CAN_FILTERMODE_IDMASK;
can_addr_filter.FilterScale = CAN_FILTERSCALE_32BIT;
can_addr_filter.FilterIdHigh = filter_id << 3; //Tried different shifts, didn't worked
can_addr_filter.FilterIdLow = 0;
can_addr_filter.FilterMaskIdHigh = filter_mask << 3; //Tried different shifts, didn't worked
can_addr_filter.FilterMaskIdHigh = 0;
if(HAL_CAN_ConfigFilter(&hcan2, &can_addr_filter) != HAL_OK)
{
error_handler(CAN_HW_ERROR);
return;
}
When sending a message to 0x010112 it works as expected
But when sending a message to 0x010013 it works against my expectations
Sending a message to 0x020112 does not work as expected.
Using different FilterIdHigh and FilterIdLow aswell different FilterMaskIdHigh and FilterMaskIdLow settings I can't get it working.
I probably made a *** mistake at one point...
I would be very grateful if someone could help me so that I can finally understand the CAN filter and find my error. Preferably as an explanation for a 5 year old so I don't have to ask again about filters.
Warmest regards
Anno
