Running the Demo

Smart Card Library

Smart Card Library
Running the Demo

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). 

Communication between the interfacing device and smart card is done as per the following steps:-

  1. Insertion of the smart card in the slot.
  2. Detection of the smart card insertion by the microcontroller (interfacing device).
  3. Microcontroller does the cold reset of the smart card.
  4. Answer to Reset (ATR) response by the card.
  5. PPS exchange (if smart card supports it).
  6. Execution of the transaction(s) between the card & the interfacing device.
  7. Removal of the smart card from the slot.
  8. Detection of the smart card removal by the microcontroller.
  9. Deactivation of the contacts.
 

Contact type smart card communication protocols that are generally used are:-

  • 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 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, 'Cold Reset' and 'PPS' (Protocol & Parameter Selection) has to be performed to the smart card running MPLAB project in debug mode. If the user has inserted 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 has inserted 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 the 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. 

For more details about smart card communication using PIC microcontrollers, please refer the application note AN1370

Microchip Smart Card Library 1.02.8 - [July 18, 2012]
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.