cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Dual CAN on STM32F4

JBond.1
Senior

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?

1 ACCEPTED SOLUTION

Accepted Solutions
  1. sFilterConfig.FilterBank = 14;
  2. sFilterConfig.SlaveStartFilterBank = 14; // Where the split between the two falls

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4

>>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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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.

  1. sFilterConfig.FilterBank = 14;
  2. sFilterConfig.SlaveStartFilterBank = 14; // Where the split between the two falls

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

It seems to work! Thanks!

My final config:

    // CAN1
    sFilterConfig.FilterBank = 0;
    sFilterConfig.SlaveStartFilterBank = 14
     
    // CAN2
    sFilterConfig.FilterBank = 14;
    sFilterConfig.SlaveStartFilterBank = 14