cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F042 CAN bus receive problem

PDavi.4
Associate

Hello,

I want to receive messages from CAN bus using STM32F042, but I have a problem with it because the interrupt is not working.

I can send messages without any kind of problem, the problem is only with the receiving.

I have set up the filter as it can be seen here (at the moment I want to receive all of the messages from the CAN bus without filtering):

HAL_CAN_ConfigFilter(&hcan,&canfil); //Initialize CAN Filter
 
HAL_CAN_Start(&hcan); //Initialize CAN Bus
 
HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING);// Initialize
 
canfil.FilterBank = 0;
 
canfil.FilterMode = CAN_FILTERMODE_IDMASK;
 
canfil.FilterFIFOAssignment = CAN_RX_FIFO0;
 
canfil.FilterIdHigh = 0;
 
canfil.FilterIdLow = 0;
 
canfil.FilterMaskIdHigh = 0;
 
canfil.FilterMaskIdLow = 0;
 
canfil.FilterScale = CAN_FILTERSCALE_32BIT;
 
canfil.FilterActivation = ENABLE;
 
canfil.SlaveStartFilterBank = 14;

When the interrupt is triggered, I want to run this code:

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan1)
 
{
 
HAL_CAN_GetRxMessage(hcan1, CAN_RX_FIFO0, &rxHeader, canRX); //Receive CAN bus message to canRX buffer
 
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0);// toggle PA0 LED
 
HAL_UART_Transmit(&huart2, canRX, 8, 1000);
 
HAL_UART_Transmit(&huart2, "\n",1, 1000);
 
}

Where can I start to search for the problem? I am sure the HAL_CAN_RxFifo0MsgPendingCallback interrupt code is not running, because I checked it with the debugger. I have enabled the HDMI-CEC and CAN global interrupts / HDMI wake-up interrupt through EXTI line 27, but it not helps.

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
PDavi.4
Associate

Thank you for helping, today morning I solved the problem.

I changed on 2 thing: I changed the order of the initialization codes, and I updated the IDE from 1.5.0 to 1.6.1.

View solution in original post

2 REPLIES 2
KnarfB
Principal III

Check the return values of all HAL API functions for errors. How are messages sent? Is the CAN bus functional?

You may set loopback mode and start ending messages to yourself.

PDavi.4
Associate

Thank you for helping, today morning I solved the problem.

I changed on 2 thing: I changed the order of the initialization codes, and I updated the IDE from 1.5.0 to 1.6.1.