12. Rabbit Serial Ports
The Rabbit 3000 has 6 on-chip serial ports designated A, B, C, D, E, and F. All the ports can perform asynchronous serial communications at high baud rates. Ports A-D can operate as clocked ports. Ports A and B can be switched to alternate pins. Ports E and F support SDLC/HDLC synchronous communications in addition to standard asynchronous communications. Port A has the special capability of being used to remote boot the microprocessor via asynchronous, synchronous, or IrDA (asynchronous serial).
Table 12-1 lists the synchronous serial port signals.
Table 12-1. Serial Port Signals
Serial Port A
|
TXA
|
Serial Transmit Out
|
|
RXA
|
Serial Transmit In
|
|
CLKA
|
Clock for clocked mode (bidirectional)
|
|
ATXA
|
Alternate serial transmit out
|
|
ARXA
|
Alternate serial receive in
|
Serial Port B
|
TXB
|
Serial Transmit Out
|
|
RXB
|
Serial Transmit In
|
|
CLKB
|
Clock for clocked mode (bidirectional)
|
|
ATXB
|
Alternate serial transmit out
|
|
ARXB
|
Alternate serial receive in
|
Serial Port C
|
TXC
|
Serial Transmit Out
|
|
RXC
|
Serial Transmit In
|
|
CLKC
|
Clock for clocked mode (bidirectional)
|
Serial Port D
|
TXD
|
Serial Transmit Out
|
|
RXD
|
Serial Transmit In
|
|
CLKD
|
Clock for clocked mode (bidirectional)
|
Serial Port E
|
TXE
|
Serial Transmit Out
|
|
RXE
|
Serial Transmit In
|
|
TCLKE
|
Optional external transmit clock
|
|
RCLKE
|
Optional external receive clock
|
Serial Port F
|
TXF
|
Serial Transmit Out
|
|
RXF
|
Serial Transmit In
|
|
TCLKF
|
Optional external transmit clock
|
|
RCLKF
|
Optional external receive clock
|
Figure 12-1 shows a block diagram of the serial ports.

Figure 12-1. Block Diagram of Rabbit Serial Ports
The individual serial ports are capable of operating at baud rates in excess of 500,000 bps in the asynchronous mode, and 8 times faster than that in the synchronous mode. Either 7 or 8 data bits may be transmitted and received in the asynchronous mode. The so-called "9th" bit or address bit mode of operation is also supported. The "9th" bit can be set high or low by accessing the appropriate serial port register. Although Parity and multiple stop bits are not directly supported by the hardware, the "9th" bit can be used to issue an extra stop bit (9th-bit high) or toggled to indicate parity.
12.1 Serial Port Register Layout
Figure 12-2 shows a functional block diagram of a serial port. Each serial port has a data register, a control register and a status register. Writing to the data register starts transmission. The least significant bit (LSB) is always transmitted first. This is true for both asycnchronous and synchronous communication. If the write is performed to an alternate data register address, the extra address bit or 9th bit (8th bit if 7 data bits) is sent. When data bits have been received, they are read from the data register (LSB first). The control register is used to set the transmit and receive parameters. The status register may be tested to check on the operation of the serial port.

Figure 12-2. Functional Block Diagram of a Serial Port
The clock input to the serial port unit must be 8 or 16 (selectable) times the baud rate in the asynchronous mode and 2 times the baud rate for the clocked serial mode when the internal clock is used. Timers A2-A7 supply the input clock for Serial Ports A-F. These timers can divide the frequency by any number from 1 to 256 (see Chapter 11). The input frequency to the timers can be selected in different ways described in the documentation for the timers. One choice is the peripheral clock--with that choice and a well-chosen crystal frequency for the main oscillator, the most commonly used baud rates can be obtained down to approximately 2400 bps or lower by prescaling timer A0 at the highest Rabbit clock frequencies (see Section A.4 in Appendix A).
12.2 Serial Port Registers
Each serial port has 6 registers shown in the tables below. The status, control and extended registers may have somewhat different formats for different serial ports.
Table 12-2. Serial Port A Registers
Serial Port A Data Register
|
SADR
|
0xC0
|
R/W
|
xxxxxxxx
|
Serial Port A Address Register
|
SAAR
|
0xC1
|
W
|
xxxxxxxx
|
Serial Port A Long Stop Register
|
SALR
|
0xC2
|
W
|
xxxxxxxx
|
Serial Port A Status Register
|
SASR
|
0xC3
|
R
|
0xx00000
|
Serial Port A Control Register
|
SACR
|
0xC4
|
W
|
xx000000
|
Serial Port A Extended Register
|
SAER
|
0xC5
|
W
|
00000000
|
Table 12-3. Serial Port B Registers
Serial Port B Data Register
|
SBDR
|
0xD0
|
R/W
|
xxxxxxxx
|
Serial Port B Address Register
|
SBAR
|
0xD1
|
W
|
xxxxxxxx
|
Serial Port B Long Stop Register
|
SBLR
|
0xD2
|
W
|
xxxxxxxx
|
Serial Port B Status Register
|
SBSR
|
0xD3
|
R
|
0xx00000
|
Serial Port B Control Register
|
SBCR
|
0xD4
|
W
|
xx000000
|
Serial Port B Extended Register
|
SBER
|
0xD5
|
W
|
00000000
|
Table 12-4. Serial Port C Registers
Serial Port C Data Register
|
SCDR
|
0xE0
|
R/W
|
xxxxxxxx
|
Serial Port C Address Register
|
SCAR
|
0xE1
|
W
|
xxxxxxxx
|
Serial Port C Long Stop Register
|
SCLR
|
0xE2
|
W
|
xxxxxxxx
|
Serial Port C Status Register
|
SCSR
|
0xE3
|
R
|
0xx00000
|
Serial Port C Control Register
|
SCCR
|
0xE4
|
W
|
xx000000
|
Serial Port C Extended Register
|
SCER
|
0xE5
|
W
|
00000000
|
Table 12-5. Serial Port D Registers
Serial Port D Data Register
|
SDDR
|
0xF0
|
R/W
|
xxxxxxxx
|
Serial Port D Address Register
|
SDAR
|
0xF1
|
W
|
xxxxxxxx
|
Serial Port D Long Stop Register
|
SDLR
|
0xF2
|
W
|
xxxxxxxx
|
Serial Port D Status Register
|
SDSR
|
0xF3
|
R
|
0xx00000
|
Serial Port D Control Register
|
SDCR
|
0xF4
|
W
|
xx000000
|
Serial Port D Extended Register
|
SDER
|
0xF5
|
W
|
00000000
|
Table 12-6. Serial Port E Registers
Serial Port E Data Register
|
SEDR
|
0xC8
|
R/W
|
xxxxxxxx
|
Serial Port E Address Register
|
SEAR
|
0xC9
|
W
|
xxxxxxxx
|
Serial Port E Long Stop Register
|
SELR
|
0xCA
|
W
|
xxxxxxxx
|
Serial Port E Status Register
|
SESR
|
0xCB
|
R
|
0xx00000
|
Serial Port E Control Register
|
SECR
|
0xCC
|
W
|
xx000000
|
Serial Port E Extended Register
|
SEER
|
0xCD
|
W
|
000x000x
|
Table 12-7. Serial Port F Registers
Serial Port F Data Register
|
SFDR
|
0xD8
|
R/W
|
xxxxxxxx
|
Serial Port F Address Register
|
SFAR
|
0xD9
|
W
|
xxxxxxxx
|
Serial Port F Long Stop Register
|
SFLR
|
0xDA
|
W
|
xxxxxxxx
|
Serial Port F Status Register
|
SFSR
|
0xDB
|
R
|
0xx00000
|
Serial Port F Control Register
|
SFCR
|
0xDC
|
W
|
xx000000
|
Serial Port F Extended Register
|
SFER
|
0xDD
|
W
|
000x000x
|
Table 12-8. Data Register All Ports
Serial Port x Data Register (SADR) (Address = 0xC0) (SBDR) (Address = 0xD0) (SCDR) (Address = 0xE0) (SDDR) (Address = 0xF0) (SEDR) (Address = 0xC8) (SFDR) (Address = 0xD8)
|
|
|
|
Returns the contents of the receive buffer.
|
|
|
Loads the transmit buffer with a data byte for transmission.
|
Table 12-9. Address Register All Ports
Serial Port x Address Register (SAAR) (Address = 0xC1) (SBAR) (Address = 0xD1) (SCAR) (Address = 0xE1) (SDAR) (Address = 0xF1) (SEAR) (Address = 0xC9) (SFAR) (Address = 0xD9)
|
|
|
|
Returns the contents of the receive buffer. In Clocked Serial mode reading the data from this register automatically causes the receiver to start a byte receive operation (the current contents of the receive buffer are read first), eliminating the need for software to issue the Start Receive command.
|
|
|
Loads the transmit buffer with an address byte, marked with a "zero" address bit, for transmission. In HDLC mode, the last byte of a frame must be written to this register to enable subsequent CRC and closing Flag transmission. In Clocked Serial mode writing the data to this register causes the transmitter to start a byte transmit operation, eliminating the need for the software to issue the Start Transmit command.
|
Table 12-10. Long Stop Register All Ports
Serial Port x Long Stop Register (SALR) (Address = 0xC2) (SBLR) (Address = 0xD2) (SCLR) (Address = 0xE2) (SDLR) (Address = 0xF2) (SELR) (Address = 0xCA) (SFLR) (Address = 0xDA)
|
|
|
|
Returns the contents of the receive buffer.
|
|
|
Loads the transmit buffer with an address byte, marked with a "one" address bit, for transmission. In HDLC mode the last byte of a frame is written to this register to enable subsequent closing Flag transmission.
|
Table 12-11. Status Register Asynchronous Mode Only (All Ports)
Serial Port x Status Register (SASR) (Address = 0xC3) (SBSR) (Address = 0xD3) (SCSR) (Address = 0xE3) (SDSR) (Address = 0xF3) (SESR) (Address = 0xCB) (SFSR) (Address = 0xDB)
|
|
|
|
Description (Async mode only)
|
|
|
|
The receive data register is empty--no input character is ready.
|
|
|
There is a byte in the receive buffer. The transition from "0" to "1" sets the receiver interrupt request flip-flop. The interrupt FF is cleared when the character is read from the data buffer. The interrupt FF will be immediately set again if there are more characters available in the FIFO or shift register to be transferred into the data buffer.
|
|
|
|
The byte in the receive buffer is data, received with a valid Stop bit.
|
|
|
Address bit or 9th (8th) bit received. This bit is set if the character in the receiver data register has a 9th (8th) bit. This bit is cleared and should be checked before reading a data register since a new data value with a new address bit may be loaded immediately when the data register is read.
The byte in the receive buffer is an address, or a byte with a framing error. If an address bit is not expected. If the data in the buffer is all zeros, this may be a Break.
|
|
|
|
The receive buffer was not overrun.
|
|
|
This bit is set if the receiver is overrun. This happens if the shift register and the data register are full and a start bit is detected. This bit is cleared when the receiver data register is read.
|
|
|
|
This bit is always zero in async mode.
|
|
|
|
The transmit buffer is empty.
|
|
|
Transmitter data buffer full. This bit is set when the transmit data register is full, that is, a byte is written to the serial port data register. It is cleared when a byte is transferred to the transmitter shift register or FIFO, or a write operation is performed to the serial port status register. This bit will request an interrupt on the transition from 1 to 0 if interrupts are enabled. Transmit interrupts are cleared when the transmit buffer is written, or any value (which will be ignored) is written to this register.
|
|
|
|
The transmitter is idle.
|
|
|
Transmitter busy bit. This bit is set if the transmitter shift register is busy sending data. It is set on the falling edge of the start bit, which is also the clock edge that transfers data from the transmitter data register to the transmitter shift register. The transmitter busy bit is cleared at the end of the stop bit of the character sent. This bit will cause an interrupt to be latched when it goes from busy to not busy status after the last character has been sent (there are no more data in the transmitter data register).
|
|
|
|
These bits are always zero in async mode.
|
Table 12-12. Status Register Clocked Serial (Ports A-D only)
Serial Port x Status Register (SASR) (Address = 0xC3) (SBSR) (Address = 0xD3) (SCSR) (Address = 0xE3) (SDSR) (Address = 0xF3)
|
|
|
|
Description (Clocked serial mode only)
|
|
|
|
The receive data register is empty
|
|
|
There is a byte in the receive buffer. The serial port will request an interrupt while this bit is set. The interrupt is cleared when the receive buffer is empty.
|
|
|
|
This bit is always zero in clocked serial mode.
|
|
|
|
The receive buffer was not overrun.
|
|
|
The receive buffer was overrun. This bit is cleared by reading the receive buffer.
|
|
|
|
This bit is always zero in clocked serial mode.
|
|
|
|
The transmit buffer is empty.
|
|
|
The transmit buffer is not empty. The serial port will request an interrupt when the transmitter takes a byte from the transmit buffer. Transmit interrupts are cleared when the transmit buffer is written, or any value (which will be ignored) is written to this register.
|
|
|
|
The transmitter is idle.
|
|
|
The transmitter is sending a byte. An interrupt is generated when the transmitter clears this bit, which occurs only if the transmitter is ready to start sending another byte but the transmit buffer is empty.
|
|
|
|
These bits are always zero in clocked serial mode.
|
Table 12-13. Status Register HDLC Mode (Ports E and F only)
Serial Port x Status Register (SESR) (Address = 0xCB) (SFSR) (Address = 0xD3)
|
|
|
|
Description (HDLC mode only)
|
|
|
|
The receive data register is empty
|
|
|
There is a byte in the receive buffer. The serial port will request an interrupt while this bit is set. The interrupt is cleared when the receive buffer is empty.
|
|
|
|
The byte in the receive buffer is data.
|
|
|
The byte in the receive buffer was followed by an Abort.
|
|
|
The byte in the receive buffer is the last in the frame, with valid CRC.
|
|
|
The byte in the receive buffer is the last in the frame, with a CRC error.
|
|
|
|
The receive buffer was not overrun.
|
|
|
The receive buffer was overrun. This bit is cleared by reading the receive buffer.
|
|
|
|
The transmit buffer is empty.
|
|
|
The transmit buffer is not empty. The serial port will request an interrupt when the transmitter takes a byte from the transmit buffer, unless the byte is marked as the last in the frame. Transmit interrupts are cleared when the transmit buffer is written, or any value (which will be ignored) is written to this register.
|
|
|
|
Transmit interrupt due to buffer empty condition.
|
|
|
Transmitter finished sending CRC. An interrupt is generated at the end of CRC transmission. Data written in response to this interrupt will cause only one Flag to be transmitted between frames, and no interrupt will be generated by this Flag.
|
|
|
Transmitter finished sending an Abort. An interrupt is generated at the end of an Abort transmission.
|
|
|
The transmitter finished sending a closing Flag. Data written in response to this interrupt will cause at least two Flags to be transmitted between frames.
|
|
|
|
The byte in the receiver buffer is 8 bits.
|
|
|
The byte in the receiver buffer is less than 8 bits.
|
Table 12-14. Serial Port Control Register Ports A and B
Serial Port x Control Register (SACR) (Address = 0xC4) (SBCR) (Address = 0xD4)
|
|
|
|
No operation. These bits are ignored in the Async mode.
|
|
|
|
In clocked serial mode, start a byte receive operation.
|
|
|
|
In clocked serial mode, start a byte transmit operation.
|
|
|
|
In clocked serial mode, start a byte transmit operation and a byte receive operation simultaneously.
|
|
|
|
Parallel Port C is used for input.
|
|
|
|
Parallel Port D is used for input.
|
|
|
|
Disable the receiver input.
|
|
|
|
Async mode with 8 bits per character.
|
|
|
|
Async mode with 7 bits per character. In this mode the most significant bit of a byte is ignored for transmit, and is always zero in receive data.
|
|
|
|
Clocked serial mode with external clock.
Serial Port A clock is on Parallel Port PB1
Serial Port B clock is on Parallel Port PB0
|
|
|
|
Clocked serial mode with internal clock.
Serial Port A clock is on Parallel Port PB1
Serial Port B clock is on Parallel Port PB0
|
|
|
|
The Serial Port interrupt is disabled.
|
|
|
|
The Serial Port uses Interrupt Priority 1.
|
|
|
|
The Serial Port uses Interrupt Priority 2.
|
Table 12-15. Serial Port Control Register Ports C and D
Serial Port x Control Register (SCCR) (Address = 0xE4) (SDCR) (Address = 0xF4)
|
|
|
|
No operation. These bits are ignored in the async mode.
|
|
|
In clocked serial mode, start a byte receive operation.
|
|
|
In clocked serial mode, start a byte transmit operation.
|
|
|
In clocked serial mode, start a byte transmit operation and a byte receive operation simultaneously.
|
|
|
|
Enable the receiver input.
|
|
|
Disable the receiver input.
|
|
|
|
This bit is ignored.
|
|
|
|
8 bits per character.
|
|
|
7 bits per character. In this mode the most significant bit of a byte is ignored for transmit, and is always zero in receive data.
|
|
|
Clocked serial mode with external clock.
Serial Port C clock is on Parallel Port PF1
Serial Port D clock is on Parallel Port PF0
|
|
|
Clocked serial mode with internal clock.
Serial Port C clock is on Parallel Port PF1
Serial Port D clock is on Parallel Port PF0
|
|
|
|
The serial port interrupt is disabled.
|
|
|
The serial port uses Interrupt Priority 1.
|
|
|
The serial port uses Interrupt Priority 2.
|
|
|
The serial port uses Interrupt Priority 3.
|
Table 12-16. Serial Port Control Register Ports E and F
Serial Port x Control Register (SECR) (Address = 0xCC) (SFCR) (Address = 0xDC)
|
|
|
|
No operation. These bits are ignored in the Async mode.
|
|
|
In HDLC mode, force receiver in Flag Search mode.
|
|
|
No operation.
|
|
|
In HDLC mode, transmit an Abort pattern.
|
|
|
|
Enable the receiver input.
|
|
|
Disable the receiver input.
|
|
|
|
This bit is ignored.
|
|
|
|
Async mode with 8 bits per character.
|
|
|
Async mode with 7 bits per character. In this mode the most significant bit of a byte is ignored for transmit, and is always zero in receive data.
|
|
|
HDLC mode with external clock. The external clock is supplied via Serial Port F pins.
|
|
|
HDLC mode with internal clock. The clock is 16X the data rate, and the DPLL is used to recover the receive clock. If necessary, the receiver and transmitter clocks can be output via Port F pins.
|
|
|
|
The serial port interrupt is disabled.
|
|
|
The serial port uses Interrupt Priority 1.
|
|
|
The serial port uses Interrupt Priority 2.
|
|
|
The serial port uses Interrupt Priority 3.
|
Table 12-17. Extended Register Asynchronous Mode All Ports
Serial Port x Extended Register (SAER) (Address = 0xC5) (SBER) (Address = 0xD5) (SCER) (Address = 0xE5) (SDER) (Address = 0xF5) (SEER) (Address = 0xCD) (SFER) (Address = 0xDD)
|
|
|
|
Description (Async mode only)
|
|
|
|
These bits are ignored in async mode.
|
|
|
|
Normal async data encoding.
|
|
|
Enable RZI coding (3/16ths bit cell IRDA-compliant).
|
|
|
|
Normal Break operation. This option should be selected when address bits are expected.
|
|
|
Fast Break termination. At the end of Break a dummy character is written to the buffer, and the receiver can start character assembly after one bit time.
|
|
|
|
Async clock is 16X data rate.
|
|
|
Async clock is 8X data rate.
|
|
|
|
These bits are ignored in async mode.
|
Table 12-18. Extended Register Clocked Serial Mode (Ports A-D only)
Serial Port x Extended Register (SAER) (Address = 0xC5) (SBER) (Address = 0xD5) (SCER) (Address = 0xE5) (SDER) (Address = 0xF5)
|
|
|
|
Description (Clocked serial mode only)
|
|
|
|
Normal clocked serial operation.
|
|
|
Timer synchronized clocked serial operation.
|
|
|
|
Timer-synchronized clocked serial uses Timer B1.
|
|
|
Timer-synchronized clocked serial uses Timer B2.
|
|
|
|
Normal clocked serial clock polarity, inactive High. Internal or external clock.
|
|
|
Normal clocked serial clock polarity, inactive Low. Internal clock only.
|
|
|
Inverted clocked serial clock polarity, inactive Low. Internal or external clock.
|
|
|
Inverted clocked serial clock polarity, inactive High. Internal clock only.
|
|
|
|
These bits are ignored in clocked serial mode.
|
|
|
|
No effect on transmitter.
|
|
|
Terminate current clocked serial transmission. No effect on buffer.
|
|
|
|
No effect on receiver.
|
|
|
Terminate current clocked serial reception.
|
Table 12-19. Extended Register HDLC Mode (Ports E and F only)
Serial Port x Extended Register (SEER) (Address = 0xCD) (SFER) (Address = 0xDD)
|
|
|
|
Description (HDLC mode only)
|
|
|
|
NRZ data encoding for HDLC receiver and transmitter.
|
|
|
NRZI data encoding for HDLC receiver and transmitter.
|
|
|
Biphase-Level (Manchester) data encoding for HDLC receiver and transmitter.
|
|
|
Biphase-Space data encoding for HDLC receiver and transmitter.
|
|
|
Biphase-Mark data encoding for HDLC receiver and transmitter.
|
|
|
|
Normal HDLC data encoding.
|
|
|
Enable RZI coding (1/4th bit cell IRDA-compliant). This mode can only be used with internal clock and NRZ data encoding.
|
|
|
|
Idle line condition is Flags.
|
|
|
Idle line condition is all ones.
|
|
|
|
Transmit Flag on underrun.
|
|
|
Transmit Abort on underrun.
|
|
|
|
These bits are ignored in HDLC mode.
|
12.3 Serial Port Interrupt
A common interrupt vector is used for the receive and transmit interrupts. There is a separate interrupt request flip-flop for the receiver and transmitter. If either of these flip-flops is set, a serial port interrupt is requested. The flip-flops are set by a rising edge only. The flip-flops are cleared by a pulse generated by an I/O read or write operation as shown in Figure 12-3. When an interrupt is requested, it will take place immediately when priorities allow and an instruction execution is complete. The interrupt is lost if the request flip-flop is cleared before the interrupt takes place. If the flip-flop is not cleared in the interrupt, another interrupt will take place when priorities are lowered.

Figure 12-3. Generation of Serial Port Interrupts
The receive interrupt request flip-flop is set after the stop bit is sampled on receive, nominally 1/2 of the way through the stop bit. Data bits are transferred on this same clock from the receive shift register to the receive data register.
The transmit interrupt request flip-flop is set on the leading edge of the start bit for data register empty and at the trailing edge of the stop bit for shift register empty (transmitter idle). Unless the data register is empty on this trailing edge of the stop bit, the transmitter does not become idle. The transmitter becomes idle only if the data register is empty at the trailing edge of the stop bit.
The serial port interrupt vectors are shown in Table 6-1.
12.4 Transmit Serial Data Timing
On transmit, if the interrupts are enabled, an interrupt is requested when the transmit register becomes empty and, in addition, an interrupt occurs when the shift register and transmit register both become empty, that is, when the transmitter becomes idle. The shift register is empty when the last bit is shifted out. When the transmit data register contains data and the shift register finishes sending data, the data bits are clocked from the transmit register to the shift register, and the shift register is never idle. The interrupt request is cleared either by writing to the data register or by writing to the status register (which does not affect the status register). The data register normally is clocked into the shift register each time the shift register finishes sending data, leaving the data register empty. This causes an interrupt request. The interrupt routine normally answers the interrupt before the shift register runs dry (9 to 11 baud clocks, depending on the mode of operation). The interrupt routine stores the next data item in the data register, clearing the interrupt request and supplying the next data bits to be sent. When all the characters have been sent, the interrupt service routine answers the interrupt once the data register becomes empty. Since it has no more data, it clears the interrupt request by storing to the status register. At this point the routine should check if the shift register is empty; normally it won't be. If it is, because the interrupt was answered late, the interrupt routine should do any final cleanup and store to the status register again in case the shift register became empty after the pending interrupt is cleared. Normally, though, the interrupt service routine will return and there will be a final interrupt to give the routine a chance to disable the output buffers, as in the case for RS-485 transmission.
12.5 Receive Serial Data Timing
When the receiver is ready to receive data, a falling edge indicates that a start bit must be detected. The falling edge is detected as a different Rx input between two different clocks, the clock being 8x or 16x the baud rate. Once the start bit has been detected, data bits are sampled at the middle of each data bit and are shifted into the receive shift register. After 7 or 8 data bits have been received, the next bit will be either a 9th (8th) address bit, or a stop bit will be sampled. If the Rx line is low, it is an address bit and the address bit received bit in the status register will be enabled. If an address bit is detected, the receiver will attempt to sample the stop bit. If the line is high when sampled, it is a stop bit and a new scan for a new start bit will begin after the sample point. At the same time, the data bits are transferred into the receive data register and an interrupt, if enabled, is requested.
On receive, an interrupt is requested when the receiver data register has data. This happens when data bits are transferred from the receive shift register to the data register. This also sets bit 7 of the status register. The interrupt request and bit 7 are cleared when the data register is read.
An interrupt is requested if bit 7 is high. The interrupt is requested on the edge of the transmitter data register becoming empty or the transmitter shift register becoming empty. The transmitter interrupt is cleared by writing to the status register or to the data register.
On receive, the scan for the next start bit starts immediately after the stop bit is detected. The stop bit is normally detected at a sample clock that nominally occurs in the center of the stop bit. If there is a 9th (8th) address bit, the stop bit follows that bit.
The serial clock can be configured to be either 16× the data rate or 8× the data rate.

Figure 12-4. Serial Port Synchronization
12.6 Clocked Serial Ports
Ports A-D can operate in clocked mode. The data line and clock line are driven as shown in Figure 12-4. The data and clock are provided as 8-bit bursts with the LSB shifted out and/or received first. By default the transmit shift register advances on the falling edge of the clock and the receiver samples the data on the rising edge of the clock. The serial port can generate the clock or the clock can be provided externally.
The clock polarity is programmable in clocked serial mode according to Figure . The clocked serial transfer may also be synchronized to the output of either of the match conditions in Timer B to give precisely timed transfers.
To enable the clocked serial mode, a code must be in bits (3,2) of the control register, enabling the clocked serial mode with either an internal clock or an external clock. The transition between the external and the internal clock should be performed with care. Normally a pullup resistor is needed on the clock line to prevent spurious clocks while neither party is driving the clock.

Figure 12-5. Clock Polarities Supported in Clocked Serial Mode
In clocked serial mode the shift register and the data register work in the same fashion as for asynchronous communications. However, to initiate basic sending or receiving, a command must be issued by writing to bits (7,6) of the control register for each byte sent or received. One command is for sending a byte, a different command is for receiving a byte, and yet another command can initiate a transmit and receive at the same time for full duplex communication. Alternatively, a read or write to the Serial Ports A-D Address registers (SxAR) eliminates the need to issue separate receive and transmit commands. In clocked serial mode, reading the data from the corresponding SxAR register automatically causes the receiver to start a byte receive operation, eliminating the need for software to issue the Start Receive command. Any data contained in the receive buffer will be read first before being replaced with new incoming data. Similarly, writing the data to the SxAR register causes the transmitter to start a byte transmit operation, eliminating the need for the software to issue the Start Transmit command. The effect of these codes is different, depending on whether the mode is internal clock or external clock.
To transmit in internal clock mode, the user must first load the data register (which must be empty) and then store the send code. When the shift register finishes sending the current character, if any, the data register will be loaded into the shift register and transmitted by an 8-clock burst. One character can be in the process of transmitting while another character is waiting in the data register tagged with the send code. The send code is effectively double-buffered.
To receive a character in internal clock mode, the receive shift register should be idle. The user then stores the receive code in the control register. A burst of 8 clocks will be generated and the sender must detect the clocks and shift output data to the data line on the falling edge of each clock. The receiver will sample the data on the rising edge of each clock for clock modes 00 and 01 or the falling edge for clock modes 10 and 11. The receive mode cannot double-buffer characters when using the internal clock. The shift register must be idle before another character receive can be initiated. However, the interrupt request and character ready takes place on the rising edge of the last clock pulse. If the next receive code is stored before the natural location of the next falling edge, another receive will be initiated without pausing the clock. To do this, the interrupt has to be serviced within 1/2 clock.
To transmit each byte in external clock mode, the user