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

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?

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.

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

Suryaprakash2002_0-1695530338596.png

This messages are transferred from MCU.I am able to see them on PC.

SRedd.5
Senior III

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
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.
Suryaprakash2002
Associate II

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

Transmit different message IDs try to disable filter and check. 

I tried its not helping.