Hi Makoto,
sorry for delay. Code sent by FAE was little bit complicated for tests. Simple test code showed that there is an issue in cleaning OR flag when FIFO is enabled. The sequence in RM does not for me either.
When OR is cleaned then you have to read the flag and then read Data register. In my test code it "moved pointer" in FIFO. That was probably causing described behavior.
After correct initiation and changing sequence both ways from following code works for me fine:
- Read overloaded buffer - when longer sequence was sent, then only first part of the sequence, which fits into Rx buffer remains. Later data are ignored - no overwriting of previous data. The code prints Rx FIFO back to TX channel.(#if 1)
- Flush overloaded buffer - previous data are lost (#if 0)
RM also recommends to disable RE when flushing FIFO - it work for me with of without. Disable RE cleans OR flag immediately
Initialization
//disable transmitter and receiver during the change
UART_PORT->C2 &= ~UART_C2_RE_MASK;
UART_PORT->C2 &= ~UART_C2_TE_MASK;
//UART_PORT-> PFIFO = UART_PFIFO_RXFE_MASK | UART_PFIFO_RXFIFOSIZE(3); //enable Rx FIFO 16 bytes
UART_PORT-> PFIFO = UART_PFIFO_RXFE_MASK | UART_PFIFO_RXFIFOSIZE(2); //enable Rx FIFO 8 bytes
status = (UART_PORT-> S1) | UART_S1_OR_MASK; // clear OR
get = UART_PORT->D; //clear OR
UART_PORT-> CFIFO |= UART_CFIFO_RXFLUSH_MASK; //flush RX buffer
UART_PORT-> SFIFO |= UART_SFIFO_RXOF_MASK; //clear RXOF
// Enable receiver and transmitter
UART_PORT->C2 |= UART_C2_RE_MASK;
UART_PORT->C2 |= UART_C2_TE_MASK;
...
...
...
Overflow handling
//overflow
if ( (UART_PORT-> SFIFO) & UART_SFIFO_RXOF_MASK)
{
//UART_PORT->C2 &= ~UART_C2_RE_MASK; // recommended to disable RE
#if 1
//read the overflowed data
while (uart_getchar_present())
{
get=uart_getchar(); // will also clear the OR flag
uart_putchar(get);
time_delay_ms(2);
}
UART_PORT-> CFIFO |= UART_CFIFO_RXFLUSH_MASK; //flush RX buffer
UART_PORT-> SFIFO |= UART_SFIFO_RXOF_MASK; //clear RXOF
#else
//flush read FIFO buffer
status = (UART_PORT-> S1) & UART_S1_OR_MASK; // clear OR - read OR and read Data (disable RE clears OR also)
get = UART_PORT->D;
UART_PORT-> CFIFO |= UART_CFIFO_RXFLUSH_MASK; //flush RX buffer
UART_PORT-> SFIFO |= UART_SFIFO_RXOF_MASK; //clear RXOF
#endif
//UART_PORT->C2 |= UART_C2_RE_MASK;
}
/Jiri