cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Rx interrupt not generating on STM32f103c8t6(STM32 BLUEPILL)

Suryaprakash2002
Associate II

I have stm32 bluepilll on which I am able to transmit CAN messages but CAN Receive interrupt is not generating.

Suryaprakash2002_0-1695524100732.png

I found while configuring that CAN RX pin(GPIO mode) is getting configured as Input mode. How accurate is this?

I  think it should be Alternate function. I made PB8 as Alternate function still CAN Rx interrupt is not working.

Suryaprakash2002_1-1695524271194.png

Suryaprakash2002_2-1695524361169.png

Above statements are under stm32f1xx_hal_msp.c

I am using CAN RX1 interrupt, following are  my configurations

static void MX_CAN_Init(void)

{

 

/* USER CODE BEGIN CAN_Init 0 */

 

/* USER CODE END CAN_Init 0 */

 

/* USER CODE BEGIN CAN_Init 1 */

 

/* USER CODE END CAN_Init 1 */

hcan.Instance = CAN1;

hcan.Init.Prescaler = 9;

hcan.Init.Mode = CAN_MODE_NORMAL;

hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;

hcan.Init.TimeSeg1 = CAN_BS1_3TQ;

hcan.Init.TimeSeg2 = CAN_BS2_4TQ;

hcan.Init.TimeTriggeredMode = DISABLE;

hcan.Init.AutoBusOff = ENABLE;

hcan.Init.AutoWakeUp = DISABLE;

hcan.Init.AutoRetransmission = ENABLE;

hcan.Init.ReceiveFifoLocked = DISABLE;

hcan.Init.TransmitFifoPriority = DISABLE;

if (HAL_CAN_Init(&hcan) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN CAN_Init 2 */

CAN_FilterTypeDef canfilterconfig;

 

canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;

canfilterconfig.FilterBank = 18; // which filter bank to use from the assigned ones PA11

canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO1;

canfilterconfig.FilterIdHigh = 0x00000103<<5;

canfilterconfig.FilterIdLow = 0;

canfilterconfig.FilterMaskIdHigh = 0x00000103<<5;

canfilterconfig.FilterMaskIdLow = 0x0000;

canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;

canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;

canfilterconfig.SlaveStartFilterBank = 20; // how many filters to assign to the CAN1 (master can)

 

HAL_CAN_ConfigFilter(&hcan, &canfilterconfig);

 

if (HAL_CAN_Start(&hcan)!= HAL_OK)

{

Error_Handler();

}

HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO1_MSG_PENDING);

/* USER CODE END CAN_Init 2 */

 

}

 

void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan)

{

HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO1, &RxHeader, RxData);

if (RxHeader.StdId == 0x0000103)

{

rx=1;

}

}

12 REPLIES 12
SRedd.5
Senior III

__weak void HAL_CAN_RxFifo0FullCallback(CAN_HandleTypeDef *hcan)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hcan);

/* NOTE : This function Should not be modified, when the callback is needed,
the HAL_CAN_RxFifo0FullCallback could be implemented in the user
file
*/
}

Why can't you use this function for receive message? I generated the project using your micro part number.

Jannaros
Associate II

Hello, i have the same configuration Suryaprakash2002. CAN RX does not trigger also for me. I do not know what to do. CAN TX transmit well, CAN RX does not trigger. The scope shows the recieved CAN at the CAN_RX PA8 PIN. What i noticed is that after a can message received the CAN TX pin PA9 goes for some bits(2 or 3) low and then high again. 

Any ideas?

Best regards

CAN RX1 interrupt it does not work. You do not have to change the filters.

I found an alternative solution for not triggering the interrupt:

At CubeMX go at Connectivity->CAN->Configuration->NVIC->

 -USB low priority or CAN RX0 interrupt  (activate)

 -CAN RX1 interrupt  (deactivate)

Then the CAN communications works well.