cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] CAN callback never call

AJouv
Associate II

I'm working on an STM32L431 and I never be call on HAL_CAN_RxFifo0MsgPendingCallback. I have set a break point in this function but the debugger never stop on it.

In my program:

  • I have generated the code using CubeMx and I set NVIC on CAN1: Tx, RX0, RX1 and SCE
  • The cubeMx init is:
void MX_CAN1_Init(void)
{
 
  hcan1.Instance = CAN1;
  hcan1.Init.Prescaler = 5;
  hcan1.Init.Mode = CAN_MODE_NORMAL;
  hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
  hcan1.Init.TimeSeg1 = CAN_BS1_13TQ;
  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();
  }
 
}

  • I have disable CAN filters
  • I already call HAL_CAN_ActivateNotification w/o any error returned:
(HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING)
  • Please see my CAN init:
void canDriver_init( ){
 
	// First of all enable the CAN
	HAL_GPIO_WritePin(EN_CAN_GPIO_Port, EN_CAN_Pin, GPIO_PIN_RESET);
 
	CAN_FilterTypeDef  		sFilterConfig;
 
	sFilterConfig.FilterIdHigh = 0x320 << 5;
	sFilterConfig.FilterIdLow = 0;
	sFilterConfig.FilterMaskIdHigh = 0xFFF << 5;
	sFilterConfig.FilterMaskIdLow = 0;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
	sFilterConfig.FilterBank = 0;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterActivation = DISABLE;
	sFilterConfig.SlaveStartFilterBank = 14;
 
	if (HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig) != HAL_OK)
	{
		/* Filter configuration Error */
		Error_Handler();
	}
 
	/* Start the CAN peripheral */
	if (HAL_CAN_Start(&hcan1) != HAL_OK)
	{
		/* Start Error */
		Error_Handler();
	}
 
	/* Activate CAN RX notification */
	if (HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK) {
		/* Notification Error */
		Error_Handler();
	}
 
	TxHeader.StdId = 0x320;			/* Specify the remote CAN node address			*/
	TxHeader.ExtId = 0x01;			/* Not used here								*/
	TxHeader.RTR = CAN_RTR_DATA;	/* Data Frame type (Data or Commands)			*/
	TxHeader.IDE = CAN_ID_STD;		/* Standard frame but not Extended				*/
	TxHeader.DLC = 2;				/* Number of data size in bytes (from 0 to 8)*/
	TxHeader.TransmitGlobalTime = DISABLE;
 
}

My test:

  • Send frame using my code

=> I already receive it in my CAN analyzer

  • I set a breakpoint in HAL_CAN_RxFifo0MsgPendingCallback()
  • Using a CAN analyzer I send CAN frame

=> but those frame never be received by the STM32 (I already see the hardware signal on the medium using an oscilloscope)

Thanks for your help

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
AJouv
Associate II

I slove the issue by activate the filtre:

	CAN_FilterTypeDef  		sFilterConfig;
	sFilterConfig.FilterIdHigh = 0x0000;
	sFilterConfig.FilterIdLow = 0x0000;
	sFilterConfig.FilterMaskIdHigh = 0x0000;
	sFilterConfig.FilterMaskIdLow = 0x0000;
	sFilterConfig.FilterFIFOAssignment = 0;
	sFilterConfig.FilterBank = 0;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

If the FilterActivation is not ENABLE it was impossible to receive CAN frame.

View solution in original post

4 REPLIES 4
Glen Cook_2
Associate III

The code looks fine. I would first try fully opening the can filter to let everything through, see if anything triggers the interrupt.

AJouv
Associate II

Hello @Community member​ ,

First of all, Thanks for your help.

In my understanding, the filter is already disable and not used in my config because I have set:

sFilterConfig.FilterActivation = DISABLE;

is it true ?

AJouv
Associate II

Anyone have an idea to help me ?

Thanks

AJouv
Associate II

I slove the issue by activate the filtre:

	CAN_FilterTypeDef  		sFilterConfig;
	sFilterConfig.FilterIdHigh = 0x0000;
	sFilterConfig.FilterIdLow = 0x0000;
	sFilterConfig.FilterMaskIdHigh = 0x0000;
	sFilterConfig.FilterMaskIdLow = 0x0000;
	sFilterConfig.FilterFIFOAssignment = 0;
	sFilterConfig.FilterBank = 0;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;

If the FilterActivation is not ENABLE it was impossible to receive CAN frame.