# Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

### Protego

# PIC24FJ64GA004 -- UART

- 1
- 2
…
- 15
- 16
- 17
- 18
- 19
…
- 55
- 56

 2009-2013 Microchip Technology Inc. DS70000582E-page 17
UART
5.3 Setup for UART Transmit
The following steps are used to set up a transmission:
1. Initialize the UxBRG register for the appropriate baud rate (see Section 3.0 “UART Baud
Rate Generator”).
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 x register (IECx).
4. Specify the interrupt priority for the transmit interrupt using the UxTXIP<2:0> control bits in
the corresponding Interrupt Priority Control x register (IPCx). Also, select the Transmit
Interrupt mode by writing to the UTXISEL<1:0> bits (UxSTA<15,13>).
5. Enable the UART module by setting the UARTEN bit (UxMODE<15>).
6. Enable the transmission by setting the UTXEN bit (UxSTA<10>), which also sets the UxTXIF bit.
7. 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<1:0> control bits.
8. Load data into 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 UTXBF status bit (UxSTA<9>) is set.
Example 5-1 provides the sample code that sets up the UART for transmission.
Figure 5-3: UARTx Transmission (8-Bit or 9-Bit Data)
Figure 5-4: UARTx 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. Writing data to the UxTXREG should be
done after the UTXEN bit is set.
Character 1
Stop bit
Character 1 to
Transmit Shift Register
Start bit bit 0 bit 1 bit 7/8
Write to UxTXREG
BCLKx/16
(Shift Clock)
UxTX
UxTXIF
TRMT bit
Character 1
UxTXIF Cleared by User in Software
Transmit Shift Register
Write to UxTXREG
BCLKx/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 Register
Character 1 Character 2
bit 0 bit 1 bit 7/8 bit 0
Note: This timing diagram shows two consecutive transmissions.
(UTXISEL<1:0> =
00
)
UxTXIF
(UTXISEL<1:0> =
10
)
UxTXIF Cleared by User in Software

- 1
- 2
…
- 15
- 16
- 17
- 18
- 19
…
- 55
- 56