Content originally posted in LPCWare by ajg112 on Thu Aug 04 04:38:53 MST 2011
Hi All,
I'm looking for an approach for reliably detecting an escape sequence received by a LPC1768 UART. Basically, I need to determine if a key press code sent to the micro is a basic key press (1 byte), or an extended key (3 to 4 bytes).
Escape sequences start with 0x1B and then have 2 or three bytes immediately following. The critical part is looking for a gap between one byte's stop bit and the next byte's start bit. When typing VERY quickly (or hitting two keys together by mistake) it is possible for the gap to be very small (less than one character width). Escape sequences have no gap.
If I could ensure that no interrupts would be serviced whilst receiving data the problem would be trivial. One approach (that is prone to delays caused by ISRs) is on detection of a byte, wait for just over 1 character length in time and then check if another byte is waiting in the RX FIFO. If there is, then I assume these are part of a sequence. However, if an ISR causes a delay the timing is invalidated.
I also looked at setting the RX FIFO trigger level to 4 characters and using the Character Timeout Indicator, but the timeout is too long. This approach can not determine a sequence from very closely spaced characters.
Any ideas?
Thanks
Andy