Rabbit 4000 Microprocessor
User's Manual
PREV INDEX NEXT


16. Serial Ports A – D

16.1 Overview

Serial Ports A, B, C, and D are identical, except for the source of the data clock and the transmit, receive, and clock pins. Serial Port A is special because it can be used to bootstrap the processor. Each serial port can be used in the asynchronous or the clocked serial mode with an internal or external clock.

In the asynchronous mode, either 7 or 8 data bits can be transferred, and a parity bit and/or an additional address (0) or long stop (1) bit can be appended as well. Parity and the address/long stop bits are also detected when they are received. The asynchronous mode is full-duplex, while the clocked mode can be half or full-duplex.

Both transmit and receive have one byte of buffering — a byte may be read while another byte is being received, or the next byte to be transmitted can be loaded while the current byte is still being transferred out. The byte is available in the buffer after the final bit is sampled.

The status of each serial port is available in the Serial Port Status Registers (SxSR), and contains information on whether a received byte is available, the receive buffer was overrun, a parity error was received, and the transmit buffer is empty or busy sending a byte. The status is updated when the final bit of a received byte is sampled, or when the final bit of a transmitted byte is sent out. Each serial port has a separate interrupt vector that will be requested whenever the transmit buffer is emptied or the receive buffer contains a full byte.

All four common SPI clock modes are supported, and the bit order of the data may be either MSB or LSB first. The transmit and receive operations are under program control as well.


Figure 16-1. Serial Ports A – D Operation in Clocked Serial Mode

In the asynchronous mode, IrDA-compliant RZI encoding can be enabled to reduce the bit widths to 3/16 the normal width (1/8 the normal width if the serial data clock is 8× instead of 16× ), which allows the serial port signal to be connected directly to an IrDA transceiver.

It is possible to select the same pin on Parallel Port C for both transmit and receive operation. This allows glueless support for bidirectional serial protocols.

It is possible to synchronize a clocked serial transfer to the match registers of Timer B to generate precisely timed transmissions.


The serial port data clocks can be generated from the appropriate 8-bit timer from Timer A shown in Table 16-1 or from a dedicated n+1 15-bit divider. In either case, the resulting byte data rate in the asynchronous mode is 1/8 or 1/16 the data clock rate (selectable). However, in the clocked serial mode the byte data rate is equal to the data clock rate as generated from the appropriate Timer A timer or from the dedicated 15-bit divider.

When Serial Port A is used in the asynchronous bootstrap mode, the 32 kHz clock is used to generate the expected 2400 bps data rate. An external clock must be supplied for the clocked serial bootstrap mode.

The behavior of the serial port during a break (line held low) is configurable; character assembly can continue during the break condition to allow for timing the break, or character assembly can be inhibited to reduce the interrupt overhead.

16.1.1 Block Diagram


16.1.2 Registers

Register Name

Mnemonic

I/O Address

R/W

Reset

Serial Port A Data Register
SADR
0x00C0
R/W
xxxxxxxx
Serial Port A Address Register
SAAR
0x00C1
W
xxxxxxxx
Serial Port A Long Stop Register
SALR
0x00C2
W
xxxxxxxx
Serial Port A Status Register
SASR
0x00C3
R
0xx00000
Serial Port A Control Register
SACR
0x00C4
R/W
xx000000
Serial Port A Extended Register
SAER
0x00C5
R/W
00000000
Serial Port A Divider Low Register
SADLR
0x00C6
R/W
xxxxxxxx
Serial Port A Divider High Register
SADHR
0x00C7
R/W
0xxxxxxx
Serial Port B Data Register
SBDR
0x00D0
R/W
xxxxxxxx
Serial Port B Address Register
SBAR
0x00D1
W
xxxxxxxx
Serial Port B Long Stop Register
SBLR
0x00D2
W
xxxxxxxx
Serial Port B Status Register
SBSR
0x00D3
R
0xx00000
Serial Port B Control Register
SBCR
0x00D4
R/W
xx000000
Serial Port B Extended Register
SBER
0x00D5
R/W
00000000
Serial Port B Divider Low Register
SBDLR
0x00D6
R/W
xxxxxxxx
Serial Port B Divider High Register
SBDHR
0x00D7
R/W
0xxxxxxx
Serial Port C Data Register
SCDR
0x00E0
R/W
xxxxxxxx
Serial Port C Address Register
SCAR
0x00E1
W
xxxxxxxx
Serial Port C Long Stop Register
SCLR
0x00E2
W
xxxxxxxx
Serial Port C Status Register
SCSR
0x00E3
R
0xx00000
Serial Port C Control Register
SCCR
0x00E4
R/W
xx000000
Serial Port C Extended Register
SCER
0x00E5
R/W
00000000
Serial Port C Divider Low Register
SCDLR
0x00E6
R/W
xxxxxxxx
Serial Port C Divider High Register
SCDHR
0x00E7
R/W
0xxxxxxx
Serial Port D Data Register
SDDR
0x00F0
R/W
xxxxxxxx
Serial Port D Address Register
SDAR
0x00F1
W
xxxxxxxx
Serial Port D Long Stop Register
SDLR
0x00F2
W
xxxxxxxx
Serial Port D Status Register
SDSR
0x00F3
R
0xx00000
Serial Port D Control Register
SDCR
0x00F4
R/W
xx000000
Serial Port D Extended Register
SDER
0x00F5
R/W
00000000
Serial Port D Divider Low Register
SDDLR
0x00F6
R/W
xxxxxxxx
Serial Port D Divider High Register
SDDHR
0x00F7
R/W
0xxxxxxx


16.2 Dependencies

16.2.1 I/O Pins

Serial Port A can transmit on parallel port pins PC7, PC6, or PD6, and can receive on pins PC7, PD7, or PE7. If the clocked serial mode is enabled, the serial clock is either transmitted or received on PB1. When an internal clock is selected in the clocked serial mode, PB1 is automatically enabled as a clock output.

Serial Port B can transmit on parallel port pins PC5, PC4, or PD4, and can receive on pins PC5, PD5, or PE5. If the clocked serial mode is enabled, the serial clock is either transmitted or received on PB0. When an internal clock is selected in the clocked serial mode, PB0 is automatically enabled as a clock output.

Serial Port C can transmit on parallel port pins PC3 or PC2, and can receive on pins PC3, PD3, or PE3. If the clocked serial mode is enabled and 8-bit memories are used, the serial clock will be transmitted on PD2, and can be received on either PD2 or PE2. The serial clock may also be transmitted on PC7, PD7, or PE7. When 16-bit memories are used, the serial clock can be transmitted on PC7 or PE7, and can be received on PD2 or PE2.

NOTE When Serial Port C is used as a clocked serial port and 8-bit memories are used, the serial clock is transmitted on PD2, and so PD2 will not be available for other use.

Serial Port D can transmit on parallel port pins PC1 or PC0, and can receive on pins PC1, PD1, or PE1. If the clocked serial mode is enabled and 8-bit memories are used, the serial clock will be transmitted on PD0, and can be received on either PD0 or PE0. The serial clock may also be transmitted on PC3, PD3, or PE3. When 16-bit memories are used, the serial clock can be transmitted on PC3 or PE3, and can be received on PD0 or PE0.

NOTE When Serial Port D is used as a clocked serial port and 8-bit memories are used, the serial clock is transmitted on PD0, and so PD0 will not be available for other use.

Table 16-2. Pin Usage Serial Ports A – D

Function

Serial Port A

Serial Port B

Serial Port C

Serial Port D

Transmit
PC7, PC6, PD6
PC5, PC4, PD4
PC3, PC2
PC1, PC0
Receive
PC7, PD7, PE7
PC5, PD5, PE5
PC3, PD3, PE3
PC1, PD1, PE1
Transmit Clock
PB1
PB0
PD2
(PC7, PD7, PE7)1.
PD0
(PC3, PD3, PE3)*
Receive Clock
PB1
PB0
PD2, PE2
PD0, PE0

  * The options in parentheses may be used in addition to PD2 or PD0 for the corresponding serial port. One of the highlighted pins not on Parallel Port D must be used for the clocked output when you are using the serial port in the clocked serial mode and you are using 16-bit memories.


16.2.2 Clocks

The data clocks for Serial Ports A – D are based on the peripheral clock and are divided by either a Timer A divider or a dedicated 15-bit divider. In either case, the overall clock divider will be the value in the appropriate register plus one.

16.2.3 Other Registers

Register

Function

TAT4R
Time constant for Serial Port A
TAT5R
Time constant for Serial Port B
TAT6R
Time constant for Serial Port C
TAT7R
Time constant for Serial Port D
PCFR, PCAHR, PCALR
PDFR, PDAHR, PDALR
PEFR, PEAHR, PEALR
Alternate port output selection


16.2.4 Interrupts

A serial port interrupt can be generated whenever a byte is available in the receive buffer or when a byte is finished being transmitted out of the transmit buffer.

The serial port interrupt vectors are located in the IIR as follows.

Each of them can be set as Priority 1, 2, or 3 in SxCR, where x is A – D for the four serial ports.

16.3 Operation

16.3.1 Asynchronous Mode

The following steps explain how to set up Serial Ports A – D for asynchronous operation. The serial ports can be used by polling the status byte, but their performance will be better with an interrupt. These instructions also apply to the asynchronous operation of Serial Ports E – F.

  1. Write the interrupt vector for the interrupt service routine to the internal interrupt table.

  2. Set up the desired transmit pin by writing to the appropriate parallel port function register (PxFR) and alternate output register (PxALR or PxAHR).

  3. Select the appropriate mode by writing to SxCR (receive input port and 7 or 8 bits). Also select the interrupt priority.

  4. Select additional options by writing to SxER (parity, RZI encoding, clock polarity, and behavior during break).

  5. Write the desired divider value to TATxR for the appropriate serial port, or else write a divider value to the dedicated 15-bit divider in SxDLR and SxDHR. If the dedicated divider is to be used, write a 1 to the most-significant bit of SxDHR to enable it.

A sample asynchronous serial interrupt handler is shown below for Serial Port A.

To transmit with an address (1) bit appended, write the data to SxAR instead of SxDR; to append a long stop (0) bit write to SxLR instead.

16.3.2 Clocked Serial Mode

The following steps explain how to set up Serial Ports A – D for the clocked serial mode. When the internal clock is selected, the Rabbit 4000 is in control of all transmit and receive operations. When an external clock is selected the other device controls all transmit and receive operation. For both situations the decision between polling and interrupt-driven methods is application dependent.

  1. Write the interrupt vector for the interrupt service routine to the internal interrupt table.

  2. Set up the desired data transmit and clock pins by writing to the appropriate parallel port function register (PxFR) and alternate output register (PxALR or PxAHR).

  3. Select the appropriate mode by writing to SxCR (receive input port and clock source). Also select the interrupt priority.

  4. Select additional options by writing to SxER (clock polarity, bit order, and clock source if external).

  5. Write the desired divider value to TATxR for the appropriate serial port, or else write a divider to the dedicated 15-bit divider in SxDLR and SxDHR. If the dedicated divider is to be used, write a 1 to the most-significant bit of SxDHR to enable it.

  6. There are two methods to transfer a byte:

write the byte to SxDR and then write 10 (or 11) to bits 6-7 of SxCR to enable the transfer;
write the byte to SxAR which will automatically start the transfer.

If the internal clock is selected, the transmission will begin immediately; if an external clock is selected, the transmission will begin when the clock is detected.

  1. To receive a byte, write 01 to bits 6-7 of SxCR to start the receive operation. If the internal clock is selected, the clock will begin immediately and the data will be read; if an external clock is selected, the receive will occur when the clock is detected.

A sample clocked serial interrupt handler is shown below for Serial Port B.

16.4 Register Descriptions

Serial Port x Data Register (SADR) (Address = 0x00C0)
(SBDR) (Address = 0x00D0)
(SCDR) (Address = 0x00E0)
(SDDR) (Address = 0x00F0)

Bit(s)

Value

Description

7:0
Read
Returns the contents of the receive buffer.
Write
Loads the transmit buffer with a data byte for transmission.


Serial Port x Address Register (SAAR) (Address = 0x00C1)
(SBAR) (Address = 0x00D0)
(SCAR) (Address = 0x00E0)
(SDAR) (Address = 0x00F0)

Bit(s)

Value

Description

7:0
Read
Returns the contents of the receive buffer. Reading the data from this register in the clocked serial mode automatically causes the receiver to start a byte-receive operation, eliminating the need for software to issue the start-receive command.
Write
Loads the transmit buffer with an address byte, marked with a "zero" address bit, for transmission. Writing the data to this register in the clocked serial mode causes the transmitter to start a byte-transmit operation, eliminating the need for the software to issue the start-transmit command.


Serial Port x Long Stop Register (SALR) (Address = 0x00C2)
(SBLR) (Address = 0x00D0)
(SCLR) (Address = 0x00E0)
(SDLR) (Address = 0x00F0)

Bit(s)

Value

Description

7:0
Read
Returns the contents of the receive buffer.
Write
Loads the transmit buffer with an address byte, marked with a "one" address bit, for transmission.


Serial Port x Status Register (SASR) (Address = 0x00C3)
(Asynchronous Mode Only) (SBSR) (Address = 0x00D3)
(SCSR) (Address = 0x00E3)
(SDSR) (Address = 0x00F3)

Bit(s)

Value

Description

7
0
The receive data register is empty
1
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.
6
0
The byte in the receive buffer is data, received with a valid stop bit.
1
The byte in the receive buffer is an address, or a byte with a framing error. If an address bit is not expected, and the data in the buffer is all zeros, this is a break.
5
0
The receive buffer was not overrun.
1
The receive buffer was overrun. This bit is cleared by reading the receive buffer.
4
0
The byte in the receive buffer has no parity error (or was not checked for parity).
1
The byte in the receive buffer had a parity error.
3
0
The transmit buffer is empty.
1
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.
2
0
The transmitter is idle.
1
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 and the transmit buffer is empty.
1:0
00
These bits are always zero in async mode.


Serial Port x Status Register (SASR) (Address = 0x00C3)
(Clocked Serial Mode Only) (SBSR) (Address = 0x00D3)
(SCSR) (Address = 0x00E3)
(SDSR) (Address = 0x00F3)

Bit(s)

Value

Description

7
0
The receive data register is empty
1
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.
6
0
This bit is always zero in the clocked serial mode.
5
0
The receive buffer was not overrun.
1
The receive buffer was overrun. This bit is cleared by reading the receive buffer.
4
0
This bit is always zero in the clocked serial mode.
3
0
The transmit buffer is empty.
1
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.
2
0
The transmitter is idle.
1
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 and the transmit buffer is empty.
1:0
00
These bits are always zero in the clocked serial mode.


Serial Port x Control Register (SACR) (Address = 0x00C4)
(SBCR) (Address = 0x00D4)
(SCCR) (Address = 0x00E4)
(SDCR) (Address = 0x00F4)

Bit(s)

Value

Description

7:6
00
No operation. These bits are ignored in the asynchronous mode.
01
In the clocked serial mode, start a byte-receive operation.
10
In the clocked serial mode, start a byte-transmit operation.
11
In the clocked serial mode, start a byte-transmit operation and a byte-receive operation simultaneously.
5:4
00
Parallel Port C is used for input.
01
Parallel Port D is used for input.
10
Parallel Port E is used for input.
11
Disable the receiver input.
3:2
00
Asynchronous mode with 8 bits per character.
01
Asynchronous 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.
10
Clocked serial mode with external clock.
11
Clocked serial mode with internal clock.
1:0
00
The serial port interrupt is disabled.
01
The serial port uses Interrupt Priority 1.
10
The serial port uses Interrupt Priority 2.
11
The serial port uses Interrupt Priority 3.


Serial Port x Extended Register (SAER) (Address = 0x00C5)
(Asynchronous Mode Only) (SBER) (Address = 0x00D5)
(SCER) (Address = 0x00E5)
(SDER) (Address = 0x00F5)

Bit(s)

Value

Description

7:5
000
Disable parity generation and checking.
001
This bit combination is reserved and should not be used.
010
This bit combination is reserved and should not be used.
011
This bit combination is reserved and should not be used.
100
Enable parity generation and checking with even parity.
101
Enable parity generation and checking with odd parity.
110
Enable parity generation and checking with space (always zero) parity.
111
Enable parity generation and checking with mark (always one) parity.
4
0
Normal asynchronous data encoding.
1
Enable RZI coding (3/16 bit cell IrDA-compliant).
3
0
Normal break operation. This option should be selected when address bits are expected.
1
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.
2
0
Asynchronous clock is 16× data rate.
1
Asynchronous clock is 8× data rate.
1
0
Continue character assembly during break to allow timing the break condition.
1
Inhibit character assembly during break. One character (all zeros, with framing error) at start and one character (garbage) at completion.
0
This bit is ignored in the asynchronous mode.


Serial Port x Extended Register (SAER) (Address = 0x00C5)
(Clocked Serial Mode Only) (SBER) (Address = 0x00D5)
(SCER) (Address = 0x00E5)
(SDER) (Address = 0x00F5)

Bit(s)

Value

Description

7
0
Normal clocked serial operation.
1
Timer-synchronized clocked serial operation.
6
0
Timer-synchronized clocked serial uses Timer B1.
1
Timer-synchronized clocked serial uses Timer B2.
5:4
00
Normal clocked serial clock polarity, inactive high. Internal or external clock.
01
Normal clocked serial clock polarity, inactive low. Internal clock only.
10
Inverted clocked serial clock polarity, inactive low. Internal or external clock.
11
Inverted clocked serial clock polarity, inactive high. Internal clock only.
3
0
Normal bit order (LSB first) for transmit and receive.
1
Reverse bit order (MSB first) for transmit and receive.
2
0
Serial clock (input mode only) from Parallel Port D (SCER and SDER only).
1
Serial clock (input mode only) from Parallel Port E (SCER and SDER only).
1
0
No effect on transmitter.
1
Terminate current clocked serial transmission. No effect on buffer.
0
0
No effect on receiver.
1
Terminate current clocked serial reception.


Serial Port x Divider Low Register (SADLR) (Address = 0x00C6)
(SBDLR) (Address = 0x00D6)
(SCDLR) (Address = 0x00E6)
(SDDLR) (Address = 0x00F6)

Bit(s)

Value

Description

7:0
Eight LSBs of the divider that generates the serial clock for this channel. This divider is not used unless the MSB of the corresponding SxDHR is set to one.


Serial Port x Divider High Register (SADHR) (Address = 0x00C7)
(SBDHR) (Address = 0x00D7)
(SCDHR) (Address = 0x00E7)
(SDDHR) (Address = 0x00F7)

Bit(s)

Value

Description

7
0
Disable the serial port divider and use the output of Timer A to clock the serial port.
1
Enable the serial port divider, and use its output to clock the serial port. The serial port divider counts modulo n + 1 and is clocked by the peripheral clock.
6:0
Seven MSBs of the divider that generates the serial clock for this channel.



Rabbit Semiconductor
www.rabbit.com
PREV INDEX NEXT