2021-03-13 05:24 AM
Hi, I want to make a bridge between 2 CAN BUSes with STM32F4. I am trying to listen of interrupts of both CAN on HAL_CAN_RxFifo0MsgPendingCallback and receive a message and send it to another CAN, but it seems that I only receive CAN1 interrupt. CAN2 does not trigger interupt.
I use same filter configurations for both BUSes:
//hcan - CAN1 and CAN2
CAN_FilterTypeDef sFilterConfig;
sFilterConfig.FilterBank = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = 0x0000;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 14;
if (HAL_CAN_ConfigFilter(hcan, &sFilterConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_CAN_Start(hcan) != HAL_OK)
{
Error_Handler();
}
if (HAL_CAN_ActivateNotification(hcan, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
{
Error_Handler();
}
Why does CAN2 do not work as expected?
Solved! Go to Solution.
2021-03-13 06:53 AM
2021-03-13 06:05 AM
>>Why does CAN2 do not work as expected?
CAN2 needs to use filters in the banks that belong to it.
You've selected a 14/14 split of the 28 filters, 0 being in the CAN1 half
2021-03-13 06:32 AM
Which ones should I select correctly?
I have also tried:
// CAN1
sFilterConfig.FilterBank = 0;
sFilterConfig.SlaveStartFilterBank = 14
// CAN2
sFilterConfig.FilterBank = 14;
sFilterConfig.SlaveStartFilterBank = 27
But seems it still did not work.
2021-03-13 06:53 AM
2021-03-13 08:40 AM
It seems to work! Thanks!
My final config:
// CAN1
sFilterConfig.FilterBank = 0;
sFilterConfig.SlaveStartFilterBank = 14
// CAN2
sFilterConfig.FilterBank = 14;
sFilterConfig.SlaveStartFilterBank = 14