cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F302R6 and CAN

ssurneed
Associate II
Posted on October 04, 2016 at 15:01

Hello. After the initialization CAN interface and call HAL_CAN_Receive_IT function (& hcan, CAN_FIFO0) there is no interruption USB_LP_CAN_RX0_IRQ Handler (); when receiving the CAN package. And accordingly misses the HAL_CAN_RxCpltCallback function (CAN_HandleTypeDef * CanHandle).

Although the function HAL_CAN_Receive (& hcan, CAN_FIFO0, 100); It takes the parcel. Transfer works fine. What can be wrong?

void MX_CAN_Init(void)
{
hcan.Instance = CAN;
hcan.Init.Prescaler = 24;
hcan.Init.Mode = CAN_MODE_NORMAL; //CAN_MODE_LOOPBACK CAN_MODE_NORMAL
hcan.Init.SJW = CAN_SJW_1TQ;
hcan.Init.BS1 = CAN_BS1_3TQ;
hcan.Init.BS2 = CAN_BS2_4TQ;
hcan.Init.TTCM = DISABLE;
hcan.Init.ABOM = DISABLE;
hcan.Init.AWUM = DISABLE;
hcan.Init.NART = DISABLE; //ENABLE //DISABLE
hcan.Init.RFLM = DISABLE;
hcan.Init.TXFP = DISABLE;
if (HAL_CAN_Init(&hcan) != HAL_OK)
{
Error_Handler();
}
// на�?траиваем фильтр — приём в�?ех по�?ылок
CAN_FilterConfTypeDef canFilterConfig;
canFilterConfig.FilterNumber = 0;
canFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
canFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
canFilterConfig.FilterIdHigh = 0x0000;
canFilterConfig.FilterIdLow = 0x0000;
canFilterConfig.FilterMaskIdHigh = 0x0000 << 5;
canFilterConfig.FilterMaskIdLow = 0x0000;
canFilterConfig.FilterFIFOAssignment = CAN_FIFO0;
canFilterConfig.FilterActivation = ENABLE;
canFilterConfig.BankNumber = 0;
HAL_CAN_ConfigFilter(&hcan, &canFilterConfig);
if (HAL_CAN_Receive_IT(&hcan, CAN_FIFO0) != HAL_OK)
{
/* Reception Error */
Error_Handler();
}
}

#stm32f302r6 #hal_can_receive_it
4 REPLIES 4
Walid FTITI_O
Senior II
Posted on October 04, 2016 at 16:53

Hibarinov.denis

, It is related to a recent reported bug in Receive function about FiFONumber. It is under fix phase. Meanwhile , add the following line into can_Receive_IT() function before FMI line :

hcan->pRxMsg->FIFONumber = FIFONumber;

-Hannibal-
ssurneed
Associate II
Posted on October 05, 2016 at 09:01

Hi, Hannibal.

I've made everything,accordingly to your advice, but it doesn't work. CAN_Receive_IT() is invoked from HAL_CAN_IRQHandler()

, and HAL_CAN_IRQ_Handler() is invoked from USB_LP_CAN_RX0_IRQHandler().

The problem is that USB_LP_CAN_RX0_IRQHandler() doesn't work, so HAL_CAN_IRQHandler() and CAN_Receive_IT() are not invoked.

But  HAL_CAN_Receive(&hcan, CAN_FIFO0, 100) is receiving packets throught CAN.

Have no idea, what is going on there.

ssurneed
Associate II
Posted on October 07, 2016 at 09:34

Problem solved. It turns out it is necessary to initialize the first USB, and then the CAN.

Posted on December 26, 2017 at 23:13

I'm having the same issue trying to port CAN code from the eval CAN Networking example.  So how do you 'initialize the first USB' before doing the CAN_Config()?