AnsweredAssumed Answered

STM32 CAN INITIALISATION PROBLEM

Question asked by MK.ShaSha on Feb 19, 2016
Latest reply on Feb 23, 2016 by kk
Hello!
I am using a stm32f302rE custom made board.

My codes keep getting stuck in the waiting for acknowledge portion in HAL_CAN_INIT:
/* Wait the acknowledge */
while((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
{
  if((HAL_GetTick()-tickstart) > INAK_TIMEOUT)
  {
     hcan->State= HAL_CAN_STATE_TIMEOUT;
     return HAL_TIMEOUT;
  }
}


I have configured my clock as follows:

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_PeriphCLKInitTypeDef PeriphClkInit;
  
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON; 
  //RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
    RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
//  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV16;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL5;
//  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL2;
  HAL_RCC_OscConfig(&RCC_OscInitStruct); 
  
 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2; 
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0); 
  
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_TIM15|RCC_PERIPHCLK_TIM16
                              |RCC_PERIPHCLK_TIM17;
  PeriphClkInit.Tim15ClockSelection = RCC_TIM15CLK_HCLK;
  PeriphClkInit.Tim16ClockSelection = RCC_TIM16CLK_HCLK;
  PeriphClkInit.Tim17ClockSelection = RCC_TIM17CLK_HCLK;
  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); 
  
  HAL_RCC_MCOConfig(RCC_MCO, RCC_MCOSOURCE_SYSCLK, RCC_MCO_DIV1);
  
  __SYSCFG_CLK_ENABLE();


I have already enabled CAN clock.
Any suggestions on how to solve this?

Outcomes