AnsweredAssumed Answered

STM32F407 CAN Bus Transmit error

Question asked by Dannis Wong on Mar 17, 2017
Latest reply on Mar 30, 2017 by Rui Loureiro

Hello, I m a new guy in ST MCU

 

I use CubeMX as start point and create a project for CAN1 and CAN2 Communication, and test a simple code below

 

result is "HAL_CAN_Transmit(&hcan1, 50); " always return Time out error;

 

can any one have idea about it?

 

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

 

  /* Configure the system clock */
  SystemClock_Config();

 

  /* Initialize all configured peripherals */
  MX_CAN1_Init();
  MX_CAN2_Init();

 

        hcan1.pTxMsg = &TxM;
        hcan1.pRxMsg = &RxM;
    
        sFilterConfig.FilterNumber = 0;
        sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
        sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
        sFilterConfig.FilterIdHigh = 0x0;
        sFilterConfig.FilterIdLow = 0;
        sFilterConfig.FilterMaskIdHigh = 0;
        sFilterConfig.FilterMaskIdLow = 0;
        sFilterConfig.FilterFIFOAssignment = 0;
        sFilterConfig.FilterActivation = ENABLE;
        sFilterConfig.BankNumber = 14;
    
    
        HAL_CAN_ConfigFilter (&hcan1, &sFilterConfig);
        hcan1.pTxMsg ->StdId = 0x11;
        hcan1.pTxMsg ->RTR = CAN_RTR_DATA;
        hcan1.pTxMsg ->IDE = CAN_ID_STD;
        hcan1.pTxMsg ->DLC = 2;
    
 
    
    HAL_CAN_Receive_IT (&hcan1, CAN_FIFO0 );

 

  while (1)
  {
        HAL_Delay (1000);
        hcan1.pTxMsg ->Data [0] = 0x5a;
        hcan1.pTxMsg ->Data [1] = 0x6d;
       


        HAL_CAN_Transmit(&hcan1, 50);
        
  }

Outcomes