# Vault 7: Projects

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

### Protego

# PIC24FJ64GA004 -- UART

- 1
- 2
…
- 47
- 48
- 49
- 50
- 51
…
- 55
- 56

 2009-2013 Microchip Technology Inc. DS70000582E-page 49
UART
15.5.2 POST-Answer-To-Reset (ATR) INITIALIZATION
After the terminal has done a reset of the Smart Card and received the setup parameters
contained in the ATR, the user software can configure the module for communication as follows:
1. Disable the UART for configuration changes by clearing the UARTEN bit.
2. Set the PTRCL (UxSCCON<1>), T0PD (UxSCCON<2>), CONV (UxSCCON<3>) and
TXRPT<1:0> bits (UxSCCON<5:4>) according to ATR parameters.
3. Program the UxBRG register for the ETU defined in ATR.
4. Program the UxGTC register and set GTCIE (UxSCINT<0>).
5. Program UxWTCL/H registers and set WTCIE (UxSCINT<1>).
6. Enable interrupts as described in Section 7.3 “Receive Interrupt”, Section 15.2 “Smart
Card Control Registers” and Section 15.4 “Smart Card Interrupt Configuration”.
7. Clear the URXEN bit.
8. Enable the UART by setting the UARTEN bit.
9. Set the UTXEN bit (UxSTA<10>) to start the first transmission to the Smart Card.
Example 15-2: Smart Card Initialization Code for UART1
15.5.3 T = 0 PROTOCOL COMMUNICATION
Transmission with T = 0:
1. Set URXEN to 0 and UTXEN to 1.
2. Write data into UxTXREG.
3. Take appropriate actions according to the ISO 7816 standard if the WTCIF, GTCIF and/or
TXRPTIF bits are set.
4. Set LAST = 1 (UxTXREG<15>) for the last byte of data.
Reception with T =
0:
1. Set UTXEN to 0 and URXEN to 1.
2. Read the UxRXREG as the data becomes available upon the receive interrupt.
3. Take appropriate actions according to the ISO 7816 standard if the WTCIF, GTCIF and/or
RXRPTIF bits are set.
Note: Only one enable bit (UTXEN or URXEN) can be set at any given time.
// Smart card initialization code example for UART1
U1BRG = 25; // Set bit rate
U1MODEbits.PDSEL = 0x01; // 8 bits, even parity
// Smart card specific register configuration
U1SCCONbits.SCEN = 1; // Enable Smart card mode
U1SCCONbits.PTRCL = 0; // T=0 protocol
U1SCCONbits.T0PD = 0; // 1 ETU pull down duration
U1SCCONbits.CONV = 0; // Direct logic convention
U1SCCONbits.TXRPT = 1; // Retransmit error byte 2 times
U1GTC = 0x0012; // Guard time = 12 ETU
U1WTCL = 0x0022; // Wait time = 22 ETU
U1WTCH = 0x0000;
U1MODEbits.UARTEN = 1; // Enable UART
Note: Due to the TX and RX pins being shorted, a receive interrupt will be generated on
transmission of a character, if enabled. It is recommended to disable receive
interrupts when transmitting.
Note: For the last character, the user must ensure that the guard time is satisfied before
transmitting the response. The GTC may be used for this purpose, whereas the
WTC interrupt may be disabled or ignored.

- 1
- 2
…
- 47
- 48
- 49
- 50
- 51
…
- 55
- 56