28
MICROCHIP User Guide Card Reader Demo 1

Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

  • Upload
    buihanh

  • View
    212

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

MICROCHIP

User GuideCard Reader

Demo

1

Page 2: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

Revision HistoryREV DATE ORIGINATOR DESCRIPTION OF CHANGE

0.1 08.03.15Shilpa Ganganna

Venkatesh BengeriInitial Version

Contents

2

Page 3: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

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

5. Device specifications..............................................................................................................7

6. Hardware Requirements........................................................................................................8

7. Hardware Connections.........................................................................................................10

8. Demo Instructions.................................................................................................................11

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

I. APPENDIX A.........................................................................................................................18

A. Schematic of the Card Reader board VER_0.3:...........................................................18

B. Bill of Materials for Card Reader board VER_0.3:........................................................19

II. APPENDIX B.........................................................................................................................20

A. Steps for programming hex file using MPLABX IDE....................................................20

1. Introduction

3

Page 4: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

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 device and displays the card data on the serial terminal.

2. Card Reader Background

2.1. Data EncodingThere 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 FormatThe 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 zeroes2. A start sentinel character3. Data characters4. An end sentinel character5. A longitudinal redundancy check character6. Clocking zeroes

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

4

Page 5: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

3.1. Operational Amplifiers (Op-amp)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.

Track outputs from Read 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 ADCThe Op-amp output signals corresponding to Track1, Track2 and Track3 data are connected to Analog-to-digital converter (ADC) channels on the dsPIC device.

3.3. RS-232 ConnectivityThe port can be connected to a PC using a straight-through cable.

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.

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

main loop5

Page 6: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

ADC_Interrupt routine ()

6ADC_Interrupt

Capture time between consecutive peaks for each track

Start

Configure ADC, UART, TIMERs, Internal OP-AMPs and comparator

Configure ADC interrupt

Is SLP Jumper P1 connected?

Sleep

Yes

Wait for Swipe

Timeout

No

Page 7: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

Swipe_Timeout _ISR ()

Till swipe

5. Device specifications

1. Uses dsPIC device having: 3 internal OP-AMPs 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

6. Hardware Requirements

7

Capture time between consecutive peaks for each track

Reinitialize the modules

Timeout_ISR

Sleep

Display data on HyperTerminal

Decode the time captured between peaks to get card data

Page 8: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

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.

Figure 3. Card Reader Board

1. USB Connector Connector J1 allows the card reader board to be connected to serial terminal on PC. It connects via USB to serial terminal.

2. Card Reader GuideCard 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.

3. Debug portSix-pin interface is provided for connection of PICkit 3 Programmer for programming and debugging.

4. Jumpers for RX and TX linesJumpers on P2 should be connected to enable the display of card data on PC terminal.

8

4

53

1

2

Page 9: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

5. Jumper P1 for enabling SleepJumper connected to P1 enables the device sleep mode.

2. Mini USB cable.

3. ISO/IEC-7811 standard cards.

7. Hardware Connections1. Connect the mini USB cable to Magnetic card reader board. Led turns on.

9

Page 10: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

2. Connect the other end of USB cable to PC. Note: Power to the board is derived from USB.

8. Demo Instructions1. Configure the hyper terminal for 38400 baud rate. On asserting MCLR button, the

following message will appear on the HyperTerminal.

10

Mini USB Cable

LED ON

Page 11: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

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.

3. Card data will be displayed on the HyperTerminal.

11

Page 12: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

4. The following error messages will be displayed in card reader demo.

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.

12

Page 13: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

13

Page 14: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

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

1. AES-128 encryption is used to encrypt the card data.

2. Configuring the AES key: Configure the hyper terminal for 38400 baud rate. On asserting MCLR button, the following message will appear on the HyperTerminal. The user has to enter ‘Y’ if the new key has to be used for encryption and ‘N’ if the default key has to be used for encryption.

3. If ‘N’ is pressed, the default key will be used for encryption and the key used for encryption will be displayed on the terminal.

14

Page 15: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

4. If ‘Y’ is pressed, the user is allowed to enter the 128-bit 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.

5. If user does not enter the full 128-bit key and if he press enter before that, the message will be displayed as “Enter remaining key” until the full key is entered.

15

Page 16: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

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

16

Page 17: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

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

17

Page 18: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

I. APPENDIX A

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

18

Page 19: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

19

Page 20: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

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

Comment Description Designator Footprint QuantityCAP-0805 CAP CER 0.1UF 25V 10%

X7R 0805,C1, C6, C7, C8, C9, C25,C26, C27

CAP-0805 8

10uF Polarized Capacitor (Radial) C2 CAP2917(7343) 1CAP-0805 CAP CER 0.1UF 25V 10%

X7R 0805C3 C1206 1

10uF CAP TANT 20UF 16V 10% 2413-C

C4 CAP_TANT_C 1

CAP-0603 CAP CER 0.1UF 25V 10% X7R 0603

C5, C10, C11, C12, C13, C14, C20, C22

CAP0603 8

18PF 50V CAP CER 18PF 50V 5% C0G 0603

C15, C16, C23, C24

CAP0603 4

4.7uF CAP TANT 4.7UF 16V 10% 2413-C

C21,C28 CAP2917(7343) 2

470nF Capacitor (Semiconductor SIM Model)

C29 CAP0603 1

440478-2 USB 2.0, Right Angle, SMT, A Type, Receptacle, 5 Position, Black

J1 440478 1

HDR_1x8_146 HDR_1x8_146 J2 MC-Reader 6Pin 16pin_Jack_18 CONN MOD JACK 6-6 RT/A

PCB 50AUJ9 HDR1X5H 1

LED3 LED GREEN CLEAR 0805 SMD

LD1, LD2,LD3,LD4

LED-0805 Green 4

Header 2 Header, 2-Pin P1 HDR1X2 1Header 2X2 Header, 2-Pin, Dual row P2 HDR2X2 14.7K RES 4.7K OHM 1/10W 5%

0603 SMD,R1, R2, R16, R18, R39

RES0603 5

1K RES 1.0K OHM 1/10W 5% 0603 SMD

R3, R7, R11, R22, R26,'R32, R33, R38

RES0603 8

20K RES 20K OHM 1/10W .1% 0603 SMD

R4, R8, R12, R21, R25

RES0603 5

10K RES 10K OHM 1/10W .1% 0603 SMD

R5, R9, R13, R23, R27,R30

RES0603 6

215E RES 215 OHM 1/10W 1% 0603 SMD

R6, R10, R14, R24, R28

RES0603 5

0E Resistor R15 Res 0603 1100E Resistor, RES 100 OHM

1/10W 5% 0603 SMDR17, R19,R34, R35, R36, R37

RES0603 6

470E Resistor R31 Res 0603 1SW_PB_107 SWITCH TACTILE SPST-NO

0.05A 12V, SW_PB_107SW1, SW2 B3F1000 2

TP_30_mils_72 TP_30_mils_72 TP8 TP125R63 TP BLK

1

TP_30_mils_72 TP_30_mils_72 TP9 TP125R63 TP RED

1

LM1117IMPX-3.3/NOPB 800mA Low-Dropout Linear Regulator, 4-pin SOT-223, Pb-Free

U1 SOT223-4N 1

dsPIC33EPXXXGM304/604 U2 TQFP44_N 1

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

Page 21: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

MCP6142-E/SNto-Rail Input/Output Operational Amplifier, 8-Pin SOIC, Extended Temperature

MCP2200 SSOP U5 SSOP-SS20_M 1Standard Usb to Mini Usb 5 Pin Data Sync Cable

Mini USB cable 1

ECS-110-S-5P_113 CRYSTAL 12MHZ 18PF THRU

Y2, Y3 ECS-110-S-5P 2

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

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.

21

Page 22: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

22

Page 23: Introductionww1.microchip.com/downloads/en/DeviceDoc/Magnetic Card... · Web viewRevision History2 1.Introduction4 2.Card Reader Background4 2.1. Data Encoding4 2.2. Data Format4

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 .

23