cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 CAN Bus Transmit error

Dannis Wong
Associate
Posted on March 17, 2017 at 03:07

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);

        

  }
2 REPLIES 2
Richard Lowe
Senior III
Posted on March 21, 2017 at 11:07

Looks like you are requesting data from ID 0x

Your line:

hcan1.pTxMsg ->RTR = CAN_RTR_DATA;
�?

Says request for remote data. If the device at 0x11 doesn't respond with 2 bytes (because your DLC of 2 means that the remote must response with 2 as well) or isn't setup for response to RTR frames.... you won't get anything but silence.

Not completely sure but if you don't have anything else on the bus to awk the transmission, you'd probably timeout as well.
Posted on March 30, 2017 at 16:04

What should the value of

hcan1.pTxMsg ->RTR be then?