cancel
Showing results for 
Search instead for 
Did you mean: 

When I have the MX program set up CAN1 on my STM32F446 Nucleo-64 the generated code fails to initialize with the default values from MX.

KiptonM
Lead

it generates the following init using the default parameters:

static void MX_CAN1_Init(void)
{
 
  /* USER CODE BEGIN CAN1_Init 0 */
 
  /* USER CODE END CAN1_Init 0 */
 
  /* USER CODE BEGIN CAN1_Init 1 */
 
  /* USER CODE END CAN1_Init 1 */
  hcan1.Instance = CAN1;
  hcan1.Init.Prescaler = 16;
  hcan1.Init.Mode = CAN_MODE_NORMAL;
  hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
  hcan1.Init.TimeSeg1 = CAN_BS1_1TQ;
  hcan1.Init.TimeSeg2 = CAN_BS2_1TQ;
  hcan1.Init.TimeTriggeredMode = DISABLE;
  hcan1.Init.AutoBusOff = DISABLE;
  hcan1.Init.AutoWakeUp = DISABLE;
  hcan1.Init.AutoRetransmission = DISABLE;
  hcan1.Init.ReceiveFifoLocked = DISABLE;
  hcan1.Init.TransmitFifoPriority = DISABLE;
  if (HAL_CAN_Init(&hcan1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN CAN1_Init 2 */
 
  /* USER CODE END CAN1_Init 2 */
 
}

And it falls immediately into the Error_Handler();

What do I need to do to fix it?

My second question is:

My system needs to have a CAN Baud rate of 1,000,000 because the other devices are running that speed. I cannot figure out how to make that happen. I tell it 1000000 for the baud rate and then I cannot figure out the Time Quanta in Bit Segment 1 or Bit Segment 2. Does this chip not support that speed? If not what will?

Thanks,

Kip

3 REPLIES 3
Jjs.1
Associate II
KiptonM
Lead

I have not changed the system clock, I left the defaults. For my chip the clock is 84 MHz.

"Not sure howbut i fixed it:

I removed the nodes from the canbus line and flashed them with the canbus not connected,

the nodes are back to normal behaviour, maybe something hardwarewise was happening in the canbus."

I do not understand what was changed.

KiptonM
Lead

If I understand it right. the other removed everything else connected tot he CAN bus. I do not have anything one the CAN bus yet. So it does not apply to my situation.

I just enabled the CAN1 interface and compiled and it failed the initialization.

Kip