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.

TMS320F280049C: C2000 microcontrollers forum: CAN Communication, Remote Request Tx and Rx

Part Number: TMS320F280049C
Other Parts Discussed in Thread: C2000WARE

Hi,

For the remote request, I am stuck on Rx setting. I changed the code from the CAN_ex8_Remote_TX. I am coding for an Rx by starting to send a remote request command first and keep receiving the data frame.

When I set CANA with ObjID = 1 to be TYPE_RX, I got an ASSERT error (not a dead error) in canSendMsg() command. I checked the error and it was caused by ASSERT(msgCtrl & CAN_IF1MCTL_DLC_M == msgLen) in the can.c file, the provided DLC size with the actual DLC size does not match. Error disappears when CANA is set to TYPE_TX. However, In this case, it is necessary to use TYPE_RX, is that right? Do I just need to ignore this issue?

If I ignore the error and keep running. The program is stuck in the while loop to check the completion of the transmission. I tried to change the TYPE_RX to TYPE_TX. However, it is still stuck in the while loop, as shown in the figure and that is what I do not understand. CAN_ES_TXOK should change to 1 when a message is sent. Even when I try to send a data frame, as I change the type to TX, it still does not change. Does that mean I have a hardware issue? For the hardware checking, I run the can_ex7_loopback_tx_rx_remote_frame and it works.

//
// Included Files
//
#include "driverlib.h"
#include "device.h"

//
// Defines
//
#define TXCOUNT            1
#define MSG_DATA_LENGTH    8
#define TX_MSG_OBJ_ID      1

//
// Globals
//
volatile unsigned long i;
volatile uint32_t txMsgCount = 0;

//
// Buffer to store the message Received by node A
//
uint16_t rxMsgData[8];

//
// Main
//
void main(void)
{
    //
    // Initialize device clock and peripherals
    //
    Device_init();

    //
    // Initialize GPIO and configure GPIO pins for CANTX/CANRX
    // on modules A
    //
    Device_initGPIO();
    GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
    GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);

    //
    // Initialize the CAN controllers
    //
    CAN_initModule(CANA_BASE);

    //
    // Set up the CAN bus bit rate to 500kHz for each module
    // Refer to the Driver Library User Guide for information on how to set
    // tighter timing control. Additionally, consult the device data sheet
    // for more information about the CAN module clocking.
    //
    CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);

    //
    // Initialize the mailbox used for sending the remote frame
    // - and receiving the corresponding data frame
    // Message Object Parameters:
    //      CAN Module: A
    //      Message Object ID Number: 1
    //      Message Identifier: 0x111
    //      Message Frame: Standard
    //      Message Type: Receive (but transmits a Remote frame first)
    //      Message ID Mask: 0x0
    //      Message Object Flags: None
    //      Message Data Length: 8 Bytes
    //
    CAN_setupMessageObject(CANA_BASE, TX_MSG_OBJ_ID, 0x111,
                           CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_RX, 0,
                           CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);


    //
    // Initialize the receive buffer to a known value
    //
    rxMsgData[0] = 0;
    rxMsgData[1] = 0;
    rxMsgData[2] = 0;
    rxMsgData[3] = 0;
    rxMsgData[4] = 0;
    rxMsgData[5] = 0;
    rxMsgData[6] = 0;
    rxMsgData[7] = 0;

    //
    // Start CAN module operations
    //
    CAN_startModule(CANA_BASE);


    //
    // Transmit Remote frame(s) from CAN-A and await data frame(s) from node B
    //
    while(1)  // Uncomment for infinite transmissions
    //for(i = 0; i < TXCOUNT; i++)
    {
        //
        // Initiate transmission of remote frame. "rxMsgData" is "dummy"
        // No data will go out on a Remote Frame
        //
        CAN_sendMessage(CANA_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH, rxMsgData);

        //
        // Poll TxOk bit in CAN_ES register to check completion of transmission
        //
        while(((HWREG_BP(CANA_BASE + CAN_O_ES) & CAN_ES_TXOK)) !=
                CAN_ES_TXOK){}

        txMsgCount++; // Increment TX counter

        //
        // Poll RxOk bit in CAN_ES register to check completion of reception
        //
        while(((HWREG_BP(CANA_BASE + CAN_O_ES) & CAN_ES_RXOK)) !=
                CAN_ES_RXOK){}

        CAN_readMessage(CANA_BASE, 1, rxMsgData);
    }
}

//
// End of File
//

  • For the remote request, I am stuck on Rx setting. I changed the code from the CAN_ex8_Remote_TX. I am coding for an Rx by starting to send a remote request command first and keep receiving the data frame

    Sorry, I don't understand what you are trying to say here.

    Initiating a Transmit request from a Receive Message object (mailbox) would cause the message object to transmit a remote frame. The data frame in response to that remote frame can be received in the same message object. This is what CAN_ex8_Remote_TX illustrates. The object that transmits the remote frame should indeed be configured as a Rx object.

    Note that, for a regular receive message object, DLC value is a "don't care". The DLC field will be overwritten by the DLC field of the received frame.

    To rule out any H/W issue, try a simple external transmit program and make sure your external node is able to receive data from the 280049. 

    It is important you use the most recent version of C2000ware.