Transcript
  •  

    1      

    MICROCHIP

    User Guide Card Reader

    Demo

  •  

    2      

    Revision History REV DATE ORIGINATOR DESCRIPTION OF CHANGE

    0.1 08.03.15 Shilpa Ganganna

    Venkatesh Bengeri Initial Version

    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.

  •  

    3      

    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  

       

     

     

     

  •  

    4      

    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

  •  

    5      

    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.

  •  

    6      

    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

    No

    Start

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

    Configure ADC interrupt

    Is SLP Jumper P1 connected?

    Sleep

    Yes  

     

     

     

    Wait for Swipe

    Timeout

     

  •  

    7      

    ADC_Interrupt routine ()

     

    Swipe_Timeout _ISR ()

    Capture time between consecutive peaks for each track

    ADC_Interrupt

    Decode the time captured between peaks to get card data

    Display data on HyperTerminal

    Sleep

    Timeout_ISR  

    Reinitialize the modules

    Till Swipe

  •  

    8      

    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

     

     

    Wait for Swipe

    Timeout

      No

  •  

    9      

    Swipe_Timeout ()

     

     

     

     

     

     

     

     

     

     

    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.

    Decode the time captured between peaks to get card data

    Display data on HyperTerminal

    main

    Timeout  

    Reinitialize the modules

  •  

    10      

    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.

     

    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.

    3

    2

    4 6

    5

  •  

    11      

    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.

  •  

    12      

    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.

    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.

    2

    3

    4

  •  

    13      

    5. MCP2200 Serial to USB converter

     

    6. Mini USB cable.

    7. ISO/IEC-7811 standard cards.

  •  

    14      

    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.

                                     

     

    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.

    Mini USB Cable

    Power LED ON

    LED ON to indicate device

    is in sleep

  •  

    15      

    8. Demo Instructions 1. Configure the serial terminal for 38400 baud rate. On asserting MCLR button, the

    following message will appear on serial terminal.

    Power LED ON

    MCP2200 Serial to USB Converter

    9V Power Supply

  •  

    16      

    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.

     

  •  

    17      

    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.

  •  

    18      

    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.

  •  

    19      

    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.

  •  

    20      

    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.

  •  

    21      

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

  •  

    22      

    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 C1, C9, C25,C26, C27

    CAP-0805 5

    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%

    X7R 0805 C3 C1206 1

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

    C4 CAP_TANT_C 1

    CAP-0603,0.1UF 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

  •  

    23      

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

    PCB 50AU J9 HDR1X5H 1

    LED3 LED GREEN CLEAR 0805 SMD

    LD1, LD2,LD3,LD4

    LED-0805 Green 4

    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%

    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 4

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

    R28 RES0603 1

    0E Resistor R15 RES 0603 1 100E Resistor, RES 100 OHM

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

    RES0603 6

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

    0.05A 12V, SW_PB_107 SW1, 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

    MCP6142-E/SN

    600 nA, Non-Unity Gain Rail-to-Rail Input/Output Operational Amplifier, 8-Pin SOIC, Extended Temperature

    U4 SOIC-SN8_N 1

    MCP2200 SSOP U5 SSOP-SS20_M 1 Standard 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

  •  

    24      

    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 CAP_SMT_D C2,C4 CAP TANT 2

    10uF Polarized Capacitor (Radial) C6 CAP2917 1

    0.1uF

    Capacitor (Semiconductor SIM Model) C7, C14, C25 CAP0603 3

    1uF,16V CAP_1206_78 C8, C9, C10, C15, C16, C17, C18 CAP-0805 7

    1nF CAP 2.5XR6.3 C19 CAP-0805 1

    4.7uF Polarized Capacitor (Radial) C21 CAP2917 1

    DIODE-600 DIODE-600 D1 DIODE-0.6 1

    Power Jack DJ005B J1 PWR_Jack-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

    LED3 Typical BLUE SiC LED LD1, LD2 LED-0805 Green 2

    TP1_145 TP1_145

    P1, P4, P5, P10, P13, P19, P20, P21, P22, P23, P24, P27, P32, P35, P36, P37, TP1 23

  •  

    25      

    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

    TP-125R63 TP-125R63 T1, T2, T3, TP4, TP6 TP125R63 TP BLK 5

    TP1_229 TP1_229 TP2 TP1 1

    TP-125R63 TP-125R63 TP5 TP125R63 TP RED 1

    LM1117IMPX-3.3/NOPB

    800mA Low-Dropout Linear Regulator, 4-pin SOT-223, Pb-Free

    U1 SOT223-4N 1

    PIV24FJXXXGB204 44Pin U2 TQFP44_N 1 MAX3232D (SO16)_75 MAX3232D (SO16)_75 U3

    MAX3232D (SO16) 1

    MCP6144-E/SL

    600 nA, Non-Unity Gain Rail-to-Rail Input/output Operational Amplifier, 14-Pin SOIC, U4

    SOIC-SL14_N 1

    32.768KHz Crystal Crystal 32.768 KHz Y1 R38 1

    12MHz Crystal CRYSTAL 12MHZ 18PF THRU Y2

    ECS-110-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

  •  

    26      

     

    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.

  •  

    27      

     

     

  •  

    28      

    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.


Recommended