Skip to main content
mcdino.5338840562911753E12
Associate III
October 10, 2018
Question

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

  • October 10, 2018
  • 8 replies
  • 1608 views

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__);

 }

}

    This topic has been closed for replies.

    8 replies

    Tesla DeLorean
    Guru
    October 10, 2018

    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    mcdino.5338840562911753E12
    Associate III
    October 10, 2018

    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;

       }

      }

    Tesla DeLorean
    Guru
    October 10, 2018

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

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    mcdino.5338840562911753E12
    Associate III
    October 10, 2018

    How do I enable clock on CAN using STMCube?

    mcdino.5338840562911753E12
    Associate III
    October 10, 2018

    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.

    Tesla DeLorean
    Guru
    October 10, 2018

    Sorry not chasing down CubeMX issues.

    Review the HAL code

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    mcdino.5338840562911753E12
    Associate III
    October 11, 2018

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

    Tesla DeLorean
    Guru
    October 11, 2018

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

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