cancel
Showing results for 
Search instead for 
Did you mean: 

Can someone help me with the function static void MX_CAN_Init(void)? When I debug my profram it get halted here!!!!

I have a STM32f042k6 Nucleo board on wich I am trying to setup the CAN Bus without success. I am using the HAL_Libraries. My programm halts at HAL_CAN_Init(&hcan); 

static void MX_CAN_Init(void)

{

 hcan.Instance = CAN;

 hcan.Init.Prescaler = 8;

 hcan.Init.Mode = CAN_MODE_NORMAL;

 hcan.Init.SJW = CAN_SJW_1TQ;

 hcan.Init.BS1 = CAN_BS1_12TQ;

 hcan.Init.BS2 = CAN_BS2_5TQ;

 hcan.Init.TTCM = DISABLE;

 hcan.Init.ABOM = DISABLE;

 hcan.Init.AWUM = DISABLE;

 hcan.Init.NART = DISABLE;

 hcan.Init.RFLM = DISABLE;

 hcan.Init.TXFP = DISABLE;

 if (HAL_CAN_Init(&hcan) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

}

8 REPLIES 8

So debug a bit harder and see if it is stuck in a loop some where or in the hard fault handler. Have a handler that outputs information and make sure SysTick or other time base is running for HAL.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

The program gets stuck here!!!!!!! Between the While and if loop.

while(HAL_IS_BIT_SET(hcan->Instance->MSR, CAN_MSR_INAK))

  {

   if((HAL_GetTick()-tickstart) > CAN_TIMEOUT_VALUE)

   {

     hcan->State= HAL_CAN_STATE_TIMEOUT;

    /* Process unlocked */

    __HAL_UNLOCK(hcan);

    return HAL_TIMEOUT;

   }

  }

Make sure the CAN clock is enabled and SysTick is advancing HAL_GetTick ​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

How do I enable clock on CAN using STMCube?

This is my solution with STMCube. @Community member​  please have a look at it and tell me what I should modify. Should in case I have to.

Sorry not chasing down CubeMX issues.

Review the HAL code

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for your hints, but up to now I dont still see the Problem.

Does HAL_GetTick() return a non-zero and increasing value? Is tickstart zero?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..