2018-04-30 07:39 PM
Hello
I am trying to use the stm32f7xx_hal_can driver on Nucleo 144 F767ZI , and the code is stuck at the init state.
While using the debugger and reading the Reference manual i found the fallowing:
- the initial state of the CAN contoller is SLEEP state
- To exit the sleep state it is needed to clear the
SLEEP bit in the MCR register
- Then the CAN controller acknowledge to the software that he move from SLEEP state by clear SLAK bit in MSR
register
I did not connect the can transceiver yet.
here is the the code 'stm32f7xx_hal_can.c' I mark the line were the program stuck
HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef *hcan)
{ uint32_t tickstart = 0U;/* Check CAN handle */
if (hcan == NULL) { return HAL_ERROR; }/* Check the parameters */
assert_param(IS_CAN_ALL_INSTANCE(hcan->Instance)); assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TimeTriggeredMode)); assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AutoBusOff)); assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AutoWakeUp)); assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AutoRetransmission)); assert_param(IS_FUNCTIONAL_STATE(hcan->Init.ReceiveFifoLocked)); assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TransmitFifoPriority)); assert_param(IS_CAN_MODE(hcan->Init.Mode)); assert_param(IS_CAN_SJW(hcan->Init.SyncJumpWidth)); assert_param(IS_CAN_BS1(hcan->Init.TimeSeg1)); assert_param(IS_CAN_BS2(hcan->Init.TimeSeg2)); assert_param(IS_CAN_PRESCALER(hcan->Init.Prescaler));if (hcan->State == HAL_CAN_STATE_RESET)
{ /* Init the low level hardware: CLOCK, NVIC */ HAL_CAN_MspInit(hcan); }/* Exit from sleep mode */
CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP);<--- clear the SLEEP bit
/* Get tick */
tickstart = HAL_GetTick();/* Check Sleep mode leave acknowledge */
while ((hcan->Instance->MSR & CAN_MSR_SLAK) != RESET) <---------- stuck here while waiting for ack { if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) { /* Update error code */ hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT;/* Change CAN state */
hcan->State = HAL_CAN_STATE_ERROR;return HAL_ERROR;
} }....
Does anyone have an idea why ?
2018-05-01 02:51 AM
only one reason for this is the pull up.
you need a transceiver chip without a pullup or
without a transceiver chip, you need a pullup on the CanRx pin.
2018-05-01 11:25 AM
Thanks , I connected the transceiver , and now is want get stuck on that line =].