Skip to main content
Associate
September 24, 2023
Question

CAN Rx interrupt not generating on STM32f103c8t6(STM32 BLUEPILL)

  • September 24, 2023
  • 7 replies
  • 5105 views

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;

}

}

This topic has been closed for replies.

7 replies

SRedd.5
Senior III
September 24, 2023

Can Tx alone cannot work if Can Tx is working it means Can Rx is working or both Can Tx and Rx are not working. How do you know that Can Tx is working?

Associate
September 24, 2023

I have an USB to CAN analyser, I am sending a CAN message under while loop which I am able to see on my PC.

From the same analyser I am sending a CAN frame whose ID is being checked under callback function.

SRedd.5
Senior III
September 24, 2023

Try to transmit message from MCU and see if you are receiving messages may be at 1sec or 100msec on the tool.

SRedd.5
Senior III
September 24, 2023

Which is your receive interrupt function, where are you putting the break point. I think you are not using the correct RxInterrupt function.

SRedd.5
Senior III
September 24, 2023
if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
{
   /* Notification Error */
   Error_Handler();
 
}
 
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
 
  if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET)
  {
    /* Retrieve Rx messages from RX FIFO0 */
    if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader1, RxData) != HAL_OK)
    {
      Error_Handler();
    }
 if (HAL_FDCAN_ActivateNotification(hfdcan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
  {
  /* Notification Error */
  Error_Handler();
  }
See if you can get some idea from above which i used for different micro. I have not put the complete code.
Associate
September 24, 2023

stm32f103c8t6 doesn't support CANFD, it supports standard and extended CAN and it has HAL_CAN_RxFifo1MsgPendingCallback.I am using CAN RX1 interrupt.

SRedd.5
Senior III
September 24, 2023

Transmit different message IDs try to disable filter and check. 

Associate
September 24, 2023

I tried its not helping.

SRedd.5
Senior III
September 24, 2023

__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
October 16, 2023

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

Jannaros
Associate
October 17, 2023

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.