Hardware manual

3.1 Transmitting
Transmitting is sending bytes out of the serial port away from the computer (output). Once you understand
transmitting, receiving (input) is easy to understand since it's similar. The first explanation given here will be
grossly oversimplified. Then more detail will be added in later explanations. When the computer wants to
send a byte out the serial port (to the external cable) the CPU sends the byte on the bus inside the computer to
the I/O (Input Output) address of the serial port. I/O is often written as just IO. The serial port takes the byte,
and sends it out one bit at a time (a serial bit-stream) on the transmit pin of the serial cable connector. For
what a bit (and byte) look like electrically see Voltage Waveshapes.
Here's a replay of the above in a little more detail (but still very incomplete). Most of the work at the serial
port is done by the UART chip (or the like). To transmit a byte, the serial device driver program (running on
the CPU) sends a byte to the serial port"s I/O address. This byte gets into a 1-byte "transmit shift register" in
the serial port. From this shift register bits are taken from the byte one-by-one and sent out bit-by-bit on the
serial line. Then when the last bit has been sent and the shift register needs another byte to send, it could just
ask the CPU to send it another byte. Thus would be simple but it would likely introduce delays since the CPU
might not be able to get the byte immediately. After all, the CPU is usually doing other things besides just
handling the serial port.
A way to eliminate such delays is to arrange things so that the CPU gets the byte before the shift register
needs it and stores it in a serial port buffer (in hardware). Then when the shift register has sent out its byte and
needs a new byte immediately, the serial port hardware just transfers the next byte from its own buffer to the
shift register. No need to call the CPU to fetch a new byte.
The size of this serial port buffer was originally only one byte, but today it is usually 16 bytes (more in higher
priced serial ports). Now there is still the problem of keeping this buffer sufficiently supplied with bytes so
that when the shift register needs a byte to transmit it will always find one there (unless there are no more
bytes to send). This is done by contacting the CPU using an interrupt.
First we'll explain the case of the old fashioned one-byte buffer, since 16-byte buffers work similarly (but are
more complex). When the shift register grabs the byte out of the buffer and the buffer needs another byte, it
sends an interrupt to the CPU by putting a voltage on a dedicated wire on the computer bus. Unless the CPU
is doing something very important, the interrupt forces it to stop what it was doing and start running a
program which will supply another byte to the port's buffer. The purpose of this buffer is to keep an extra byte
(waiting to be sent) queued in hardware so that there will be no gaps in the transmission of bytes out the serial
port cable.
Once the CPU gets the interrupt, it will know who sent the interrupt since there is a dedicated interrupt wire
for each serial port (unless interrupts are shared). Then the CPU will start running the serial device driver
which checks registers at I/0 addresses to find out what has happened. It finds out that the serial's transmit
buffer is empty and waiting for another byte. So if there are more bytes to send, it sends the next byte to the
serial port's I/0 address. This next byte should arrive when the previous byte is still in the transmit shift
register and is still being transmitted bit-by-bit.
In review, when a byte has been fully transmitted out the transmit wire of the serial port and the shift register
is now empty the following 3 things happen in rapid succession:
The next byte is moved from the transmit buffer into the transmit shift register1.
The transmission of this new byte (bit-by-bit) begins2.
Serial HOWTO
3.1 Transmitting 9