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: TM4C1294 UARTCharsAvail can't check 1byte

I try to read only 1 byte from UART with the Interrupt, however, somehow while(UARTCharsAvail(UART0_BASE)) do not return true if the I'm not send 4 bytes. Is while(UARTCharsAvail(UART0_BASE)) only return true if the Receive FIFO have 32-bits data in it?
I try to send only 1 byte from PC to the UART. But somehow I can't read that byte unless I send 4 times. Is there any way I can just read 1 byte before I can do anything else?

Best regards,

void UARTIntHander(void){

    uint32_t ui32Status;
    uint8_t data = 0;
    //
    // Get the interrrupt status.
    //
    ui32Status = UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    UARTIntClear(UART0_BASE, ui32Status); // clear the asserted interrupts

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(UARTCharsAvail(UART0_BASE)) // loop while there are chars // return if 32 bit is full.
    {
        data = UARTCharGetNonBlocking(UART0_BASE);
        UARTCharPutNonBlocking(UART0_BASE, data); //echo character
    }

}




void
InitConsole(void)
{
    IntMasterEnable();


    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);

    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    UARTStdioConfig(0, 115200, ui32SysClockFreq);

    // For interrupt

    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX); // trigger only in RX

    //UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    UARTFIFODisable(UART0_BASE); // Clear FIFO
    UARTFIFOEnable(UART0_BASE);

}

  • To get an interrupt after one byte, you should use the code in line 52, not the code in line 50. For efficiency the receive interrupt is only set when the FIFO level is met. If you enable both the receive interrupt (UART_INT_RX) and the receive timeout (UART_INT_RT), you will get an interrupt after only one byte is received if there is not another byte coming immediately after it.