2022-11-22 12:35 PM
I cannot get the CAN bus CAN1_RX0 interrupt to fire. I have two other development boards (STM32429i-EVAL1 and STM32373C-eval) that both work correctly. I am using the same code in each setup thru the ST MX and IDE. The Eval boards have built in CAN interface, so on the Nucleo board I am using a CAN adapter.
I have a USB CAN device to receive and send CAN messages to boards. I also have a CAN logic analyzer verifying messages.
So on the NUCLEO board I am able to verify the CAN message being received is correct on the port PINS PB8 and PB9. tried configuring CAN1_RX to PA11 also, same result.
I have gone back and forth between boards and project trying to find a difference or reason I cannot receive the CAN interrupt on the Nucleo board!
I have attached the Nucleo project.
Any help would be appreciated.
2022-11-22 01:45 PM
Filter looks like it would reject everything..
2022-11-22 02:18 PM
FilterMaskIDHigh and Low set to 0x0. I believe that will allow everything.
Normally I had it set to 0xFFFF so that only ID 0x245 would be let thru. That is how the other projects have worked, 0x0 allow everything, 0xF only allows FilterID.
If I am wrong, please advise correct way.
2022-11-22 02:52 PM
IF ((PATTERN & FilterMaskId) == FilterId) THEN TAKE
2022-11-22 03:20 PM
pTxHeader.DLC=2;
pTxHeader.IDE=CAN_ID_EXT;
pRxHeader.IDE=CAN_ID_STD;
pTxHeader.RTR=CAN_RTR_DATA;
//pTxHeader.StdId=0x20; //0x244;
pTxHeader.ExtId=0x20;
uint8_t message[2] = {'A','B'};
sFilterConfig.FilterFIFOAssignment=CAN_FILTER_FIFO0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
/* High ID must be shifted by <<5 and low shifted by >> 3*/
sFilterConfig.FilterIdHigh=0x245<<5; //0x245<<5;
sFilterConfig.FilterIdLow=0x245<<3; //0x245<<3;
sFilterConfig.FilterMaskIdHigh=0xFFFF;//If filter is F it must match ID
sFilterConfig.FilterMaskIdLow=0xFFFF;
sFilterConfig.FilterScale=CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterActivation=CAN_FILTER_ENABLE;
HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig);
Still not receiving.
2022-11-22 03:28 PM
Cause its STILL broken
Try the TAKE EVERYTHING pattern
2022-11-22 03:39 PM
TAKE STDID 0x245
sFilterConfig.FilterIdHigh=0x245 << 5;
sFilterConfig.FilterIdLow=0;
sFilterConfig.FilterMaskIdHigh=0x7FF << 5;
sFilterConfig.FilterMaskIdLow=0;
2022-11-22 03:50 PM
TAKE EXTID 0x245
sFilterConfig.FilterIdHigh=0;
sFilterConfig.FilterIdLow=0x245 << 3; // | 8 for IDE bit
sFilterConfig.FilterMaskIdHigh=0xFFFF;
sFilterConfig.FilterMaskIdLow=0x1FFF << 3; // | 8 for IDE bit
2022-11-23 07:07 AM
I tried all of your suggested config, but same result. Will not receive interrupt.
Again, any of these configurations will work correctly with other demo boards. Apparently, I am missing something with the setup of this F446 board. As you can see in the above graph, the logic analyzer is showing correct received CAN message on the pins PB8 and PB9 directly on the board so I have to assume the CAN adapter board is working, plus as you can also see, the F446 board is correctly transmitting the CAN message (and these are again going thru the CAN adapter).
I have even tried reconfiguring the board changing the CAN1_RX pin from PB8 to PA11. I assumed the port pin was damaged, but i get same result on PA11.
2022-11-30 10:16 AM
I figured out the issue! The RX interrupt needs to be "Activated". It is not enough to enable the RX interrupt in the MX .ioc file,
You must call:
HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING);// Initialize CAN Bus Rx Interrupt
/* USER CODE BEGIN CAN_Init 2 */
HAL_CAN_Start(&hcan);
HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING);// Initialize CAN Bus Rx Interrupt
/* USER CODE END CAN_Init 2 */
Now it will interrupt on RX0_IRQ