Serial Flush() ?

29 Aug 2010

Is there a method to flush the serial port and clear all of the data from the buffer?

Replies

31 Aug 2010

No, but good idea. I'll look to add that.

01 Sep 2010 . Edited: 01 Sep 2010

Well, I'm not sure about this, but could it be something like:

LPC_UART0->FCR = 0x06;

The reason of the 0x06 is because the FIFO register clears the FIFO on two single 1's. e.g. 0b00000110 :-)

 


/ Lerche

01 Sep 2010 . Edited: 01 Sep 2010

Then again....

I really don't know what's inside of the FCR register, and I would like to know / keep it as it always are:

var = LPC_UART0->FCR;                         // Copy the FIFO control register to var           
LPC_UART0->FCR = LPC_UART0->FCR | 0x06;       // Flush the serial FIFO buffer / OR with FCR
pc.printf("%d",var);                          // Write var to PC

or you can

LPC_UART0->FCR | 0x06; 

Hope this is correct.

 

/ Lerche

01 Sep 2010

The last one should be:

LPC_UART0->FCR |= 0x06; 

01 Sep 2010

Ahh, bitwise or.... :-)
Thx

/ Lerche

07 Mar 2012

A simple (and crude) method that works for me:

void flushSerialBuffer(void) { char char1 = 0; while (device.readable()) { char1 = device.getc(); } return; }

03 May 2012

how can I know what pins are UART0 register? thx

25 Jun 2012

user David Russ wrote:

A simple (and crude) method that works for me:

void flushSerialBuffer(void) { char char1 = 0; while (device.readable()) { char1 = device.getc(); } return; }

Thanks for this.

27 Oct 2012

user David Russ wrote:

A simple (and crude) method that works for me:

void flushSerialBuffer(void) { char char1 = 0; while (device.readable()) { char1 = device.getc(); } return; }

Thank you, this is absolutely necessary everywhere in serial communication!

Please log in to post a reply.