status flag is set and the new data is lost. Because the UART receiver is double-buffered,
the program has one full character time after UART_S1[RDRF] is set before the data in
the receive data buffer must be read to avoid a receiver overrun.
When a program detects that the receive data register is full (UART_S1[RDRF] = 1), it
gets the data from the receive data register by reading UART_D. Refer to Interrupts and
status flags for details about flag clearing.
39.3.3.1 Data sampling technique
The UART receiver supports an oversampling rate of between 4× and 32× of the baud
rate clock for sampling. The receiver starts by taking logic level samples at the
oversampling rate times the baud rate to search for a falling edge on the UART_RX serial
data input pin. A falling edge is defined as a logic 0 sample after three consecutive logic
1 samples. The oversampling baud rate clock divides the bit time into 4 to 32 segments
from 1 to OSR (where OSR is the configured oversampling ratio). When a falling edge is
located, three more samples are taken at (OSR/2), (OSR/2)+1, and (OSR/2)+2 to make
sure this was a real start bit and not merely noise. If at least two of these three samples
are 0, the receiver assumes it is synchronized to a receive character. If another falling
edge is detected before the receiver is considered synchronized, the receiver restarts the
sampling from the first segment.
The receiver then samples each bit time, including the start and stop bits, at (OSR/2),
(OSR/2)+1, and (OSR/2)+2 to determine the logic level for that bit. The logic level is
interpreted to be that of the majority of the samples taken during the bit time. If any
sample in any bit time, including the start and stop bits, in a character frame fails to agree
with the logic level for that bit, the noise flag (UART_S1[NF]) is set when the received
character is transferred to the receive data buffer.
When the UART receiver is configured to sample on both edges of the baud rate clock,
the number of segments in each received bit is effectively doubled (from 1 to OSR*2).
The start and data bits are then sampled at OSR, OSR+1 and OSR+2. Sampling on both
edges of the clock must be enabled for oversampling rates of 4× to 7× and is optional for
higher oversampling rates.
The falling edge detection logic continuously looks for falling edges. If an edge is
detected, the sample clock is resynchronized to bit times (unless resynchronization has
been disabled). This improves the reliability of the receiver in the presence of noise or
mismatched baud rates. It does not improve worst case analysis because some characters
do not have any extra falling edges anywhere in the character frame.
Chapter 39 Universal Asynchronous Receiver/Transmitter (UART0)
KL25 Sub-Family Reference Manual, Rev. 3, September 2012
Freescale Semiconductor, Inc. 741