cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Bus interrupt stopped working

Hadi Ghani
Associate
Posted on May 24, 2018 at 03:42

Hello everyone, I am using STM32F072C8 with MAX3051 CAN BUS transceiver to gather CAN bus data from a vehicle.

Below is the main part ofmycode.

while (1)
{
main_counter++;
sprintf(print_buf1, '\r\n%d | main_counter: %d | interrupt_counter: %d |',data1,main_counter,interrupt_counter); 
HAL_USART_Transmit(&husart1, print_buf1, sizeof(print_buf1), HAL_MAX_DELAY);
}
void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef *hcan)
{
if (hcan->pRxMsg->StdId == 0x102)
{
interrupt_counter++;
data1 = hcan->pRxMsg->Data[3];
}
if (HAL_CAN_Receive_IT(hcan, CAN_FIFO0) != HAL_OK) 
{
Error_Handler();
}
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

The code works fine as I have tested it with several vehicles.

However, it does not work with this vehicle model that I recently tested. The CAN Bus interrupt stop working causing the data not to be updated. I have checked the vehicle's CAN Bus data structure using a CAN Bus tool and it is the same with past vehicles that I have worked with.

Below is the serial monitor output for working interrupt:

87| main_counter: 1 | interrupt_counter:6|

87

| main_counter:2| interrupt_counter: 11 |

88

| main_counter:3| interrupt_counter:16|

88

| main_counter:4| interrupt_counter:21|

89

| main_counter:5| interrupt_counter:26|

89 | main_counter: 6 | interrupt_counter: 31 |

.. and so on

Below is the serial monitor outputwhen the interrupt stop working:

87| main_counter: 1 | interrupt_counter:6|

87

| main_counter:2| interrupt_counter: 11 |

88

| main_counter:3| interrupt_counter:16|

88

| main_counter:4| interrupt_counter:16|

88

| main_counter:5| interrupt_counter:

16

|

88 | main_counter: 6 | interrupt_counter:16 |

... and so on

So I was wonderingwhy the interrupt stop working after a few moment. Could this be a firmware issue? Is there anyway to reset the interrupt in the main loop? Thank you for reading.

#can-bus #canbus
1 REPLY 1
T J
Lead
Posted on May 24, 2018 at 08:25

I only ever do this on startup.  (maybe I have an older HAL/Cube solution now.)

   

    __HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP1);

    __HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0);

       

void CEC_CAN_IRQHandler(void) {

    /* USER CODE BEGIN CEC_CAN_IRQn 0 */

    CAN_IRQFlag = true;

    checkCanRxFifos();         <     //I pull the data out here

    /* USER CODE END CEC_CAN_IRQn 0 */

    HAL_CAN_IRQHandler(&hcan);                     // HAL gets no data, so stays enabled.

    /* USER CODE BEGIN CEC_CAN_IRQn 1 */

    /* USER CODE END CEC_CAN_IRQn 1 */

}