2025-12-01 1:12 AM - last edited on 2025-12-01 1:30 AM by mƎALLEm
Hello
I have a code use CAN on a stm32U585 he work fine if the CAN bus have not disturbance
But if i have to many disturbance for exemple if i make a short circuit bethen CANH and CANL when i remove the short circuit the CAN no restart to send data. I need stop and restart CAN
HAL_FDCAN_Stop(&hfdcan1);
HAL_FDCAN_Start(&hfdcan1);
After the disturbance, the return value of HAL_FDCAN_GetState() and HAL_FDCAN_GetError() remains unchanged.
How can I immediately know when there is a problem with CAN
Solved! Go to Solution.
2025-12-01 1:25 AM - edited 2025-12-01 1:26 AM
Hello,
@lll wrote:
if i make a short circuit bethen CANH and CANL when i remove the short circuit the CAN no restart to send data.
That's normal. The node is in Bus-off state and there is no automatic Bus-off recovery by hardware with FDCAN. You need to do it by software.
To implement the Bus-Off recovery by software you need to:
HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_BUS_OFF, 0);
void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs)
{
FDCAN_ProtocolStatusTypeDef protocol_status;
HAL_FDCAN_GetProtocolStatus(hfdcan, &protocol_status);
if (protocol_status.BusOff != 0) // If Bus-Off error occurred
{
CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT); // Clear INIT bit to recover from Bus-Off
}
}
Hope that answers your question.
2025-12-01 1:16 AM
correction: HAL_FDCAN_GetTxFifoFreeLevel is always full after error
2025-12-01 1:25 AM - edited 2025-12-01 1:26 AM
Hello,
@lll wrote:
if i make a short circuit bethen CANH and CANL when i remove the short circuit the CAN no restart to send data.
That's normal. The node is in Bus-off state and there is no automatic Bus-off recovery by hardware with FDCAN. You need to do it by software.
To implement the Bus-Off recovery by software you need to:
HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_BUS_OFF, 0);
void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs)
{
FDCAN_ProtocolStatusTypeDef protocol_status;
HAL_FDCAN_GetProtocolStatus(hfdcan, &protocol_status);
if (protocol_status.BusOff != 0) // If Bus-Off error occurred
{
CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT); // Clear INIT bit to recover from Bus-Off
}
}
Hope that answers your question.