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.

Need to add more CAN Frames



Hi.,

I am using TM4C1294N CPDT Microcontroller. I am using CAN Protocol for sensing and receiving data from one PCB to Another PCB. Now i am sending one frame (ie) 8 bytes. Next development i need to send 32 bytes which means 3 frames.

Example:

void CAN1_Tx_FUNCTION(void)
{
if((g_CAN1MsgRx.ui32MsgID >= 51)&&(g_CAN1MsgRx.ui32MsgID <= 60))
{
uint8_t ui8Count=0;
uint8_t *CAN1_Tx_msgDataPtr;

CAN1_Tx_msgDataPtr = (uint8_t *)&g_ui8CAN1TxData;
for(ui8Count=0 ; ui8Count<sizeof(g_ui8CAN1TxData) ; ui8Count++)
{
g_ui8CAN1RxData[ui8Count] = 0;
}

ui8CAN1TxData[0] = Reply;
ui8CAN1TxData[2] = Status;
ui8CAN1TxData[3] =Length;

ui8CAN1TxData[4] =Yarn_Status;
ui8CAN1TxData[5] =Ready;
ui8CAN1TxData[6] = Event;
ui8CAN1TxData[7] =Fault_Length;


CAN1MsgTx.ui32MsgID = g_CAN1MsgRx.ui32MsgID;
CAN1MsgTx.ui32MsgIDMask = 0;
CAN1MsgTx.ui32Flags = MSG_OBJ_NO_FLAGS;
CAN1MsgTx.ui32MsgLen = sizeof(g_ui8CAN1TxData);
CAN1MsgTx.pui8MsgData = CAN1_Tx_msgDataPtr;
CANMessageSet(CAN1_BASE, 2, &g_CAN1MsgTx, MSG_OBJ_TYPE_TX);
}

My question is how to i add more frames,how to i set CAN ID for this protocol please guide me and i also need proper example for sending CAN frames  using CAN Protocol.

Thanks in advance

  • Hi,

      Per CAN 2.0 protocol, the payload is limited to 8 bytes maximum. You simply cannot try to send 32 bytes in one CAN frame. That is not possible. What you can do is concatenate four message objects into a FIFO buffer. Each message object will be transferred in sequence per their priority order. Your receiving CAN node will need to reassemble the four 8-byte messages. 

    Here is a helpful post about FIFO mode, although it talks about receiving not transmitting. 

    https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/886550/tm4c123gh6pm-can-using-fifo?tisearch=e2e-sitesearch&keymatch=can%2520fifo

  • HI.,

    Thanks for your reply. Can you please give any live example regarding my issue.

    Ex:already 8 bytes sent.

    ui8CAN1TxData[0] = Reply;
    ui8CAN1TxData[2] = Status;
    ui8CAN1TxData[3] =Length;

    ui8CAN1TxData[4] =Yarn_Status;
    ui8CAN1TxData[5] =Ready;
    ui8CAN1TxData[6] = Event;
    ui8CAN1TxData[7] =Fault_Length;

    I need to add 2nd 8 bytes like this

    ui8CAN1TxData[0] = retry;
    ui8CAN1TxData[2] = Spindle;
    ui8CAN1TxData[3] =led;

    ui8CAN1TxData[4] =Display unit;
    ui8CAN1TxData[5] =xxx;
    ui8CAN1TxData[6] = xxxx;
    ui8CAN1TxData[7] =xxxx;

    How could i add, because its able to send only 8 bytes at a time.

    Please resolve my issue. 

    Hope you understand what i am asking.

    Thank you

  • Hi,

    How could i add, because its able to send only 8 bytes at a time.

      Sorry, what is not clear in my last reply? I already say the CAN module can only sent 8 bytes at a time per CAN hardware and protocol. If you want to send the second 8 byte using the same message object then you will need to wait until the first 8 byte is transmitted and then send the second 8 bytes. Or you can setup multiple message objects (e.g. 4 message objects to can send 32 bytes) in an FIFO order. 

  • Thanks.,

    I got acknowledge for first 8 bytes transmission. The next step is need to send next 8 bytes. If  any example is there for sending more frames in can communication?Please share with me.

    Thank you

  • HI,

      There are CAN examples in C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals\can directory. In the simple_tx.c example, data is continuously sent out using the same message object. You can reference this example. Also you can use the CANStatusGet() to find out if the message object finishes the transmission successfully. If successful the CAN_STATUS_TXOK will set. If the message is still pending to be sent then  CAN_STS_TXREQUEST will set. Wait until the first 8 bytes is sent successfully then you can send out the next message using the same message object.