Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

 

MICROCHIP

User Guide
Card Reader
Demo

gsmskimms@protonmail.com

1  
   
 

Revision History
REV DATE ORIGINATOR DESCRIPTION OF CHANGE

Shilpa Ganganna
0.1 08.03.20 Initial Version
Venkatesh Bengeri

Updated the schematic and BOM section


0.2 09.15.20 Shilpa Ganganna to accommodate the “Device Sleep”
feature.

Updated the user guide to include PIC24F


0.3 10.15.20 Shilpa Ganganna
solution.

2  
   
 

Contents    
 

Revision  History  ......................................................................................................................................  2  


1.   Introduction  ...............................................................................................................................  4  
2.   Card Reader Background  .......................................................................................................  4  
2.1. Data Encoding  ......................................................................................................................  4  
2.2. Data Format  ..........................................................................................................................  4  
3.   Hardware  ..................................................................................................................................  5  
3.1. Operational Amplifiers (Op-amp)  .......................................................................................  5  
3.2. On chip ADC  .........................................................................................................................  5  
3.3. RS-232 Connectivity  ............................................................................................................  5  
4.   Software:  ...................................................................................................................................  5  
4.1. For dsPIC solution  ...............................................................................................................  6  
4.2. For PIC24F solution  .............................................................................................................  8  
5.   Device specifications  ..............................................................................................................  9  
5.1. For dsPIC solution  ...............................................................................................................  9  
5.2. For PIC24F solution  .............................................................................................................  9  
6.   Hardware Requirements  .......................................................................................................  10  
6.1. For dsPIC solution  .............................................................................................................  10  
6.2. For PIC24F solution  ...........................................................................................................  12  
7.   Hardware Connections  .........................................................................................................  14  
7.1. For dsPIC solution  .............................................................................................................  14  
7.2. For PIC24F solution  ...........................................................................................................  14  
8.   Demo Instructions  ..................................................................................................................  15  
9.   Demo Instructions for Card Reader with Software AES-128 Encryption  ......................  18  
I.   APPENDIX A  ..........................................................................................................................  22  
A.   For dsPIC solution:  ............................................................................................................  22  
B.   For PIC24F solution:  .........................................................................................................  24  
II.   APPENDIX  B  ..........................................................................................................................  25  
A.   Steps for programming hex file using MPLABX IDE  ....................................................  25  
   

 
3  
   
 

1. Introduction

With the common use of cards instead of cash, Credit Card Reader (MSR, mag
stripe/swipe readers) are an essential part of any POS system. MSRs can read any card
with magnetic stripes, including some driver's licenses, gift cards, and other IDs.

Magnetic Card Readers (also known as Magnetic Stripe Readers or MSRs) read data
from a 3-track magnetic stripe via a peak detection circuit and process that data for
downstream users. After extracting data from the magnetic stripe, it is converted to
binary data and formatted for encryption. They feed the swiped information to
applications management software and connect through USB, RS-232, or PS/2
connections.

This demonstration shows the Magnetic Stripe Reader using Microchip’s dsPIC and
PIC24F device and displays the card data on the serial terminal.

2. Card Reader Background

2.1. Data Encoding


There are number of different formats used for encoding information on magnetic
stripes. Data encoded on the magnetic stripe using ISO/IEC-7811 standard is known
as "Frequency/double frequency (F2F)" or “Aiken Bi-Phase” encoding. The serial
data encoded is self-clocking. Each bit of data on a track has a fixed physical length
on the magnetic stripe. Bits are encoded serially on the magnetic stripe using a
series of magnetic flux transitions. The presence or absence of an additional peak in
the middle of the bit determines whether it is a ‘1’ or a ‘0’.

Figure 1. Magnetic Stripe Encoding

2.2. Data Format


The data format specified by ISO/IEC-7811 encodes 7-bit (6 bits + parity) characters
on Track 1, and 5-bit (4 bits + parity) decimal characters on Track 2. Track 3 contains
5-bit encoding. Characters are written to the stripe LSB-first, with the parity bit written
last. All tracks contain leading and trailing zeroes at the ends of the stripe to aid the
clock recovery process. When read in the forward direction, a typical track contains
information in the following order:

1. Clocking zeroes
2. A start sentinel character
3. Data characters
4. An end sentinel character
5. A longitudinal redundancy check character
6. Clocking zeroes

4  
   
 

3. Hardware
It includes Op-amp circuitry, power supply and RS-232 connectivity.

3.1. Operational Amplifiers (Op-amp)


In dsPIC solution, Internal OP-amps of the device is used amplify and shift the
signals from Magnetic Read Head such that the signal is read by on chip ADC.

In the case of PIC24F solution, external Op-amps are used to amplify and shift the
signals from Magnetic Read Head such that the signal is read by on chip ADC.

Track outputs from Magnetic Guide Head are connected to the Inverting terminal of
the Op-ampT1, T2 and T3 respectively. Output of Op-amp is connected to the analog
channels of the Microcontroller.

OP-amp circuit connections for tracks 1 is shown in figure 2.

Figure 2: Op-amp connections for Track 1

3.2. On chip ADC


The Op-amp output signals corresponding to Track1, Track2 and Track3 data are
read by Analog-to-digital converter (ADC).

3.3. RS-232 Connectivity


dsPIC solution: Mini-USB port on the demo board can be connected to a PC.

PIC24F solution: External MCP2200 Serial-to-USB converter is used for connecting


PC to demo board.

Note: dsPIC based demo board has integrated MCP2200.

4. Software:
 

An exponential averaging technique is applied to filter the noise prior to the signal
detection algorithm. While the card is swiped, the software algorithm performs the F2F
decoding and stores the time between consecutive peaks into RAM. After a swipe has
finished, the read data is decoded and checked for the errors. Universal asynchronous
receiver/transmitter (UART) is used to transfer the decoded data from the controller to
the PC terminal application.

5  
   
 

The basic flowchart which shows the working of the card reader is shown below:

4.1. For dsPIC solution


dsPIC solution is interrupt based solution. In order to save power, the device is put
into sleep mode. It wakes up during the swipe, decodes the track and prints it on
Serial Terminal and goes back to sleep mode.

main loop

Start

Configure ADC, UART,


TIMERs, Internal OP-
AMPs and comparator

Configure ADC interrupt

No
Is SLP Jumper
P1 connected?

Y
e
s  

Sleep

Wait for
Swipe
Timeout

6  
   
 

ADC_Interrupt routine ()

 
ADC_Interrupt

Capture time between consecutive


peaks for each track

Swipe_Timeout _ISR ()

Timeout_ISR  

Decode the time captured between


peaks to get card data

Display data on HyperTerminal

Reinitialize the modules

Till Swipe
Sleep

7  
   
 

4.2. For PIC24F solution


PIC24F solution is polling based solution. On completing the swipe, the card data is
decoded and printed on Serial Terminal.

Note: A low power feature has not been added. It can be added based on customer
interest/needs.

main loop

 
Start
 
 
 
Configure ADC, UART,
  TIMERs

   

 
Configure 3 external OP-AMPs
  and one external comparator
No
   

 
Wait for
  Swipe
Timeout
 

8  
   
 

Swipe_Timeout ()

Timeout  
 

 
Decode the time captured between
  peaks to get card data

  Display data on HyperTerminal

 
Reinitialize the modules
 

 
main
 

5. Device specifications

5.1. For dsPIC solution


 
1. dsPIC device having:
• 3 internal OP-AMPs (one for each track) and one optional Comparator (for
wake-up from sleep).
• 10K of RAM
• 18K of Program memory.
2. Peripherals used:
• Internal OP-AMPs and comparator.
• ADC: Sampling speed 833.333 KSPS.
• Timers: Four 16-bit timers.
• UART

5.2. For PIC24F solution


 
1. Uses PIC24F device having:
• 8K of RAM
• 12K of Program memory.

2. Peripherals used:
• ADC: Sampling speed 400 KSPS.
• Timers: Two 16-bit timers.
• UART
• INT0: External Interrupt for wakeup from sleep.
9  
   
 

3. Uses 3 external op-amps (MCP6144) (one for each track).

6. Hardware Requirements

6.1. For dsPIC solution


   

1. Magnetic Swipe reader board. The device needs to be programmed with


supported hex file. Please refer APPENDIX section for Steps for programming
the hex file using MPLABX IDE.

4
6

Figure 3. Card Reader Board for dsPIC

2. USB Connector

Connector J1 allows the card reader board to be connected to serial


terminal on PC. It connects via USB to serial terminal.

10  
   
 

3. Card Reader Guide

Card Reader Guide has magnetic sensor inside it which reads track data
during swipe. During the swipe, make sure the Card stripe is in-line with
the magnetic sensor.

4. Debug port

Six-pin interface is provided for connection of PICkit 3 Programmer for


programming and debugging.

5. Jumpers for RX and TX lines

Jumpers on P2 should be connected to enable the display of card data on


PC terminal.

6. Jumper P1 for enabling Sleep

Jumper connected to P1 enables the device sleep mode.

7. Mini USB cable.

8. ISO/IEC-7811 standard cards.

11  
   
 

6.2. For PIC24F solution


 

1. Magnetic Swipe reader board. The device needs to be programmed with


supported hex file. Please refer APPENDIX section for Steps for
programming the hex file using MPLABX IDE.

4
2

Figure 4. Card Reader Board for PIC24F

2. DB9 Connector for MCP2200 (serial to USB converter)

3. Card Reader Guide

During the swipe, make sure the Card stripe is in-line with the magnetic
sensor.

4. Debug port

RJ11 connector J3 is provided as debug port to support programming and


debugging.

12  
   
 

5. MCP2200 Serial to USB converter

6. Mini USB cable.

7. ISO/IEC-7811 standard cards.

13  
   
 

7. Hardware Connections

7.1. For dsPIC solution


 

1. Connect the mini USB cable to Magnetic card reader board. Power LED turns
ON indicating board is powered-up.

If the jumper is connected to P1, the device will enter into sleep mode once
powered-up and it is indicated by the LED LD1. On swipe, the device will
wake-up from sleep and displays the card data on the terminal.

Power LED ON

Mini USB Cable

LED ON to
indicate device
is in sleep

                                 

2. Connect the other end of USB cable to PC.


Note: Power to the board is derived from USB.

7.2. For PIC24F solution

1. Connect the MCP2200 Serial to USB converter from PC to the board as


shown in the figure below.

2. Power-up the board using 9V power supply as shown in figure below. Power
LED turns ON indicating board is powered-up.

14  
   
  Power LED ON

9V Power Supply

MCP2200 Serial to
USB Converter

8. Demo Instructions
1. Configure the serial terminal for 38400 baud rate. On asserting MCLR button, the
following message will appear on serial terminal.

15  
   
 

2. Hold the card as shown below and then swipe. Make sure
• Card stripe is in-line with the magnetic head of the guide.
• Card is not tilted during the swipe.
• Do not stop or hold the card in-between during the swipe.

3. Card data will be displayed on the HyperTerminal.

16  
   
 

4. If error is detecting during the swipe, then following error messages will be
displayed..

i) If Track 3 is not present on the card, error message will be displayed as


“TRACK_IS_NOT_PRESENT_OR_INVALID_TRACK” as shown below.

ii) If the card is not swiped properly or if card is tilted while swiping, card data will
not be read correctly and the error message will be displayed as
“CARD_NOT_READ_PROPERLY” for each of the tracks which are not correctly
read.

17  
   
 

9. Demo Instructions for Card Reader with Software AES-128 Encryption


 

1. AES-128 encryption is used to encrypt the card data. For more information on AES

2. Configuring the AES key: Configure the serial terminal for 38400 baud rate. On

asserting MCLR button, the following message will appear on the serial terminal.

Option “Y” for entering new key and option “N” for using default key.

3. On entering “N” option, the default key will be used for encryption and the key used
for encryption will be displayed on the terminal.

18  
   
 

4. If ‘Y’ is pressed, the user is allowed to enter the 128-bit (16 bytes in hexa decimal
format) key to be used for encryption.
The key entered by the user will be displayed on the screen. After 128-bit key is
entered, the cursor will move to the next line displaying the demo message.

19  
   
 

5. Demo software looks for complete 128 bit key (16 bytes). If the line feed option is
entered accidently then following message (“Enter remaining key”) is prompted on
serial terminal.

6. Once the full key is entered, the default message will be displayed as shown below.

20  
   
 

7. Swipe the card. The AES key used for encryption, track data and encrypted data of
each track will be displayed as below.

21  
   
 

I. APPENDIX A
 

A. For dsPIC solution:

a. Schematic of the Card Reader board VER_0.3:

b. Bill of Materials for Card Reader board VER_0.3:

                               Comment Description Designator Footprint Quantity


0.1UF CAP CER 0.1UF 25V 10% C1, C9, CAP-0805 5
X7R 0805 C25,C26, C27
0.47UF CAP CER 0.47UF 25V 10%
X7R 0603 C6, C7, C8, CAP-0603 3
10uF Polarized Capacitor (Radial) C2 CAP2917(7343) 1
0.1UF CAP CER 0.1UF 25V 10% C3 C1206 1
X7R 0805
10uF CAP TANT 20UF 16V 10% C4 CAP_TANT_C 1
2413-C
CAP-0603,0.1UF CAP CER 0.1UF 25V 10% C5, C10, C11, CAP0603 8
X7R 0603 C12, C13,
C14, C20, C22
18PF 50V CAP CER 18PF 50V 5% C0G C15, C16, CAP0603 4
0603 C23, C24
4.7uF CAP TANT 4.7UF 16V 10% C21,C28 CAP2917(7343) 2
2413-C
470nF Capacitor (Semiconductor SIM C29 CAP0603 1
Model)
440478-2 USB 2.0, Right Angle, SMT, A J1 440478 1
Type, Receptacle, 5 Position,
Black

22  
   
 

HDR_1x8_146 HDR_1x8_146 J2 MC-Reader 6Pin 1


6pin_Jack_18 CONN MOD JACK 6-6 RT/A J9 HDR1X5H 1
PCB 50AU
LED3 LED GREEN CLEAR 0805 LD1, LED-0805 Green 4
SMD LD2,LD3,LD4
Header 2 Header, 2-Pin P1 HDR1X2 1
Header 2X2 Header, 2-Pin, Dual row P2 HDR2X2 1
4.7K RES 4.7K OHM 1/10W 5% R1, R2, R16, RES0603 5
0603 SMD, R18, R39
1K RES 1.0K OHM 1/10W 5% R3, R7, R11, RES0603 8
0603 SMD R22, R26,'R32,
R33, R38
20K RES 20K OHM 1/10W .1% R4, R8, R12, RES0603 5
0603 SMD R21, R25
10K RES 10K OHM 1/10W .1% R5, R9, R13, RES0603 6
0603 SMD R23, R27,R30
215E RES 215 OHM 1/10W 1% R6, R10, R14, RES0603 4
0603 SMD R24, R28
5.6K RES 5.6K OHM 1/10W 1% R28 RES0603 1
0603 SMD
0E Resistor R15 RES 0603 1
100E Resistor, RES 100 OHM R17, R19,R34, RES0603 6
1/10W 5% 0603 SMD R35, R36, R37
470E Resistor R31 Res 0603 1
SW_PB_107 SWITCH TACTILE SPST-NO SW1, SW2 B3F1000 2
0.05A 12V, SW_PB_107
TP_30_mils_72 TP_30_mils_72 TP8 TP125R63 TP 1
BLK
TP_30_mils_72 TP_30_mils_72 TP9 TP125R63 TP 1
RED
LM1117IMPX-3.3/NOPB 800mA Low-Dropout Linear U1 SOT223-4N 1
Regulator, 4-pin SOT-223, Pb-
Free
dsPIC33EPXXXGM304/604 U2 TQFP44_N 1

600 nA, Non-Unity Gain Rail- U4 SOIC-SN8_N 1


to-Rail Input/Output
MCP6142-E/SN Operational Amplifier, 8-Pin
SOIC, Extended Temperature
MCP2200 SSOP U5 SSOP-SS20_M 1
Standard Usb to Mini Usb 5 Mini USB cable 1
Pin Data Sync Cable
ECS-110-S-5P_113 CRYSTAL 12MHZ 18PF Y2, Y3 ECS-110-S-5P 2
THRU

23  
   
 

B. For PIC24F solution:

a. Schematic of the Card Reader board VER_0.1:

b. Bill of Materials for Card Reader board VER_0.1:

Comment Description Designator Footprint Quantity

C1,C3,C5, C11, C12, C13,


0.1uF Capacitor C20, C22, C23, C24, C26 CAP-0805 11
100uF,25V CAP_SMT_D C2,C4 CAP TANT 2
Polarized Capacitor
10uF (Radial) C6 CAP2917 1
Capacitor
(Semiconductor SIM
0.1uF Model) C7, C14, C25 CAP0603 3
C8, C9, C10, C15, C16,
1uF,16V CAP_1206_78 C17, C18 CAP-0805 7
1nF CAP 2.5XR6.3 C19 CAP-0805 1
Polarized Capacitor
4.7uF (Radial) C21 CAP2917 1
DIODE-600 DIODE-600 D1 DIODE-0.6 1
PWR_Jack-
Power Jack DJ005B J1 2.5mm 1
HDR_1x8_146 HDR_1x8_146 J2 MC-Reader 1
DB9_RA_FM_77 DB9_RA_FM_77 J3 DB9-F 1
6pin_Jack_18 6pin_Jack_18 J9 Conn-RJ11 1
LED-0805
LED3 Typical BLUE SiC LED LD1, LD2 Green 2
P1, P4, P5, P10, P13, P19,
P20, P21, P22, P23, P24,
TP1_145 TP1_145 P27, P32, P35, P36, P37, TP1 23
24  
   
 

P38, P41, P42, P43, P44,


TP1, TP3
4.7K Resistor R1, R17, R18, R19 RES0603 4
100R Resistor R2, R16 RES0603 2
20K Resistor R3, R7, R11 RES0603 3
1K Resistor R4, R8, R12 RES0603 3
10K Resistor R5, R9, R13 RES0603 3
215R Resistor R6, R10, R14 RES0603 3
10R Resistor R15 RES0603 1
Switch SW_PB_107 SW1, SW2 B3F1000 2
TP125R63
TP-125R63 TP-125R63 T1, T2, T3, TP4, TP6 TP BLK 5
TP1_229 TP1_229 TP2 TP1 1
TP125R63
TP-125R63 TP-125R63 TP5 TP RED 1
LM1117IMPX- 800mA Low-Dropout
3.3/NOPB Linear Regulator, 4-pin
SOT-223, Pb-Free SOT223-
U1 4N 1
PIV24FJXXXGB204
44Pin U2 TQFP44_N 1
MAX3232D MAX3232D
(SO16)_75 MAX3232D (SO16)_75 U3 (SO16) 1
600 nA, Non-Unity Gain
Rail-to-Rail Input/output
Operational Amplifier, SOIC-
MCP6144-E/SL 14-Pin SOIC, U4 SL14_N 1
32.768KHz Crystal Crystal 32.768 KHz Y1 R38 1
CRYSTAL 12MHZ 18PF ECS-110-
12MHz Crystal THRU Y2 S-5P 1

II. APPENDIX  B  
 

A. Steps for programming hex file using MPLABX IDE


 

1. Open MPLABX IDE installed in the system.

2. Select the hex file to be loaded on controller.

File -> Import -> Hex/ELF…(Prebuilt) File

25  
   
 

3. A dialog box will be opened as shown below:

Browse the hex file to be loaded. Select the device and family of the
microcontroller. Also select the debugger/programmer to be used for
programming.

Click Next and then Finish.

26  
   
 

 
27  
   
 

X2-Software.zip
EMV Writer Reader Software v8.6.zip
X2 certified software.zip
EMV Writer Reader Software v8.zip
EMV Reader Writer.rar
X1-ATR.zip

upon purchasing software please


have us contacted at
gsmskimms@protonmail.com

28  
   

You might also like