cancel
Showing results for 
Search instead for 
Did you mean: 

CAN is getting stuck in initilaztion

SS.Sagar
Associate III
Posted on September 27, 2016 at 03:34

Hi,

I m using STM32F303XC processor.

I configured the CAN at 250 kbps baud rate. but it is getting stuck in following while loop. CAN is not able initialize properly.

What would be the problem to getting stuck in initialisation.

[CODE]

  /* Request initialisation */

  SET_BIT(hcan->Instance->MCR, CAN_MCR_INRQ);

  /* Get timeout */

  tickstart = HAL_GetTick();   

  

  /* Wait the acknowledge */

  while(HAL_IS_BIT_CLR(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;

    }

  }

[/CODE]

here is my CAN configuration.

[CODE]

hcan.Instance = CAN1;

hcan.Init.Prescaler = 16; //250 kbps baud rate.

hcan.Init.Mode = CAN_MODE_LOOPBACK;

hcan.Init.SJW = CAN_SJW_1TQ;

hcan.Init.BS1 = CAN_BS1_5TQ;

hcan.Init.BS2 = CAN_BS2_2TQ;

hcan.Init.TTCM = DISABLE;

hcan.Init.ABOM = DISABLE;

hcan.Init.AWUM = DISABLE;

hcan.Init.NART = DISABLE;

hcan.Init.RFLM = DISABLE;

hcan.Init.TXFP = DISABLE;

[/CODE]

4 REPLIES 4
Uwe Bonnes
Principal III
Posted on September 27, 2016 at 09:18

Is a terminated bus and some other working device connected? If no ''ACK'' is asserted by some other device, initialalization will no succeed.

dimf_91
Associate II
Posted on September 27, 2016 at 09:36

Have you initialized a CAN-Filter?

SS.Sagar
Associate III
Posted on September 27, 2016 at 20:22

__CAN_CLK_ENABLE();
hcan.pTxMsg = &txmsg;
hcan.pRxMsg = &rxmsg;
hcan.Instance = CAN;
hcan.Init.Prescaler = 16; //250 kbps baud rate.
hcan.Init.Mode = CAN_MODE_LOOPBACK;
hcan.Init.SJW = CAN_SJW_1TQ;
hcan.Init.BS1 = CAN_BS1_5TQ;
hcan.Init.BS2 = CAN_BS2_2TQ;
hcan.Init.TTCM = DISABLE;
hcan.Init.ABOM = DISABLE;
hcan.Init.AWUM = DISABLE;
hcan.Init.NART = DISABLE;
hcan.Init.RFLM = DISABLE;
hcan.Init.TXFP = DISABLE;
HAL_CAN_Init(&hcan);
CAN_FilterStruct.FilterIdHigh = (0x0123)<<5; /* Upper 16bit filter ID */
CAN_FilterStruct.FilterIdLow = 0x0000; /* Filter lower 16bit ID */
CAN_FilterStruct.FilterMaskIdHigh = 0xFFE0; /* Upper 16bit filter mask */
CAN_FilterStruct.FilterMaskIdLow = 0x0000; /* Lower 16bit filter mask */
CAN_FilterStruct.FilterFIFOAssignment = CAN_FILTER_FIFO0; /* Which FIFO will be assigned to filter */ ///Need to check whether FIFOx is assigned to respective RXx.
CAN_FilterStruct.FilterNumber = 0;
CAN_FilterStruct.FilterMode = CAN_FILTERMODE_IDLIST; /* Identifier mask mode CAN_FILTERMODE_IDLIST/CAN_FILTERMODE_IDMASK */
CAN_FilterStruct.FilterScale = CAN_FILTERSCALE_32BIT; /* 32bit ID filter */
CAN_FilterStruct.FilterActivation = ENABLE; /* Enable this filter */
CAN_FilterStruct.BankNumber = 14; /* Start slave bank filter (?) */
HAL_CAN_ConfigFilter(&hcan, &CAN_FilterStruct); /* Initialize filter */
__HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0); /* Enable 'message pending in FIFO0' interrupt */

SS.Sagar
Associate III
Posted on September 27, 2016 at 20:28

I m using apb1 and apb2 at 36mhz and system at 72mhz

currently configured for LOOPBACK mode.

Any kind of suggestion will be helpful to go ahead.