AnsweredAssumed Answered

CAN Bus interrupt stopped working

Question asked by Hadi Ghani on May 24, 2018
Latest reply on May 24, 2018 by T J

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

Below is the main part of my code.

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 output when 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 wondering why 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.

Outcomes