cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32F103C8X HAL_CAN_Transmit(&hcan,10) not working, always return HAL_TIMEOUT and HAL_ERROR

Dhananjay Khairnar
Associate II
Posted on March 02, 2017 at 11:56

I am programing STm32F103 for Transmitting CAN data. Initialization of can  is done by following function with 250kb bit rate

static void MX_CAN_Init(void)

{

      /*♯♯-1- Configure the CAN peripheral ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

      hcan.Instance = CAN1;

      hcan.pTxMsg = &TxMessage;

      hcan.pRxMsg = &RxMessage;

      hcan.Init.TTCM = DISABLE;

      hcan.Init.ABOM = DISABLE;

      hcan.Init.AWUM = DISABLE;

      hcan.Init.NART = DISABLE;

      hcan.Init.RFLM = DISABLE;

      hcan.Init.TXFP = DISABLE;

      hcan.Init.Mode = CAN_MODE_NORMAL;

      hcan.Init.SJW = CAN_SJW_1TQ;

      hcan.Init.BS1 = CAN_BS1_3TQ;

      hcan.Init.BS2 = CAN_BS2_4TQ;

      hcan.Init.Prescaler = 4;

      if (HAL_CAN_Init(&hcan) != HAL_OK)

      {

        /* Initiliazation Error */

        Error_Handler();

      }

      /*♯♯-2- Configure the CAN Filter ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

      sFilterConfig.FilterNumber = 0;

      sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

      sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

      sFilterConfig.FilterIdHigh = 0x0000;

      sFilterConfig.FilterIdLow = 0x0000;

      sFilterConfig.FilterMaskIdHigh = 0x0000;

      sFilterConfig.FilterMaskIdLow = 0x0000;

      sFilterConfig.FilterFIFOAssignment = 0;

      sFilterConfig.FilterActivation = ENABLE;

      sFilterConfig.BankNumber = 14;

      if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK)

      {

        /* Filter configuration Error */

        Error_Handler();

      }

      /*♯♯-3- Configure Transmission process ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

            TxMessage.StdId = 0x321;

      TxMessage.ExtId= 0x01;

      TxMessage.RTR = CAN_RTR_DATA;

      TxMessage.IDE = CAN_ID_STD;

      TxMessage.DLC = 2;

      TxMessage.Data[0] = 1;

      TxMessage.Data[1] = 2;           

      hcan.pTxMsg = &TxMessage;

}

and for transmitting data I used following function is main

while (1)

  {

     int err = HAL_CAN_Transmit(&hcan,10);

      if(err != HAL_OK)

      {

      }

      delay();

  }

err always get HAL_TIMEOUT then after some time HAL_ERROR. I receiving CAN data on Arduino but their is no data on CAN TX. I try to check signals on Oscilloscope its shows fluctuation on first time execution of HAL_CAN_Transmit(&hcan,10).

#can #can-bus #hal_can_transmit #stm32f103c8t6
1 ACCEPTED SOLUTION

Accepted Solutions
Dhananjay Khairnar
Associate II
Posted on March 21, 2017 at 08:37

My problem get solved. It actually I am providing 3.3v power supply to CAN driver which is not up to the working voltage of MCP2551. CAN library is working fine.

View solution in original post

1 REPLY 1
Dhananjay Khairnar
Associate II
Posted on March 21, 2017 at 08:37

My problem get solved. It actually I am providing 3.3v power supply to CAN driver which is not up to the working voltage of MCP2551. CAN library is working fine.