cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F469I-DISCO CAN2 not working

zenobik
Associate II

I'm trying to use CAN2 on STM32F469I-DISCO board. I connected SN65HVD232 to CN12 connector 9 (PB5 RX) and 10 (PB13 TX). On pin 9 i can see with Saleae proper CAN data frame with baud 125000. But uC doesn't receive any frame and not generating IT.

I tried to change PB5 to EXTI mode with falling edge detection - when i send the frame, IT is generated, so electrically everything is ok.

I generated code with CubeMX.

CAN2 initialization:

  GPIO_InitTypeDef GPIO_InitStruct;
    /* Peripheral clock enable */
    __HAL_RCC_CAN2_CLK_ENABLE();
    __HAL_RCC_CAN1_CLK_ENABLE();
  
    /**CAN2 GPIO Configuration    
    PB5     ------> CAN2_RX
    PB13     ------> CAN2_TX 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_13;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF9_CAN2;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
    /* CAN2 interrupt Init */
    HAL_NVIC_SetPriority(CAN2_RX0_IRQn, 5, 0);
    HAL_NVIC_EnableIRQ(CAN2_RX0_IRQn);
 
//input clock 45MHz / (20*18)=125000
  hcan2.Instance = CAN2;
  hcan2.Init.Prescaler = 20;
  hcan2.Init.Mode = CAN_MODE_NORMAL;
  hcan2.Init.SyncJumpWidth = CAN_SJW_1TQ;
  hcan2.Init.TimeSeg1 = CAN_BS1_15TQ;
  hcan2.Init.TimeSeg2 = CAN_BS2_2TQ;
  hcan2.Init.TimeTriggeredMode = DISABLE;
  hcan2.Init.AutoBusOff = DISABLE;
  hcan2.Init.AutoWakeUp = DISABLE;
  hcan2.Init.AutoRetransmission = DISABLE;
  hcan2.Init.ReceiveFifoLocked = DISABLE;
  hcan2.Init.TransmitFifoPriority = DISABLE;
  if (HAL_CAN_Init(&hcan2) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
//config filters - accept every frame
CAN_FilterTypeDef  sFilterConfig;
	sFilterConfig.FilterBank = 14;
	sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
	sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
	sFilterConfig.FilterIdHigh = 0x0000;
	sFilterConfig.FilterIdLow = 0x0000;
	sFilterConfig.FilterMaskIdHigh = 0x0000;
	sFilterConfig.FilterMaskIdLow = 0x0000;
	sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
	sFilterConfig.FilterActivation = ENABLE;
	sFilterConfig.SlaveStartFilterBank = 14;
	HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig);
 
HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO0_MSG_PENDING);

What can i try to get this things working?

2 REPLIES 2
Ant2
Associate

Maybe try using CAN1, there is a master / slave arrangement between CAN1 and CAN2 which personally I couldn't figure out.

I couldn't get CAN2 to work on my F413-Nucleo, but CAN1 and CAN3 worked fine.

Ant

zenobik
Associate II

Great idea - on other board I have no problems with CAN1, but I can't do this.

On this DISCO board CAN1 pins are used for SDRAM :(