cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F405 RX0 Interrupt won't activate, wrong filter configuration?

Ubus99
Associate III

Hi, I am trying to receive CAN message on a F405, but the Rx interrupt doesn't trigger. Sending works fine however.

I am also in doubt about the

CAN1_RX0_IRQHandler

because I can't find any documentation when it is triggered, the HAL manual only refers to

HAL_CAN_RxFifo0MsgPendingCallback

neither of which work.

My init code:

HAL_CAN_ActivateNotification(&hcan1,
	CAN_IT_RX_FIFO0_MSG_PENDING || CAN_IT_TX_MAILBOX_EMPTY);
	userCANFilterSetup(&hcan1);
	HAL_CAN_Start(&hcan1);
 
//-------------
 
static void MX_CAN1_Init(void) {
 
	/* USER CODE BEGIN CAN1_Init 0 */
 
	/* USER CODE END CAN1_Init 0 */
 
	/* USER CODE BEGIN CAN1_Init 1 */
 
	/* USER CODE END CAN1_Init 1 */
	hcan1.Instance = CAN1;
	hcan1.Init.Prescaler = 3;
	hcan1.Init.Mode = CAN_MODE_NORMAL;
	hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
	hcan1.Init.TimeSeg1 = CAN_BS1_9TQ;
	hcan1.Init.TimeSeg2 = CAN_BS2_4TQ;
	hcan1.Init.TimeTriggeredMode = DISABLE;
	hcan1.Init.AutoBusOff = ENABLE;
	hcan1.Init.AutoWakeUp = ENABLE;
	hcan1.Init.AutoRetransmission = DISABLE;
	hcan1.Init.ReceiveFifoLocked = DISABLE;
	hcan1.Init.TransmitFifoPriority = DISABLE;
	if (HAL_CAN_Init(&hcan1) != HAL_OK) {
		Error_Handler();
	}
	/* USER CODE BEGIN CAN1_Init 2 */
	HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 0, 0); // todo why, just why?
	HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
	/* USER CODE END CAN1_Init 2 */
 
}
 
void userCANFilterSetup(CAN_HandleTypeDef *hcan) {
 
	CAN_FilterTypeDef sFilterConfig;
 
	sFilterConfig.FilterIdHigh = 0x0000;					//Filter 1 = 0
	sFilterConfig.FilterMaskIdHigh = 0xFFFF;		//Mask 1 = accept any MSB
 
	sFilterConfig.FilterIdLow = 0x0200 << 5;			//Filter 2 = MsgID 0x200
	sFilterConfig.FilterMaskIdLow = 0x0200 << 5;		//Mask 2 = MsgID 0x200
 
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
	sFilterConfig.FilterBank = 0;						//Filter Register 0 / 2
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;		//Maske per ID
	sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT;//2x 16bit Masken per Filter
	sFilterConfig.FilterActivation = ENABLE;
 
	HAL_CAN_ConfigFilter(hcan, &sFilterConfig);
 
}

Messages with ID 0 or 200 should get through, but I don't know if it's the filter or the interrupt.

I tried not initializing a filter at all as well, but that didn't work either, I suspect that the whitelist just remains empty.

2 REPLIES 2

Read out and check/post the relevant CAN registers. Observe CAN_RFxR.FMP field. If it's nonzero, check if you have enabled the Rx interrupt in CAN and in NVIC and if the ISR's address is at the proper position in the vector table. Some other interrupt-related hints here.

JW

I found the problem:

0693W00000AMnClQAL.pngFor some reason, the CAN_IT_RX_FIFO0_MSG_PENDING bit is not set, it should be in FMPIE0...

>> got it: the new compiler expects a | operator, not ||, it used to work.