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/TM4C1294NCPDT: UART prints continuously even if UARTCharsAvail() is false.

Part Number: TM4C1294NCPDT

Tool/software: Code Composer Studio

Hi Guys,

Please help me out. I am working on a code where I check if there is any data in the UART receive buffer and print an output on the  on the TX if true. 

Here is the following piece of code:

while(1)
{

    if (UARTCharsAvail(UART7_BASE))
      {
       UARTprintf("Received Data \n");
      }
}



The issue I am facing with the above code is that once I am sending a character on the RX, "Data Received" is continuously being printed on the TX. It seems to me that the if statement is true even if there isn't any character being sent to the RX.

It would be really helpful if anyone could point me in the right direction. TIA

Regards

  • In the code above, you never read the character from the receive FIFO so it continues to have characters available. The function UARTCharsAvail() does not empty the receive FIFO, it merely reports the status.
  • Hello Bob,

    Thank you for your suggestion. That seems to work. But I would like to know if there is a way to clear the FIFO buffer with an inbuilt library API instead of reading the data every time.  

    Regards

  • Prabhav,

    There is no function to clear the UART fifo. If you'd like one, it is simply

    while(UARTCharsAvail(BASE){UARTCharGet(BASE);}

    But if you don't need the data, just ignore it - disable the interrupt, for example - not that it makes too much sense to connect a serial port input and then not want to hear it...

    By the way, do you have your TivaWare user guide open on your PC while you develop? Chapter 30.2 shows all the UART functions available.

    Regards

    Bruno

  • And as poster Bruno suggests - the "luxury of a 2nd monitor" (to constantly display the DRL User Guide) saves great time & effort...

    Where resources preclude - nothing prevents users from "Printing" the API Functions (on a "By Peripheral" basis) and keeping that printout nearby...