2015-09-04 06:00 AM
Hello,
I'm having problems initializing the CAN peripheral, using generated code by Cube.APB1 Peripheral clock is 32MHz (XTAL16*PLL4*0.5PRESC).The device cannot get INAK cleared after clearing INRQ.Pins seem to be correctly set up on the alternate function (Mode = AF_PP and Alternate = AF9_CAN).Any help would be great!Here are some code snippets.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_8TQ; hcan.Init.BS2 = CAN_BS2_7TQ; 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);}void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan){ GPIO_InitTypeDef GPIO_InitStruct; if(hcan->Instance==CAN) { /* USER CODE BEGIN CAN_MspInit 0 */ /* USER CODE END CAN_MspInit 0 */ /* Peripheral clock enable */ __CAN_CLK_ENABLE(); /**CAN GPIO Configuration PB8 ------> CAN_RX PB9 ------> CAN_TX */ GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF9_CAN; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* USER CODE BEGIN CAN_MspInit 1 */ /* USER CODE END CAN_MspInit 1 */ }}/* Request leave initialisation */
hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_INRQ; /* Get timeout */ tickstart = HAL_GetTick(); /* 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; } } #stm32f3-can-cubemx2015-09-07 10:12 PM
The problem was solved kind of its own when I connected the power pin on the external CAN transceiver.
It seems that the CAN peripheral refuses to leave initialization if the associated pin logic state does not match normal operation values, i.e. the CAN transceiver has to be powered on.2017-05-03 11:23 PM
Hi All,
i am using STM32F303RE my code also stuck at this function :-
while((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
{ if((HAL_GetTick()-tickstart) > CAN_TIMEOUT_VALUE) { hcan->State= HAL_CAN_STATE_TIMEOUT; /* Process unlocked */ __HAL_UNLOCK(hcan); return HAL_TIMEOUT; } }i am using default code with certain pin changes (PIN are correct i crosscheck )
Please help, i will have to deliver this with in 2 day.
Thanks
Ankit Rathore