The UART allows us to transmit and receive data serially without having to bother about parallel-to-serial or serial-to-parallel conversions since the UART does this job for us.
Before the UART can be used, it must be told the desired BAUD rate, the number of DATA BITS, the type of PARITY and the number of STOP BITS. Once the UART has been "programmed" with this information (via OUT instructions from the microprocessor to the UART's various port registers) it can be used to send and receive serial data.
When we want to transmit a character of data, we check the UART status (using an IN instruction) to see if the Transmitter Holding Register (THR) is empty. If it is, we can output a byte of data to the UART's data port and this byte will be placed in the THR. When the UART has completed transmitting the previous character or is currently not transmitting any data (output line is logical 1), the contents of the THR are placed in the Transmitter Shift Register (TSR). The THR is then available for another output character from the computer. Only the low-order bits of the byte in the THR are used if the protocol calls for fewer than eight data bits. The UART adds the appropriate start, parity and stop bits to the character in the TSR, and then sends the entire string of bits out on the serial communications line.
The UART places any serial input it receives into the Receiver Shift Register (RSR). After the appropriate number of stop bits are received and error checking is performed, the character is placed in the Receiver Data Register (RDR). If fewer than eight bits of data are used, then only the low-order bits of the RDR are valid. The UART then updates its status to show that receiver data is ready. The computer knows that it can read another byte of data from the UART when the Receiver Data Ready status bit is set. After the data is read by the computer, the Receiver Data Ready bit is reset and remains reset until another character is placed in the RDR by the UART.
If the UART must place a second character into the RDR before the first character is read by the computer, then an Overrun Error results. This error can occur if the computer does not monitor the receiver ready status often enough. A noisy phone line can change bits in the transmission and this can trigger a Parity Error (if Parity is enabled) when this occurs the software should ask for a re-transmission of the character, it is up to the user software to test for errors and request re-transmission when they are detected If the UART does not receive a stop bit when it is expecting one, then a Framing Error results. This error can have several causes, the way the receiving UART is initialized may not match the the way the transmitting UART is initialized. The clocks of the receiver and transmitter may be off frequency just enough to cause sync loss before an entire charcter can be assembled. Transmision line noise can garble the reception of the stop bit. In any case the data is corrupted, just as if we had a parity error, so the same action should be taken. Some protocols allow for a break condition on the transmission line, to send this break condition, the line must be held in a spacing condition (logical zero) for at least as long as it takes to transmit one character with all its associated control bits.The UART will reflect the reception of a break condition by seting the appropriate bit in the status register.
The UART provides us with programmed interrupts so we do not have to keep polling the status, interrupts can be programmed to signal if a character is ready for pickup, if an error has been detected or if the THR is empty.
A UART is looped back when it's transmit output is connected to it's receive input, this is done for testing purposes. There are two types of loopback, internal and external, in internal loopback the transmit and receive are connected to each other inside the UART (so only the UART chip can be tested by this method) this is done by setting a bit in the control register (ie. by software). In external loopback, a loopback plug (a plug wired to connect the transmit pin to the receive pin) is plugged onto the serial port and this tests the circuits between the UART and the port as well.