Getting Started: Smart Card Demo
Configuration
3: Low Pin Count USB Development Kit
Configuration
4: PICDEM FS USB
Configuration
3: PIC18F14K50 + LPC Board
Configuration
4: PICDEM FS USB
To run this project, you will need one of the
following sets of hardware:
High
pin count (HPC) Explorer (DM183022)
SC (Smart/Sim Card) PICTail Board
And
one of the following PIMs
PIC18F87J50
Plug-In-Module (PIM) (MA180021)
PIC18F46J50
Full Speed USB Demo Board (MA180024)
Explorer
16 (DM240001)
SC
(Smart/Sim Card) PICTail Board
And one of the following PIMs
PIC24FJ256GB110 Plug-In-Module (PIM) (MA240014)
Low Pin Count USB Development Kit with PICKit 2
Debugger/Programmer (DV164126)
or without
Debugger/Programmer (DM164127).
SC (Smart/Sim Card) PICTail Board
PICDEM
FS USB (DM163025)
SC (Smart/Sim Card) PICTail Board
This
section describes how to set up the various configurations of hardware to run
this demo.
Configuration 2: PIC24FJ256GB110 PIM + Explorer 16
Configuration 3: PIC18F14K50 + LPC Board
Configuration 4: PICDEM FS USB Board
1)
Before attaching the PIC18F87J50 PIM or PIC18F46J50 PIM to the HPC Explorer
board, insure that the processor selector switch (S3) is in the “ICE” position
as seen in the image below. Failure to
so will result in difficulties in getting the PIC18F87J50/PIC18F46J50 PIM to
sit properly on the HPC Explorer.
2)
Before inserting PIC18F87J50/PIC18F46J50 PIM into the HPC Explorer board,
remove all the attached cables from both the boards. Be careful while inserting
the PIM into HPC board. Insure that no pins are bent or damaged during the
process. Also insure that the PIM is not
shifted in any direction and that all of the headers are properly aligned.
3) Insert the J4 port of SC (Smart/Sim Card)
PICTail Board to the J3
1)
Before attaching the PIM to the Explorer 16 board, insure that the processor
selector switch (S2) is in the “PIM” position as seen in the image below.
2)
Short the J7 jumper to the “PIC24” setting
3)
Be careful while inserting the PIC24FJ256GB110 PIM into Exp 16 board. Insure
that no pins are bent or damaged during the process. Also insure that the PIM is not shifted in
any direction and that all of the headers are properly aligned.
4)
Short JP1 to CLK2 (i.e. RB15) in the SC (Smart/Sim Card) PICTail Board as shown
below:
5) Insert the J2
1)
Make sure that JP1 of SC PICTail card is left open. Make sure that J12 of LPC
board is left open. One side of J4 port pins of the SC (Smart/Sim Card) PICTail
Board match with the J11
1) Short Tx
& Rx line of the UART at J13 port using a wire and connect it to I/O pin of
SC PICTail board.
2) Connect RB6 (of J13 port) to
“Card Present” signal pin of SC PICTail board.
1) If using the PICDEM FS USB Demo Board, no hardware
related configuration or jumper setting changes should be necessary. The demo board need only be programmed with
appropriate firmware.
2) Don’t short the jumper at J11 port.
3) Insert the J2
To
run this project, you will need to load the corresponding firmware into the
devices.
The
source code for this demo is available in the “<Install Directory\Smart Card
Demo” directory. In this directory you
will find all of the user level source and header files, linker file as well as
project file for each of the hardware platforms. Find the project (*.mcp)
file that corresponds to the hardware platform you wish to test. Compile and
program the demo code into the hardware platform. For more help on how to
compile and program projects, please refer to the MPLAB® IDE help available
through the help menu of MPLAB (Help->Topics…->MPLAB IDE).
This demo uses the selected hardware platform as a Smart
card reader. The demo has to be run in the debug mode of MPLAB IDE. Please
refer “Configuring the Hardware” section for the bench setup connections.
Smart Card consists of 8 pins namely:-
I/O: Input or Output for serial data to the integrated circuit inside the card.
VPP: Programming voltage input (optional use by the card).
GND: Ground (reference voltage).
CLK: Clocking or timing signal.
RST: Reset Signal to the Card.
VCC: Power supply input (optional use by the card).
All card sessions consist of the following steps:-
·
Insertion
of the card into the slot; connection and activation of the contact.
·
Reset
of the card; establishment of communication between the reader and the card
(ATR & PPS).
·
Execution
of the transaction(s).
·
Removal
of the card; Deactivation of the contact.
At the current times there are two communication protocols
that are in general use:-
·
T
= 0 asynchronous half duplex character transmission.
·
T
= 1 asynchronous half duplex block transmission.
The data transfers between the card and the terminal happens
on the single wire I/O line. The smart card library supports both T=0 & T=1
protocol.
Example code for T=0 cards:-
The demo executes the card commands namely SUBMIT CODE,
SELECT FILE, READ RECORD & WRITE RECORD. The command list can be extended
further as per the project requirement.
Example code for T=1 cards:-
The demo executes the "Get CPLC (Card Production Life Cycle)
data" command for T=1 java card. The command list can be extended further
as per the smart card manual and the project requirement.
The demo uses the signal connections between the smart card
& PIC micro port pins as per the below table:-
S.No |
Signal Name |
PIC18F46J50 |
PIC18F87J50 |
PIC18F4550 |
PIC18F14K50 |
PIC24FJ256GB110 |
1 |
SIM_CARD_DET |
RB1 |
RB1 |
RB1 |
RB4 |
RB1 [RP1] |
2 |
SMART_CLK |
RB2 |
RC2 |
RC2 |
RC2 |
RB15 [RP29] |
3 |
SMART_I/O |
RC6,RC7 |
RC6,RC7 |
RC6,RC7 |
RB7,RB5 |
RC4 [RPI41], RF2 [RP30] |
4 |
SMART_RST |
RB4 |
RB4 |
RB4 |
RC1 |
RE8 [RPI33] |
5 |
SMART_CARD_DET |
RB3 |
RB3 |
RB3 |
RB6 |
RB0 |
6 |
SMART_VCC |
RB0 |
RB0 |
RB0 |
RC0 |
RB9 [RP9] |
SMART_CARD_DET/SIM_CARD_DET signals indicate the presence of
Smart Card/Sim Card to the microcontroller. Either of one between Smart Card
& Sim Card has to be inserted in the Smart Card PICTail board. If both the
cards are inserted at a time in the PICTail card, then the demo won’t work
successfully.
If the user wants to connect the smart card signals to
different port pins of the micro, then he or she needs to modify the pin
mapping in “sc_config.h” file.
The demo
waits in the while(1) loop until the smart card is inserted in the smart card
connector slot. Once the card is inserted in the slot, ATR (Answer to Reset)
and PPS (Protocol & Parameter Selection) operations are performed. Then
after the execution of card commands is done as per the smart card manual
provided by the manufacturer. If the user inserts T=0 card in the slot, then
“SC_TransactT0” function is called & the result of the executed command
from the smart card is stored in “apduData”. If the user inserts T=1 card in
the slot, then “SC_TransactT1” function is called & the result of the
executed command from the smart card is stored in “apduData”. Variable
“cardResponse” stores the status codes & the length of the received data
from the smart card.
Note:
After initially being reset by the card reader, the smart card responds with a string
of characters known as the Answer to Reset, or ATR. These characters consist of
an initial character, TS, followed by a maximum of 32 additional characters.
Together, these characters provide information to the card reader about how to
communicate with the card for the remainder of the session. If the card reader
wants to modify any of these data transmission parameters in the smart card,
then it must perform PPS in accordance with ISO/IEC 7816-3 before the
transmission protocol is actually used.
Troubleshooting Tips:
Issue
1: How to get the exact delays for Work Wait time functionality?
Solution: It is advisable to use Timers to generate the exact delays.
The Microchip name and logo, the Microchip logo,
MPLAB, and PIC are registered trademarks of Microchip Technology Incorporated
in the
PICDEM and PICTail are trademarks of Microchip
Technology Incorporated in the
Microsoft, Windows, and Windows Vista are either
registered trademarks or trademarks of Microsoft Corporation in the
SD is a trademark of the SD Association in the
U.S.A and other countries