cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407VET CAN BUS interrupt does not trigger

JBond.1
Senior

Hi, I am trying to communicate on CAN BUS, I have previously succeeded in doing so with STM32F103C8 and STM32F091RC, but I cant make it work on STM32F407VET It does not trigger its interrupt on message receive. What could be the difference on this MCU? Do I need to enable something different?

MCU clock 168Mhz, APB1 42Mhz, CAN BUS speed is 100000bit/s, enabled "CAN1 RX0 interrupts" in NVIC, code:

hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 28;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_12TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = ENABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
	Error_Handler();
}
 
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(hcan1, &sFilterConfig) != HAL_OK)
{
	Error_Handler();
}
 
if (HAL_CAN_Start(hcan1) != HAL_OK)
{
	Error_Handler();
}
 
if (HAL_CAN_ActivateNotification(hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
{
	Error_Handler();
}

I am expecting to get callback on:

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
}

But its never executed. I tried to set break point on, but it does not brake there ether:

/**
  * @brief This function handles CAN1 RX0 interrupts.
  */
void CAN1_RX0_IRQHandler(void)
{
  /* USER CODE BEGIN CAN1_RX0_IRQn 0 */
 
  /* USER CODE END CAN1_RX0_IRQn 0 */
  HAL_CAN_IRQHandler(&hcan1);
  /* USER CODE BEGIN CAN1_RX0_IRQn 1 */
 
  /* USER CODE END CAN1_RX0_IRQn 1 */
}

 What could be the problem?

I dont know what to trouble shoot next.

14 REPLIES 14

Both MCU has external transceivers, I switched places to make sure that both transceivers work. STM32F091 works on both of them, STM32F407 does not.

Hi,

Probably You have problem with settings of SystemClock.

You have on the board STM32F4VE 8 MHz external resonator?

If yes, please change value from RCC_OscInitStruct.PLL.PLLM = 25 to RCC_OscInitStruct.PLL.PLLM = 8,

Best Regards,

Slawek

Thanks for your reply! Indeed its issue with SystemClock, I have 8Mhz external resonator, not sure why its by default 25Mhz. I have changed settings:

0693W000008wkLXQAY.pngNow I am able to send CAN BUS messages from STM32F4 and other can read them!

But STM32F4 is still not receiving messages, interrupt is not triggering...

Hi,

Please add in Your function:

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
	led = !led;
	GPIO_SetLed(!led);
	GPIO_SetLed2(led);
}

function HAL_CAN_GetRxMessage

I think so You should get the data from the bufor FIFO RX.

Best Regards,

Slawek

Thank you! I found another root cause. It seems that ST-Link and MCU must share same power supply or ground and then I receive CAN BUS interrupts!

Yes I should also use HAL_CAN_GetRxMessage as you said.

So there were 2 root causes SystemClock and common ground or power supply with debugger. Do you know why does it need common ground?

Again thanks for your help, I was loosing hope!