cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 CAN INITIALISATION PROBLEM

akshayamk
Associate II
Posted on February 19, 2016 at 10:45

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? #looking-in-the-wrong-place #selective-cut-n-paste
3 REPLIES 3
Posted on February 19, 2016 at 12:54

Any suggestions on how to solve this?

Zoom out a couple of levels. Are ANY of the registers in the CAN peripheral non-zero?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
akshayamk
Associate II
Posted on February 23, 2016 at 04:54

Hi Clive,

I have checked the MSR register.

I noticed the last for bits in the register are 1001.

According to the register bit assignment, these bits correspond to:

1 - wake up interrupt

0 - error interrupt

0 - Sleep acknowledge

1 - initialisation acknowledge

Any suggestions how to solve this??

pkumar1883
Associate II
Posted on February 23, 2016 at 12:56

Dear ms.shasha,

How did you debug your clock configuration. Check if it is configured accurately what you need.Only after that you should debug your CAN.