Skip to main content
JBond.1
Senior
Mar 13, 2021 1:24 PM UTC
Solved

How to use Dual CAN on STM32F4

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?

This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Mar 13, 2021 2:53 PM UTC
  1. sFilterConfig.FilterBank = 14;
  2. sFilterConfig.SlaveStartFilterBank = 14; // Where the split between the two falls

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

4 replies

Tesla DeLorean
Guru
Mar 13, 2021 2:05 PM UTC

>>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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
JBond.1
JBond.1Author
Senior
Mar 13, 2021 2:32 PM UTC

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.

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Mar 13, 2021 2:53 PM UTC
  1. sFilterConfig.FilterBank = 14;
  2. sFilterConfig.SlaveStartFilterBank = 14; // Where the split between the two falls

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