Skip to main content
Manoj Hiwarkar
Associate III
August 20, 2018
Question

CAN messege transmission using HAL LIBRARY

  • August 20, 2018
  • 2 replies
  • 634 views

Please tell me how to send a CAN message using HAL_CAN_Transmit function.

For ex. if I want send a hex number say 0xFE.

    This topic has been closed for replies.

    2 replies

    T J
    Senior III
    August 20, 2018

    i use the cube to initialise all the peripherals with HAL. including CanBus

    but it ends there,

    I use this to transmit.

    if ((CAN->TSR & CAN_TSR_TME0) == CAN_TSR_TME0) // (1) fifo0 is empty
     {
     CAN->sTxMailBox[0].TDTR = 8; // (2) length
     CAN->sTxMailBox[0].TDLR = 0x11223344; // (3) 4bytes
     CAN->sTxMailBox[0].TDHR = 0x44556677; // (3) 4bytes
     CAN->sTxMailBox[0].TIR = ((uint32_t)TxMsgID << 21 | CAN_TI0R_TXRQ); // (4)
    // sent to fifo now, if the line is idle it will start now
    }
     if ((CAN->TSR & CAN_TSR_TME1) == CAN_TSR_TME1) // (1) fifo1 is empty
    {}
     if ((CAN->TSR & CAN_TSR_TME2) == CAN_TSR_TME2) // (1) fifo2 is empty
    {}

    Tesla DeLorean
    Guru
    August 20, 2018

    Perhaps looks at some code examples for the STM32 part you're using?

    STM32Cube_FW_L4_V1.12.0\Projects\STM32L476G-EVAL\Examples\CAN\CAN_Networking\Src\main.c

           /* Set the data to be transmitted */

           TxData[0] = 0xFE;

           /* Start the Transmission process */

           if (HAL_CAN_AddTxMessage(&CanHandle, &TxHeader, TxData, &TxMailbox) != HAL_OK)

           {

             /* Transmission request Error */

             Error_Handler();

           }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..