Professional Documents
Culture Documents
Smart Card Communication Using PIC® MCUs PDF
Smart Card Communication Using PIC® MCUs PDF
RAM
(Working Memory)
VCC
Ground
Reset
Input/Output
ROM
(Operating System)
The interfacing device (such as a PIC® microcontroller) After the ten bits of information, there is a Stop bit. If
controls the CLK, RST and VCC signals given to the there is any error in the reception of the data, then the
smart card. receiving device has to pull the I/O line low before the
Based on the nominal supply voltage provided by the middle of the Stop bit (i.e.,10.5-bit time from start edge).
interfacing device through VCC, the smart card can be The receiver pulls the line low for 1 to 2 ETU. Elementary
classified into three types: Time Unit (ETU) is one bit time on the I/O line.
• Class A – 4.5V ≤ VCC ≤ 5.5V at ICC ≤ 60 mA The transmitter checks the I/O line at the end of the
Stop bit (11 ETU). If the transmitter detects the line as
• Class B – 2.70V ≤ VCC ≤ 3.3V at ICC ≤ 50 mA
low, it retransmits the previous data byte after at least 2
• Class C – 1.62V ≤ VCC ≤ 1.98V at ICC ≤ 30 mA ETU. The UART peripheral in the PIC microcontrollers
Each byte transfer in the smart card communication on sets the Receiver Ready and Transmitter Empty flags
the I/O line consists of ten bits as shown in Figure 4. to true at 0.5 Stop bit. This allows the implementation of
The first bit of a character is a Start bit, which is always the ISO 7816-3 error detection and the possible
low. Preceding the Start bit, the I/O line is kept in its retransmission protocol using the PIC microcontrollers.
default high state. The Start bit is followed by a 8-bit
Note: For more information on electrical
data byte. The last bit of the character is the parity bit,
characteristics of the smart card, refer to
which is either high or low as determined by the source.
the ISO 7816-3 document.
1 ETU
Parity error during byte transfer
START B0 B1 B2 B3 B4 B5 B6 B7 PARITY B0 B1 B2
When Parity error detected, the receiver brings the I/O line is
I/O Line Low at 10.5 ETU held low
for 1 to 2
ETU
Interfacing
Smart Card
Device
CLA INS P1 P2 P3
Procedure
Byte
DATA
Status BYTES
SW1 SW2
Interfacing
Smart Card
Device
CLA INS P1 P2 P3
Procedure
Byte
DATA
Status BYTES
SW1 SW2
There are two status bytes: SW1 and SW2. These T = 1 Protocol
bytes are sent from the smart card to the interface
device on completion of the APDU command to The T = 1 protocol is a block oriented protocol, which
indicate the status of the current card. The normal means that one block is the smallest data unit that can
response is: be transmitted between the smart card and the
interfacing device.
• SW1 = 0x90
There are three types of blocks in T = 1 protocol:
• SW2 = 0x00
• Information Blocks (I-blocks) – They are used to
The card reports the error condition by transmitting
exchange the application layer data.
SW1 = 6X or 9X (where ‘X’ has any value from 1 to F).
ISO 7816-3 defines five such error conditions: • Receive Ready Blocks (R-blocks) – They are used
to convey a positive or negative acknowledgment.
• SW1:
• Supervisory Blocks (S-blocks) – They are used to
- 6E – Card does not support instruction class exchange control information between the
- 6D – Invalid INS code interfacing device and the card.
- 6B – Incorrect reference The three fields involved in the block frames are:
- 67 – Incorrect length
• Prologue field
- 6F – No particular diagnosis
• Information field
The T = 0 protocol also includes an error detection and • Epilogue field
correction mechanism. After detecting the parity error,
the receiver pulls the I/O line to low logic level for a Table 5 lists the block frame fields of T = 1 protocol.
minimum of 1 ETU and maximum of 2 ETU in the
middle of the Stop bit transmission (10.5 ± 0.2 ETU).
The transmitter checks for this condition and
retransmits the corrupt character.
CGT ≤ t ≤ CWT
BGT ≤ t ≤ BWT
VCC
C4
1μF
C5 1 U1
19 16
RA0/D+/PGD VDD RC0/AN4/C12IN+/INT0/VREF+
10nF 18 15
C2 RA1/D-/PGC RC1/AN5/C12IN1-/INT1/VREF-
4 14
RA3/MCLR/VPP RC2/AN6/P1D/C12IN2-/CVREF/INT2
3 7
RA4/AN3/OSC2/CLKO RC3/AN7/P1C/C12IN3-/PGM
2 6
RA5/OSC1/CLKI RC4/P1B/C12OUT/SRQ
22pF
RC5/CCP1/P1A/T0CKI
5 C6
X1 13
RB4/AN10/SDI/SDA RC6/AN8/SS/T13CKI/T1OSI
8 47nF
12MHz 12 9
C3 RB5/AN11/RX/DT RC7/AN9/SDO/T1OSO
11
RB6/SCK/SCL
10 17
RB7/TX/CK VSS VUSB
22pF C1
20 PIC18F14K50
470nF
J2
1
VCC
2
RST
3
CLK
4
5
GND
6
7
I/O
8
UART_RX
R6
4k7
9
10
Start
Is Smart Card No
inserted in the slot?
Yes
Do Cold Reset
Is Answer to Reset No
successful?
Yes
Does card No
support PPS?
Yes
Do PPS
Stop
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
ISBN: 978-1-60932-957-0
02/18/11