© 2004 Microchip Technology Inc. DS70066C-page 19-13
Section 19. UART
UART
19
19.5.3 Setup for UART Transmit
Steps to follow when setting up a transmission:
1. Initialize the UxBRG register for the appropriate baud rate (Section 19.3 “UART Baud
Rate Generator (BRG)”).
2. Set the number of data bits, number of Stop bits, and parity selection by writing to the
PDSEL<1:0> (UxMODE<2:1>) and STSEL (UxMODE<0>) bits.
3. If transmit interrupts are desired, set the UxTXIE control bit in the corresponding Interrupt
Enable Control register (IEC). Specify the interrupt priority for the transmit interrupt using
the UxTXIP<2:0> control bits in the corresponding Interrupt Priority Control register (IPC).
Also, select the Transmit Interrupt mode by writing the UTXISEL (UxSTA<15>) bit.
4. Enable the UART module by setting the UARTEN (UxMODE<15>) bit.
5. Enable the transmission by setting the UTXEN (UxSTA<10>) bit, which will also set the
UxTXIF bit. The UxTXIF bit should be cleared in the software routine that services the
UART transmit interrupt. The operation of the UxTXIF bit is controlled by the UTXISEL
control bit.
6. Load data to the UxTXREG register (starts transmission). If 9-bit transmission has been
selected, load a word. If 8-bit transmission is used, load a byte. Data can be loaded into
the buffer until the UxTXBF status bit (UxSTA<9>) is set.
Figure 19-3: Transmission (8-bit or 9-bit Data)
Figure 19-4: Transmission (Back to Back)
Note: The UTXEN bit should not be set until the UARTEN bit has been set. Otherwise,
UART transmissions will not be enabled.
Character 1
Stop Bit
Character 1 to
Transmit Shift Reg.
Start Bit Bit 0 Bit 1 Bit 7/8
Write to UxTXREG
Character 1
BCLK/16
(Shift Clock)
UxTX
UxTXIF
TRMT bit
UxTXIF Cleared by User
Transmit Shift Reg.
Write to UxTXREG
BCLK/16
(Shift Clock)
UxTX
UxTXIF
TRMT bit
Character 1 Character 2
Character 1 to
Character 2 to
Start Bit
Stop Bit
Start Bit
Transmit Shift Reg.
Character 1
Character 2
Bit 0 Bit 1
Bit 7/8 Bit 0
Note: This timing diagram shows two consecutive transmissions.
(UTXISEL = 0)
UxTXIF
(UTXISEL = 1)
UxTXIF Cleared by User in Software