2017-04-25 11:27 AM
My hardware has to disconnect the CAN bus sometimes. When i do the callback HAL_CAN_ErrorCallback will pop up. My CAN bus has to continue work so i clear all flags that i found:
__HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_EWG);
__HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_EPV); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_BOF);__HAL_CAN_CLEAR_FLAG(hcan,CAN_TSR_RQCP0);
__HAL_CAN_CLEAR_FLAG(hcan,CAN_TSR_RQCP1); __HAL_CAN_CLEAR_FLAG(hcan,CAN_TSR_RQCP2); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_TXOK0); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_TXOK1); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_TXOK2); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_TME0); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_TME1); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_TME2); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_FF0); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_FOV0); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_FF1); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_FOV1); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_WKU); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_SLAKI); __HAL_CAN_CLEAR_FLAG(hcan,CAN_FLAG_BOF);The CAN bus does work after that however every receive message the ErrorCallback comes back, what do i need to clear?
2018-01-05 03:08 PM
I don't get any errors any more. I never reinitialise any part of the network.
it sounds like the network your attaching to, is contentious, is it a preexisting network ? or still on the bench ?
did you look at the canbus wires, on a scope ?
is it possible that your clock source is drifting ?
2 boards, both with a drifting clocks ?
if the canbus frequency between boards, drifts by 5%, you would likely see these errors.
did you check the frequency on a scope ?
2018-01-06 01:48 AM
It is an existing (6 year) network with 12 microchip 18F modules on it. Length 30 meter 125kb. 120E on both sides. And a third party CAN-USB translator for debugging. The CAN on the microchip was working within a few minutes. It does not have so may error conditions so never stops receiving or reaches the state off bus.
So my STM32 CAN works prefect for hours or sometimes days. Then a problem happens. A CAN cable hardware disconnect or whatever.
I need to recover from the
CAN_ESR error state. The reference manual or HAL manual does not tell how.
2018-01-06 02:01 PM
I am not sure I can help you,
I had to power cycle many times before I fixed my issues,
Now, I don't see any errors anymore.
the trick was to make sure that every messageID was unique in the network.
my nodes all have a separate 16 'ID's' some channels are TX and some are Rx. much like endpoints
no two nodes can transmit the same ID.
Did you set the ABOM bit ?
(the automatic Bus Off repair mechanism )
2018-01-06 02:49 PM
I checked my '767 code, I dont enable most interrupts.. maybe that's why I don't see any issues ??
void initCairoCan (void) {
CAN_Config(); canRxpointerIN = 0; canRxMsgIN =0; canRxMsgOUT =0; canRxMsgTableEMPTY = true; canRxMsgTableFULL = false;for(int i = 0; i<16;i++)
IOCanMsgFlag[i] =false;// // Receive Interrupts ////// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_FF0); //!< FIFO 0 full interrupt ////// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_FOV0); //!< FIFO 0 overrun interrupt ////// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_FF1); //!< FIFO 1 full interrupt ////// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_FOV1); //!< FIFO 1 overrun interrupt ////// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_FMP0); //!< FIFO 0 message pending interrupt ////// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_FMP1); //!< FIFO 1 message pending interrupt ////// // Operating Mode Interrupts ////// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_WKU); //!< Wake-up interrupt //// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_SLK); //!< Sleep acknowledge interrupt //////// // Error Interrupts //// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_EWG); //!< Error warning interrupt //// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_EPV); //!< Error passive interrupt //// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_BOF); //!< Bus-off interrupt //// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_LEC); //!< Last error code interrupt //// __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_ERR); //!< Error Interrupt //// /* Enable Transmit mailbox empty Interrupt */ __HAL_CAN_ENABLE_IT (&hcan1, CAN_IT_TME); //!< Transmit mailbox empty interrupt // __HAL_CAN_ENABLE_IT (&hcan1, CAN_IT_FMP0); //!< FIFO 0 message pending interrupt // __HAL_CAN_ENABLE_IT (&hcan1, CAN_IT_FMP1); //!< FIFO 1 message pending interrupt //canTxMsgIN =0;
canTxMsgOUT =0; canTxMsgTableEMPTY = true; canTxMsgTableFULL = false; canTxMsgTableOverflow = false; canTxMsgOverrun = false; blockCanTx = false;}