2018-10-10 04:54 AM
I have a STM32f042k6 Nucleo board on wich I am trying to setup the CAN Bus without success. I am using the HAL_Libraries. My programm halts at HAL_CAN_Init(&hcan);
static 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_12TQ;
hcan.Init.BS2 = CAN_BS2_5TQ;
hcan.Init.TTCM = DISABLE;
hcan.Init.ABOM = DISABLE;
hcan.Init.AWUM = DISABLE;
hcan.Init.NART = DISABLE;
hcan.Init.RFLM = DISABLE;
hcan.Init.TXFP = DISABLE;
if (HAL_CAN_Init(&hcan) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
2018-10-10 05:16 AM
So debug a bit harder and see if it is stuck in a loop some where or in the hard fault handler. Have a handler that outputs information and make sure SysTick or other time base is running for HAL.
2018-10-10 05:21 AM
The program gets stuck here!!!!!!! Between the While and if loop.
while(HAL_IS_BIT_SET(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;
}
}
2018-10-10 05:32 AM
Make sure the CAN clock is enabled and SysTick is advancing HAL_GetTick
2018-10-10 06:23 AM
How do I enable clock on CAN using STMCube?
2018-10-10 07:03 AM
2018-10-10 08:17 AM
Sorry not chasing down CubeMX issues.
Review the HAL code
2018-10-11 06:34 AM
Thanks for your hints, but up to now I dont still see the Problem.
2018-10-11 08:33 AM
Does HAL_GetTick() return a non-zero and increasing value? Is tickstart zero?