14.3.6 Transmitting and Receiving Data
Initialization: Before transmitting or receiving data, initialize the smart card interface by the
procedure below. Initialization is also necessary when switching from transmit mode to receive
mode or from receive mode to transmit mode.
1.
Clear the TE and RE bits to 0 in the serial control register (SCR).
2.
Clear the ERS, PER, and ORER error flags to 0 in the serial status register (SSR).
3.
Set the parity mode bit (O/
E
) and baud rate generator clock source select bits (CKS1 and
CKS0) as required in the serial mode register (SMR). At the same time, clear the C/
A
, CHR,
and MP bits to 0, and set the STOP and PE bits to 1.
4.
Set the SMIF, SDIR, and SINV bits as required in the smart card mode register (SMR). When
the SMIF bit is set to 1, the TxD
0
and RxD
0
pins switch from their I/O port functions to their
serial communication interface functions, and are placed in the high-impedance state.
5.
Set a value corresponding to the desired bit rate in the bit rate register (BRR).
6.
Set clock enable bit 0 (CKE0) as required in the serial control register (SCR). Write 0 in the
TIE, RIE, TE, RE, MPIE, TEIE, and CKE1 bits. If bit CKE0 is set to 1, a serial clock will be
output from the SCK
0
pin.
7.
Wait for at least the interval required to transmit or receive one bit, then set the TIE, RIE, TE,
and RE bits as necessary in SCR. Do not set TE and RE both to 1, except when performing a
loop-back test.
Transmitting Serial Data: The transmitting procedure in smart card mode is different from the
normal SCI procedure, because of the need to sample the error signal and retransmit. Figure 14-4
shows a flowchart for transmitting, and figure 14-5 shows the relation between a transmit
operation and the internal registers.
1.
Initialize the smart card interface by the procedure given above in Initialization.
2.
Check that the ERS error flag is cleared to 0 in SSR.
3.
Check that the TEND flag is set to 1 in SSR. Repeat steps 2 and 3 until this check passes.
4.
Write transmit data in TDR and clear the TDRE flag to 0. The data will be transmitted and the
TEND flag will be cleared to 0.
5.
To continue transmitting data, return to step 2.
6.
To terminate transmission, clear the TE bit to 0.
This procedure may include interrupt handling and DMA transfer.
If the TIE bit is set to 1 to enable interrupt requests, when transmission is completed and the
512
www.DataSheet4U.com