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.

CCS/TM4C123GH6PM: HOW TO SEND A DATA PACKET IN A UART USING FIFO?

Part Number: TM4C123GH6PM


Tool/software: Code Composer Studio

Hi,

   I have a doubt in UART section.How to send a 13 byte of packet through the FIFO in the UART . 

#pragma pack(1)

typedef struct __Datapacket__
{
unsigned int Header;
unsigned char Maxsize;
short int X_Data;
short int Y_Data;
short int Z_Data;
short int checksum;
}Datapacket;

Suppose the above is my packet and size is 13 byte and i want to send these Datapacket through UART to the serial port of the PC.Then i will decode the Packet in PC side for the feature work.Can any one guide me how to work with these.

After studying some forum in tiva and datasheet i got if data need to Tx-it through UART by writing the data in DATA REGISTER .So studying forum and uart_polled.c present in the example i got an idea

UARTCharPut(UART0_BASE, sizeof(Datapacket)); 

I don't know wheather the above is correct or not.Can any one provide correct path to handle these in UART.

  • Hi,

      You can do something like below where you would pass sizeof(Datapacket) as the number of characters when you call UARTSend(). The below example code can also be found in the uart_echo.c example. 

    void
    UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
    {
        //
        // Loop while there are more characters to send.
        //
        while(ui32Count--)
        {
            //
            // Write the next character to the UART.
            //
            ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);
        }
    }

  • No, UARTCharPut only sends one character to the UART. You could put that function in a for loop and it might look more like this:

    void Output_Struct(Datapacket myPacket)
    {
        unsigned int i;
        char *c_ptr;
    
        c_ptr = (char *)&myPacket;
        for(i = 0; i < sizeof(Datapacket); i++)
        {
        	UARTCharPut(UART0_BASE,*c_ptr++);
        }
    }
    

  • Thanks for reply,

                   But i want to send the whole packet in a single shot,from the datasheet i found FIFO level (TX & RX) will be of 16 x 8 (16 byte).In these link also 

    http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C11_SerialInterface.htm  

    (The software can actually write 16 bytes to the UART0_DR_R, and the hardware will send them all one at a time in the proper order.) these line i got from the above book link in the below to the Interactive Tool 11.4 . If whole packet is send in the form of byte by byte whether data loss will occur.Guide me how to send a whole 13 byte packet in a single shot to the FIFO and i will decode it in my PC side.These 13 byte transmit  of packet need to send continuously to FIFO.Guide me a path to clear these UART.

    Interactive Tool 11.4

  • The code I have provide you will do just that as long as the FIFO is enabled. Each call to UARTCharPut() puts a byte in the FIFO until the FIFO is full. Writing to the FIFO happens much faster than the serial transmission of the data.
  • Thanks for reply,

                     Now it working fine and can able to send the datapacket. Thanks a lot.