AnsweredAssumed Answered

[RESOLVED] STM32F107VC CAN Slave

Question asked by Yannick Dannel on Jan 22, 2018
Latest reply on Mar 29, 2018 by kadir ustun

Dear,

 

I work on CAN bus with STM32F107 MCU.

I arrived to configured CAN 1 with the help of "CAN Networking" example to send and receive CAN frame but when I try to use the CAN 2 (Slave CAN)? I only can send CAN frame. I can't receive CAN frame.

So my CAN is correctly configured because I can send CAN frame. I think the problem is with the filters (I don't completely understand how it work).

 

// CAN 2 configuration

can2HwHandle.Init.Prescaler = 18;
can2HwHandle.Init.Mode = CAN_MODE_NORMAL;
can2HwHandle.Init.SJW = CAN_SJW_1TQ;
can2HwHandle.Init.BS1 = CAN_BS1_8TQ;
can2HwHandle.Init.BS2 = CAN_BS2_7TQ;
can2HwHandle.Init.TTCM = DISABLE;
can2HwHandle.Init.ABOM = DISABLE;
can2HwHandle.Init.AWUM = DISABLE;
can2HwHandle.Init.NART = DISABLE;
can2HwHandle.Init.RFLM = DISABLE;
can2HwHandle.Init.TXFP = DISABLE;

 

// CAN 2 clock enable

__HAL_RCC_CAN2_CLK_ENABLE();

 

if ( HAL_CAN_Init(&can2HwHandle) == HAL_OK ) {
   filterConfig.FilterNumber = 0;
   filterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
   filterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
   filterConfig.FilterIdHigh = 0;
   filterConfig.FilterIdLow = 0;
   filterConfig.FilterMaskIdHigh = 0;
   filterConfig.FilterMaskIdLow = 0;
   filterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
   filterConfig.FilterActivation = ENABLE;
   filterConfig.BankNumber = 14;
      if ( HAL_CAN_ConfigFilter(&can2HwHandle, &filterConfig) == HAL_OK) {
         if ( HAL_CAN_Receive_IT(&can2HwHandle,CAN_FIFO0) == HAL_OK ) {
            // CAN 2 ITs configuration.
            HAL_NVIC_SetPriority(CAN2_TX_IRQn,0,15);
            HAL_NVIC_EnableIRQ(CAN2_TX_IRQn);
            HAL_NVIC_SetPriority(CAN2_RX0_IRQn,0,15);
            HAL_NVIC_EnableIRQ(CAN2_RX0_IRQn);

         }

      }

   }

 

 

I use the same configuration as example but it don't work.

Maybe someone can help me ?

Outcomes