Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28379D: CAN Communication query

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

I am working with Launchpad XL TMS320F28379D, trying to get the CAN communication up & running using Bus Master PC tool(Peak driver installed). I have written a basic code similar to CAN examples & CAN provided driver files. The code sets up Message object 1 as Tx & Message Object 2 as Rx.
Trying to Transmit a message periodic 5 seconds. In interrupt handler, check if transmit interrupt is generated & receive interrupt is generated.
Tried with below 3 options in CAN_selectClockSource(CANA_BASE, X)
X = CAN_CLOCK_SOURCE_SYS, CAN_CLOCK_SOURCE_XTAL, CAN_CLOCK_SOURCE_AUX

After this using CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);
Not seeing any CAN messages on the BusMaster tool - Channel 1 Configured for 500kbps. Can you please tell me how to debug ? Thanks.

  • CAN_Driver.c
    
    #include "can.h"
    #include "can_driver.h"
    #include "driverlib.h"
    #include "device.h"
    
    uint16_t txMsgData[8];
    uint16_t rxMsgData[8];
    
    __interrupt void canISR(void);
    
    volatile uint32_t errorFlag = 0;
    
    void Can_Init(void)
    {
    
        Device_init();    // disables watchdog also.
        Device_initGPIO();
    
        GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);
    
       CAN_selectClockSource(CANA_BASE, CAN_CLOCK_SOURCE_SYS);
    
        CAN_initModule(CANA_BASE);
        CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);
    
        CAN_enableInterrupt(CANA_BASE, CAN_INT_IE0 | CAN_INT_ERROR | CAN_INT_STATUS);
        Interrupt_initModule();
        Interrupt_initVectorTable();
        EINT;
        ERTM;
    
        Interrupt_register(INT_CANA0, &canISR);
        Interrupt_enable(INT_CANA0);
        CAN_enableGlobalInterrupt(CANA_BASE, CAN_GLOBAL_INT_CANINT0);
    
        //Configure CAN ID : 0x701 as Transmit ID associated with Msgobject 1
        CAN_setupMessageObject(CANA_BASE, CAN_MSG_OBJECT_1, CAN_TX_MSG_ID_1, CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, CAN_MSG_ID_MASK, CAN_MSG_OBJ_TX_INT_ENABLE, MSG_DATA_LENGTH_EIGHT);
    
        // Configure CAN ID : 0x717 as receive  ID associated with Msgobject 2
        CAN_setupMessageObject(CANA_BASE, CAN_MSG_OBJECT_2, CAN_RX_MSG_ID_1, CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_RX, CAN_MSG_ID_MASK, CAN_MSG_OBJ_RX_INT_ENABLE, MSG_DATA_LENGTH_EIGHT);
    
        CAN_startModule(CANA_BASE);
    
    }
    
    void CAN_MainTask(void)
    {
        //uint16_t txMsgData[8], rxMsgData[8];
    
        txMsgData[0] = 0x01;
        txMsgData[1] = 0x02;
        txMsgData[2] = 0x03;
        txMsgData[3] = 0x04;
        txMsgData[4] = 0x05;
        txMsgData[5] = 0x06;
        txMsgData[6] = 0x07;
        txMsgData[7] = 0x08;
    
        for(;;)
        {
           CAN_sendMessage(CANA_BASE, CAN_MSG_OBJECT_1, MSG_DATA_LENGTH_EIGHT, txMsgData);
    
           DEVICE_DELAY_US(5000000);   // 5 seconds
    
           txMsgData[0] += 0x01;
           txMsgData[1] += 0x01;
           txMsgData[2] += 0x01;
           txMsgData[3] += 0x01;
           txMsgData[4] += 0x01;
           txMsgData[5] += 0x01;
           txMsgData[6] += 0x01;
           txMsgData[7] += 0x01;
    
           if(txMsgData[7] > 0xFF)
           {
              txMsgData[0] = 0;
              txMsgData[1] = 0;
              txMsgData[2] = 0;
              txMsgData[3] = 0;
              txMsgData[4] = 0;
              txMsgData[5] = 0;
              txMsgData[6] = 0;
              txMsgData[7] = 0;
            }
        }
    }
    
    void Can_Transmit(void)
    {
    }
    
    void Can_Rx_Interrupt(void)
    {
    }
    
    __interrupt void
    canISR(void)
    {
       uint32_t status;
       status = CAN_getInterruptCause(CANA_BASE);
    
       if(status == CAN_INT_INT0ID_STATUS)
       {
          status = CAN_getStatus(CANA_BASE);
    
          if(((status  & ~(CAN_STATUS_TXOK | CAN_STATUS_RXOK)) != 7) &&
             ((status  & ~(CAN_STATUS_TXOK | CAN_STATUS_RXOK)) != 0))
          {
             errorFlag = 1;
          }
       }
       else if(status == CAN_MSG_OBJECT_1)   //1
       {
          CAN_clearInterruptStatus(CANA_BASE, CAN_MSG_OBJECT_1);
          errorFlag = 0;
       }
       else if(status == CAN_MSG_OBJECT_2)   //2
       {
          CAN_readMessage(CANA_BASE, CAN_MSG_OBJECT_2, rxMsgData);
          CAN_clearInterruptStatus(CANA_BASE, CAN_MSG_OBJECT_2);
          errorFlag = 0;
       }
       else
       {
       }
    
       CAN_clearGlobalInterruptStatus(CANA_BASE, CAN_GLOBAL_INT_CANINT0);
       Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
    
    }
    
    CAN_Driver.c
    
    #include "can.h"
    #include "can_driver.h"
    #include "driverlib.h"
    #include "device.h"
    
    uint16_t txMsgData[8];
    uint16_t rxMsgData[8];
    
    __interrupt void canISR(void);
    
    volatile uint32_t errorFlag = 0;
    
    void Can_Init(void)
    {
    
        Device_init();    // disables watchdog also.
        Device_initGPIO();
    
        GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);
    
       CAN_selectClockSource(CANA_BASE, CAN_CLOCK_SOURCE_SYS);
    
        CAN_initModule(CANA_BASE);
        CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);
    
        CAN_enableInterrupt(CANA_BASE, CAN_INT_IE0 | CAN_INT_ERROR | CAN_INT_STATUS);
        Interrupt_initModule();
        Interrupt_initVectorTable();
        EINT;
        ERTM;
    
        Interrupt_register(INT_CANA0, &canISR);
        Interrupt_enable(INT_CANA0);
        CAN_enableGlobalInterrupt(CANA_BASE, CAN_GLOBAL_INT_CANINT0);
    
        //Configure CAN ID : 0x701 as Transmit ID associated with Msgobject 1
        CAN_setupMessageObject(CANA_BASE, CAN_MSG_OBJECT_1, CAN_TX_MSG_ID_1, CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, CAN_MSG_ID_MASK, CAN_MSG_OBJ_TX_INT_ENABLE, MSG_DATA_LENGTH_EIGHT);
    
        // Configure CAN ID : 0x717 as receive  ID associated with Msgobject 2
        CAN_setupMessageObject(CANA_BASE, CAN_MSG_OBJECT_2, CAN_RX_MSG_ID_1, CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_RX, CAN_MSG_ID_MASK, CAN_MSG_OBJ_RX_INT_ENABLE, MSG_DATA_LENGTH_EIGHT);
    
        CAN_startModule(CANA_BASE);
    
    }
    
    void CAN_MainTask(void)
    {
        //uint16_t txMsgData[8], rxMsgData[8];
    
        txMsgData[0] = 0x01;
        txMsgData[1] = 0x02;
        txMsgData[2] = 0x03;
        txMsgData[3] = 0x04;
        txMsgData[4] = 0x05;
        txMsgData[5] = 0x06;
        txMsgData[6] = 0x07;
        txMsgData[7] = 0x08;
    
        for(;;)
        {
           CAN_sendMessage(CANA_BASE, CAN_MSG_OBJECT_1, MSG_DATA_LENGTH_EIGHT, txMsgData);
    
           DEVICE_DELAY_US(5000000);   // 5 seconds
    
           txMsgData[0] += 0x01;
           txMsgData[1] += 0x01;
           txMsgData[2] += 0x01;
           txMsgData[3] += 0x01;
           txMsgData[4] += 0x01;
           txMsgData[5] += 0x01;
           txMsgData[6] += 0x01;
           txMsgData[7] += 0x01;
    
           if(txMsgData[7] > 0xFF)
           {
              txMsgData[0] = 0;
              txMsgData[1] = 0;
              txMsgData[2] = 0;
              txMsgData[3] = 0;
              txMsgData[4] = 0;
              txMsgData[5] = 0;
              txMsgData[6] = 0;
              txMsgData[7] = 0;
            }
        }
    }
    
    void Can_Transmit(void)
    {
    }
    
    void Can_Rx_Interrupt(void)
    {
    }
    
    __interrupt void
    canISR(void)
    {
       uint32_t status;
       status = CAN_getInterruptCause(CANA_BASE);
    
       if(status == CAN_INT_INT0ID_STATUS)
       {
          status = CAN_getStatus(CANA_BASE);
    
          if(((status  & ~(CAN_STATUS_TXOK | CAN_STATUS_RXOK)) != 7) &&
             ((status  & ~(CAN_STATUS_TXOK | CAN_STATUS_RXOK)) != 0))
          {
             errorFlag = 1;
          }
       }
       else if(status == CAN_MSG_OBJECT_1)   //1
       {
          CAN_clearInterruptStatus(CANA_BASE, CAN_MSG_OBJECT_1);
          errorFlag = 0;
       }
       else if(status == CAN_MSG_OBJECT_2)   //2
       {
          CAN_readMessage(CANA_BASE, CAN_MSG_OBJECT_2, rxMsgData);
          CAN_clearInterruptStatus(CANA_BASE, CAN_MSG_OBJECT_2);
          errorFlag = 0;
       }
       else
       {
       }
    
       CAN_clearGlobalInterruptStatus(CANA_BASE, CAN_GLOBAL_INT_CANINT0);
       Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
    
    }
    

  • Hi Sunil,

    Can you check a few things:

    1. If the message RAM is being configured properly.
    2. Is the Bit Rate of the Receiving device same.
    3. Did you refer to the c2000ware example for external transmit.

    Thanks and Regards
    Harshmeet Singh
  • Thanks for the reply, Yes my code is attached to this query

    1. Configuring message RAM using CAN_setupMessageObject - (1 as Tx, 2 as RX, - please refer code ) seems correct. 

    2. used: CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);    at receiver end : Busmaster tool config I have given 500000(screenshot), is this correct ? not sure. 

    3. yes code based on examples itself. 

    Please advise, Thanks. 

  • One more thing. Which Pins are you using from the LaunchPAD? You are using the CANH and CANL pins from the Transceiver on the launchpad that will be pin 70 and 71 if i am not wrong.

    Regards
    Harshmeet
  • Thanks for the reply, I am using GPIO30 CAN-A receive, GPIO31 CAN-A transmit in code - exactly as given in can_ex3_external_transmit.c example file.
    I am suspecting problem may be - mismatch between CAN_setBitRate function & the bus master screenshot setings for the baud rate. Thanks .

    I have connected the Peak CAN wires to pins mentioned CAN-H CAN-L on board . 

  • This is for the control card. You are using the launchpad which has a can Transceiver on chip. Unless you are using an external CAN Transceiver you can ignore this otherwise you need to change the GPIO Configurations.

    Can you connect CANH and CANL to the one's on the receiver side. Which are GPIO70 and GPIO71. Please refer to the Launchpad Schematic Document for more details.
    Change the code also accordingly.


    Thanks and Regards
    Harshmeet Singh
  • I didnt get your previous reply,
    Code has below :
    GPIO_setPinConfig(GPIO_30_CANRXA);
    GPIO_setPinConfig(GPIO_31_CANTXA);
    I am not using external Transceiver. Using the Pins marked CAN-H, CAN-L on board to connect my wires to PEAK CAN\BusMaster tool.
    Is this correct ?
    Thanks, Sunil G
  • Sunil,

    Can you please make some changes and try again.

    1. In device.h
    //
    // CANA
    //
    #define DEVICE_GPIO_PIN_CANTXA 71U // GPIO number for CANTXA
    #define DEVICE_GPIO_PIN_CANRXA 70U // GPIO number for CANRXA

    //
    // CAN External Loopback
    //
    #define DEVICE_GPIO_CFG_CANRXA GPIO_70_CANRXA // "pinConfig" for CANA RX
    #define DEVICE_GPIO_CFG_CANTXA GPIO_71_CANTXA // "pinConfig" for CANA TX

    2. The Driverlib code is for control card. In device.h there is a define as _LAUNCHXL_F28379D which should be used to correctly configure clock for Launchpad.

    These two changes will enable you run the code correctly.

    An advice i have is that you try to run the internal loopback once to see if it is working properly.
    The above changes will help you run your code.

    Hope this helps.

    Thanks and Regards
    Harshmeet Singh
  • Hi Sunil,

    Did you get a chance to try this?

    Regards
    Harshmeet
  • Yes, thanks, Tx & RX of CAN messages working correctly after below code changes, as per the transceiver connection. 

    GPIO_setPinConfig(GPIO_12_CANTXB); 

    GPIO_setPinConfig(GPIO_17_CANRXB);