Reading UART Tx FIFO level

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by graynomad on Sun Dec 09 17:26:33 MST 2012
I'm writing a driver for a UART (on the 1227), so far it's working well but if I send too many bytes the FIFO fills and I lose characters. No problem I just write a buffer function that creates a software FIFO for the overflow.

So to implement that I need to test the hardware FIFO level, if it's full write to the software buffer, if not write directly to the hardware. But no matter what I do I get a value of 0 for LPC_UART0->FIFOLVL.

Here's the test code I'm currently using.

void serialWrite (uint8 b) {
    uint8 x = (LPC_UART0->FIFOLVL >> 8) & 0x0F;
    if (x < 15) {
        LPC_UART0->THR = 0x11;
        LPC_UART0->THR = 0x22;
        LPC_UART0->THR = 0x33;
        LPC_UART0->THR = LPC_UART0->FIFOLVL >> 8;  // !!!!!!!!!!!!!! this is always 0
        LPC_UART0->THR = 0x44;
    } else {
        fifoWrite (s->TxBuffer, b);

(what's with no CODE tags on this forum?)

Because I think stopping the processor to use the debugger will allow the FIFO to empty and give me a bogus reading of FIFOLVL for testing I write three bytes into the FIFO then write the TXFIFOLVL bits from the register and finally another byte just to frame the level data.

I always get 0 for the LPC_UART0->FIFOLVL >> 8 byte when presumably it should be 4.

This should be simple right? Am I missing a secret handshake or something?