Magnetic Card Reader User Guide

 MICROCHIP
User Guide
Card Reader
Demo
1 Revision History
REV
DATE
ORIGINATOR
DESCRIPTION OF CHANGE
Shilpa Ganganna
0.1
08.03.15
Initial Version
Venkatesh Bengeri
0.2
09.15.15
Shilpa Ganganna
Updated the schematic and BOM section
to accommodate the “Device Sleep”
feature.
0.3
10.15.15
Shilpa Ganganna
Updated the user guide to include PIC24F
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.
2.
3.
4.
5.
6.
Clocking zeroes
A start sentinel character
Data characters
An end sentinel character
A longitudinal redundancy check character
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 OPAMPs 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.
2.
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.
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.
3
4
6
5
2
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.
3
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
software library please refer to
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680
&dDocName=en537998
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%
X7R 0805
CAP CER 0.47UF 25V 10%
X7R 0603
Polarized Capacitor (Radial)
C1, C9,
C25,C26, C27
CAP-0805
5
C6, C7, C8,
C2
CAP-0603
CAP2917(7343)
3
1
CAP CER 0.1UF 25V 10%
X7R 0805
CAP TANT 20UF 16V 10%
2413-C
CAP CER 0.1UF 25V 10%
X7R 0603
C3
C1206
1
C4
CAP_TANT_C
1
C5, C10, C11,
C12, C13,
C14, C20, C22
C15, C16,
C23, C24
C21,C28
CAP0603
8
CAP0603
4
CAP2917(7343)
2
C29
CAP0603
1
J1
440478
1
0.47UF
10uF
0.1UF
10uF
CAP-0603,0.1UF
18PF 50V
CAP CER 18PF 50V 5% C0G
0603
CAP TANT 4.7UF 16V 10%
2413-C
Capacitor (Semiconductor SIM
Model)
USB 2.0, Right Angle, SMT, A
Type, Receptacle, 5 Position,
Black
4.7uF
470nF
440478-2
22 HDR_1x8_146
HDR_1x8_146
J2
MC-Reader 6Pin
1
6pin_Jack_18
J9
HDR1X5H
1
LD1,
LD2,LD3,LD4
P1
LED-0805 Green
4
Header 2
CONN MOD JACK 6-6 RT/A
PCB 50AU
LED GREEN CLEAR 0805
SMD
Header, 2-Pin
HDR1X2
1
Header 2X2
Header, 2-Pin, Dual row
P2
HDR2X2
1
4.7K
RES 4.7K OHM 1/10W 5%
0603 SMD,
RES 1.0K OHM 1/10W 5%
0603 SMD
R1, R2, R16,
R18, R39
R3, R7, R11,
R22, R26,'R32,
R33, R38
R4, R8, R12,
R21, R25
R5, R9, R13,
R23, R27,R30
R6, R10, R14,
R24, R28
R28
RES0603
5
RES0603
8
RES0603
5
RES0603
6
RES0603
4
RES0603
1
LED3
1K
20K
RES 20K OHM 1/10W .1%
0603 SMD
RES 10K OHM 1/10W .1%
0603 SMD
RES 215 OHM 1/10W 1%
0603 SMD
RES 5.6K OHM 1/10W 1%
0603 SMD
Resistor
10K
215E
5.6K
0E
R15
RES 0603
1
Resistor, RES 100 OHM
1/10W 5% 0603 SMD
Resistor
R17, R19,R34,
R35, R36, R37
R31
RES0603
6
Res 0603
1
SW1, SW2
B3F1000
2
TP_30_mils_72
SWITCH TACTILE SPST-NO
0.05A 12V, SW_PB_107
TP_30_mils_72
TP8
1
TP_30_mils_72
TP_30_mils_72
TP9
LM1117IMPX-3.3/NOPB
800mA Low-Dropout Linear
Regulator, 4-pin SOT-223, PbFree
U1
TP125R63 TP
BLK
TP125R63 TP
RED
SOT223-4N
U2
TQFP44_N
1
U4
SOIC-SN8_N
1
U5
SSOP-SS20_M
1
100E
470E
SW_PB_107
dsPIC33EPXXXGM304/604
600 nA, Non-Unity Gain Railto-Rail Input/Output
Operational Amplifier, 8-Pin
SOIC, Extended Temperature
MCP6142-E/SN
MCP2200 SSOP
Standard Usb to Mini Usb 5
Pin Data Sync Cable
ECS-110-S-5P_113
1
1
Mini USB cable
CRYSTAL 12MHZ 18PF
THRU
1
Y2, Y3
ECS-110-S-5P
23 2
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
0.1uF
Capacitor
C1,C3,C5, C11, C12, C13,
C20, C22, C23, C24, C26
CAP-0805
11
100uF,25V
C2,C4
CAP TANT
2
C6
CAP2917
1
0.1uF
CAP_SMT_D
Polarized Capacitor
(Radial)
Capacitor
(Semiconductor SIM
Model)
CAP0603
3
1uF,16V
CAP_1206_78
C7, C14, C25
C8, C9, C10, C15, C16,
C17, C18
CAP-0805
7
1nF
C19
CAP-0805
1
4.7uF
CAP 2.5XR6.3
Polarized Capacitor
(Radial)
C21
CAP2917
1
DIODE-600
DIODE-600
D1
1
Power Jack
DJ005B
J1
DIODE-0.6
PWR_Jack2.5mm
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
1
LED3
Typical BLUE SiC LED
TP1_145
TP1_145
LD1, LD2
P1, P4, P5, P10, P13, P19,
P20, P21, P22, P23, P24,
P27, P32, P35, P36, P37,
Conn-RJ11
LED-0805
Green
10uF
1
2
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
2
TP-125R63
TP-125R63
T1, T2, T3, TP4, TP6
B3F1000
TP125R63
TP BLK
TP1_229
TP1_229
TP2
1
TP-125R63
LM1117IMPX3.3/NOPB
TP-125R63
800mA Low-Dropout
Linear Regulator, 4-pin
SOT-223, Pb-Free
TP5
TP1
TP125R63
TP RED
U1
SOT2234N
PIV24FJXXXGB204
44Pin
MAX3232D
(SO16)_75
MCP6144-E/SL
32.768KHz Crystal
12MHz Crystal
II.
U2
MAX3232D (SO16)_75
600 nA, Non-Unity Gain
Rail-to-Rail Input/output
Operational Amplifier,
14-Pin SOIC,
U3
TQFP44_N
MAX3232D
(SO16)
U4
SOICSL14_N
Crystal 32.768 KHz
CRYSTAL 12MHZ 18PF
THRU
Y1
Y2
5
1
1
1
1
1
R38
ECS-110S-5P
1
1
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 4. Program the device by using “Make and Program Device” Option.
5. The video in the below link shows about loading a hex file:
https://www.youtube.com/watch?v=pEMORwwuyos.
28