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?
2017-05-29 09:32 AM
When printing the cause of the Error callback with:
printf('ERR CB %d\r\n',hcan->ErrorCode);
It gives a 3 for and is HAL_CAN_ERROR_EPV | HAL_CAN_ERROR_EWG
Good idea of ST so say ''user can add his own code' but what should i do? My CAN just has to continue error or not.
Anyone???
2017-08-17 01:30 PM
It seems the CAN is not populair here. I am still having problems. On every CAN receive interrupt there is also a call to the HAL_CAN_ErrorCallback and that is because the EPV and EWG flags are high. This happens after can trouble such as disconnect cable. The documentation tells it is not needed to clear them because they are read only. And indeed clearing them does not work. Resetting my cpu (M0) is the only way to come out of this error. Calling MX_CAN_Init(); again does not help also.
2017-08-17 06:57 PM
>>
It seems the CAN is not popular here.
Responding because other haven't, but for my perspective HAL is not much liked, and as such I don't commit time/resources to it's issues.
I suspect ST expects you to count and clear the error, blink an LED or something, log an error, adapt your response based on the frequency of the error, or time since last observed. Depending on the implementation you might broadcast a message to other nodes that you were down, or resume some other protocol based transfer. I'm not sure much of this has been well thought out, or applied to some real-world application.
2017-08-18 12:14 PM
I would suggest disabling the BOFIE, EPVIE, EWGIE interrupt enable bits. This would mean that an ErrorCallback is only triggered when there was a new bus error, and would not be triggered just because the CAN controller is out of the error active state.
2017-08-18 12:24 PM
Hi, if you could give to use more information maybe we could help you better, for example: how are you making the communication? do you have two modules connected each other throughCAN bus IC as
the
SN65HVD230? Are you using Cubemx to initialize the peripheral? Are you using polling or interrupt method to make the frame Tx and Rx? how are you setting the filters? What exactly means '
My hardware has to disconnect the CAN bus sometimes', Is a physical disconnect or just disabling the peripheral? Could you share the code to check it?
Althoughthere is no to muchinformation maybe this post coulb bring to you some help:
2017-09-09 12:08 AM
Hi,
I'm using the STM32F7 series
I was having the same problem and found this post.
I fixed it just now...
the fix was, a lose connector between the Isolated CAN Transceiver PCB and the CAN pins on the main PCB
I re-enabled the BOF EWG and EPV interrupts and they have stopped firing.
2017-12-21 01:18 AM
How do you re enable the
BOF EWG and EPV
is it:
__HAL_CAN_ENABLE_IT(&hcan, CAN_IT_BOF | | CAN_IT_EWG | CAN_IT_EPV );
When you disable the BOFIE, EPVIE, EWGIE, IRQ's there will never be a new message IRQ anymore.
Right now i have a very stupid solution, if no messages a received for 10 seconds the CPU will reboot. Most of the problems when HAL_CAN_ErrorCallback comes up are solved with calling MX_CAN_Init(); in the error callback.
Best solution should be resetting all can setting in the error callback but how?
2017-12-21 05:03 PM
I found the only errors are actual CAN-BUS contention issues, where two devices are transmitting at the same time...
once all that is fixed the errors never appear again.
My addressing scheme now has unique address channels for transmitting and separately receiving frames.
I don't transmit and receive on one CAN-BUS address.
I never reinitialize the can-bus peripheral on any of the processors.
2018-01-05 10:36 AM
Basically what happens if there is a lot of CAN traffic in the:
CAN error status register (CAN_ESR) the BOFF EPVF EWGF will be set.
Bit 2 BOFF: Bus-off flag
Bit 1 EPVF: Error passive flag
Bit 0 EWGF: Error warning flag
When this happens the CAN peripheral is shut down. The only way to get out of this situation is calling MX_CAN1_Init(); again.
Simpy clearing the error flag does not help, the errors are there for some reason.