Manual · MagTek
MagTek Magnetic Stripe Reader Application Note: Interfacing to a Microprocessor
Manual2 pagesPDF 144 KB
Both pages are below, each with its text.
Filed with · 1 model
Also filed with these models on the old site
From the manual · read page by page
Key facts from this manual
Each line names its page in the PDF.
A two-page Mag-Tek application note on connecting a magnetic stripe card reader to a microprocessor. It names no particular reader model, so it applies to the reader's signals in general. It explains the single-bit and USART methods, signal timing, error checking, finding the Start Sentinel, reading in both directions, and converting card data to ASCII.
- What it is
- Application note on interfacing a Mag-Tek magnetic stripe card reader to a microprocessor unit (MPU) p. 1
- Interface methods
- Single-bit input programming in software, or a USART such as the NEC 82C51 p. 1
- Reader signals
- Card Present, Data and Strobe, all negative true logic p. 2
- Card Present timing
- Goes low after 14-15 head flux reversals; returns high approximately 150mS after the last flux transition p. 2
- Data timing
- Data valid 1.0µS (min.) before the leading negative edge of strobe p. 2
- Data rates at 50 ips
- Track 1: 10,500 bits/sec., 1,500 char/sec.; Track 2: 3,750 bits/sec., 750 char/sec.; Track 3: 10,500 bits/sec., 2,100 char/sec. p. 1
- Track encoding
- Track 1: six data bits plus odd parity per character; Tracks 2 and 3: four data bits plus odd parity p. 2
- USART setup
- Synchronous mode, one sync character equal to the track's Start Sentinel; Track 1 parity on with 6-bit words or off with 7-bit; Tracks 2 and 3 parity off p. 1
- Error checking
- Check the parity of each character and the Longitudinal Redundancy Check (LRC) character p. 1
- ASCII conversion
- Track 1: remove parity and add 20h; Tracks 2 and 3: remove parity and add 30h p. 2
- Leading zeros
- Worst case no more than four leading zeros on track 2 and no more than nine on tracks 1 and 3 p. 2
What this manual walks you through
- Reading card data with single-bit input programming p. 1
- Connecting the reader to a USART p. 1
- Calculating and checking the LRC character p. 1
- Detecting the Start Sentinel reliably on noisy blank tracks p. 2
- Reading cards swiped in either direction p. 2
- Converting between card data and ASCII p. 2
Good to know
- With single-bit input programming the processor must give its full attention to the incoming data while a card is read. p. 1
- Random noise on a blank track, especially high coercivity media, may be read as a Start Sentinel. p. 2
- For reading in both directions a USART cannot identify the Start Sentinel. p. 2
- The LRC character can look like a false Start Sentinel when reading in reverse. p. 2
Questions this manual answers
How do I connect a Mag-Tek card reader to a microprocessor?
The note gives two common ways: single-bit input programming in software, or a USART such as the NEC 82C51. p. 1
Are the Mag-Tek reader's Card Present, Data and Strobe signals active low?
Yes. The note says all three are negative true logic, and Card Present goes low after 14-15 head flux reversals. p. 2
How do I convert track 2 card data to ASCII?
Remove the parity bit from the card data code, then add 30h to the remaining four-bit portion. p. 2
Can a USART read a magnetic card swiped in both directions?
Not by finding the Start Sentinel. The USART must start capturing at the first binary 1, and software then searches the bits both ways. p. 2
The file
Size and text
Every page · 2
Read it here
Each page as it is printed, and its words beside it, so a phone can search and copy them.
Page1of 2
Open in the PDF
The text of page 1, from the PDF itself
Application Note - Magnetic Stripe Reader Interfacing the Card Reader to a Microprocessor The Mag-Tek Card Reader may be interfaced to a microprocessor unit (MPU) in a number of ways. Selection of the most suitable method will depend on the system requirements and the MPU capabilities. The two most common methods are: 1. Single-bit input programming. 2. USART (Universal Synchronous/Asynchronous Receiver - Transmitter such as NEC 82C51).
Single - Bit Input Programming This method of interface does not require any external chip to implement serial data communication between the Card Reader and an MPU. This function is done through a software program that allows the MPU to transmit and receive data. This process requires some very time-critical programming. A disadvantage of this approach is that, while the processor is receiving data serially, it must totally dedicate itself to the task. Accurate timing can only be maintained if the program remains in a tight wait loop without being diverted to other functions. When programming the MPU, the timing loops required for receiving data cannot exceed the time period of the incoming data bits. Table 1 shows the data rates at card speed of 50 inches per second (ips). TK1 Bit Rate (bits/sec.) 10,500 Character Rate (char/sec.) 1,500 Table 1 data rates @ 50ips
TK2 3,750 750
TK3 10,500 2,100
USART The primary advantage of the USART method is that the MPU is relieved of the critical time-dependent programming. The CARD PRESENT signal can be connected to an input pin on the USART. The DSR input of the USART is suggested as an input of the CARD PRESENT signal to the MPU. The serial data input (RXD) of the USART receives data from the Card Reader. The clock input (RXC) of the USART is connected to the read STROBE output of the Card Reader. The USART must be set up to operate in the synchronous mode with a single sync character. This sync character must be equivalent to the Start Sentinel character of the track that is being read. When reading Track 1, the user may set the parity on the USART to ON or OFF. If parity is set to Enabled, then the word size must be set to 6 bits. In this case the USART checks the character for parity error. If the user
prefers the parity to be checked by the MPU and not the USART then parity must be set to Disabled and word size must be set to 7 bits. When reading Track 2 or Track 3, parity must be set to OFF. This is because data characters encoded on these two tracks are in 5 bit words, including parity. The USART is limited to a minimum word size of 5 bits only when parity is OFF. In this case, the USART treats the parity bit just like any other data bit, and the MPU should check for correct parity on each character. In operation, the USART remains inactive until it recognizes the Start Sentinel character. Then it becomes active and collects the data characters, frames the data, and presents it to the MPU. (In some applications, this may not be suitable for reliable Start Sentinel detection; see the Detecting Start Sentinel discussion below.) When using either method, after the CARD PRESENT signal indicates that the card is gone, the MPU should perform error detection by checking both the parity of each character and of the Longitudinal Redundancy Check (LRC) character. To perform the LRC calculation, each bit of each character excluding the parity bit should be exclusive ORed with the respective bit of all characters, including Start Sentinel and End Sentinel. Exclusive ORing the parity bit of all characters does not generate the parity bit for the LRC character; it is the parity bit for the LRC character. The Start Sentinel and the End Sentinel characters frame data. The first bits encountered by the Card Reader are the leading zeros. They indicate to the Reader the presence of an encoded magnetic stripe card, and allow the Reader to synchronize itself with the incoming data bits. The leading zeros are followed by the Start Sentinel character, which indicates the beginning of data on a track. The characters following the Start Sentinel represent the data. The End Sentinel Character indicates the end of data. After the End Sentinel is the Longitudinal Redundancy Check (LRC) character. Trailing zeros follow the LRC and fill the remainder of the track. NOTE: Characters are encoded on the magnetic stripe with the least significant bit recorded first. The Start Sentinel character on Track 2 is recorded as 11010. The bit pattern is B0 B1 B2 B3 P. The least significant bit is B0. B3 is the most significant bit. P is the parity bit. As defined in the ANSI x4.16 1983, ODD parity is required. The conventional representation of the Start Sentinel would be 01011 (P B3 B2 B1 B0) or 0Bh (hex).
Page2of 2
Open in the PDF
The text of page 2, from the PDF itself
Note: For bidirectional reading, a USART cannot be used to identify the Start Sentinel. The USART must be programmed to begin capturing data based on the first binary 1 that is found. Set the word length to one byte (8 bits) and disable parity checking; for track 2, the word size should be no more than 5 bits. Notes: 1. Card Present, Data, and Strobe are negative true logic. 2. Card Present goes low after 14-15 head flux reversals. 3. Card Present returns to high level approximately 150mS after the last flux transition. 4. Data is valid 1.0µS (min.) before the leading negative edge of strobe and remains valid until approximately 1.0µS before the next STROBE.
Detecting Start Sentinel In some cases, random noise on a blank track (especially High Coercivity media) may be detected as a Start Sentinel. If a Start Sentinel is erroneously detected then parity and/or LRC checking would undoubtedly indicate that the track, although blank, actually has an error on it. For this reason, it is suggested that some number of the leading zeros be included in the detection of Start Sentinel. The location of the Start Sentinel and the number of zeros required to synchronize the read circuitry determine the number of detectable zeros prior to the Start Sentinel. In the worst case, there may be no more than four leading zeros on track 2 and no more than nine on tracks 1 and 3. In other words, the Start Sentinel on track 2 should be considered as a 9-bit value: 4 bits of zero and 5 bits of Start Sentinel.
Bidirectional Reading In many of today’s magnetic stripe card applications, reading the card in both directions is necessary. Programming for bidirectional reading has its own special requirements. First, the data acquired from the reader must be treated in memory as a collection of bits (see note below). Since the direction is not known, the program must search the bits looking for the Start Sentinel. If the first character is not the Start Sentinel, then you must move to the other end of the memory and begin searching the bits in reverse order for the Start Sentinel. However, if a Start Sentinel is found, it is possible that the character is LRC. You may check for this by determining if the next character is the End Sentinel. If the next character is the End Sentinel, then you must move to the other end of memory and begin searching the bits in the reverse order as discussed above. The important point is to realize that the LRC could appear to be a false Start Sentinel. If the message does not meet the requirements for a correct recording (the sentinels, party & LRC) then try to interpret the message in the other direction. The card is unreadable only after the software has tried both directions.
Converting Card Data to ASCII Data The data transmitted or received by the user’s device is in ASCII. The data encoded on the cards, however, is in a different format called Card Data. All RS-232 Mag-Tek equipment automatically converts transmitted and received data from ASCII to Card Data. The procedure for converting ASCII to Card Data is described bellow.
Track 1 Card data on Track 1 consists of six binary bits and an odd parity bit for each character. A method for converting ASCII characters to six-bit Card Data (the parity bit is not included in the calculation) is to subtract 20h (hex) from the equivalent 0 parity ASCII character (see Character Conversion Chart). For example, the ASCII character that represents the percent sign (%) is 25h. Subtract 20h from 25h and the result is 05h, which represents the six-bit portion of the card data code for the percent sign. An odd parity bit must be added to the six-bit portion of the character to complete the Card Data code. A method for converting card data to ASCII characters is to remove the parity bit from the Card Data code, then add 20h to the remaining six-bit portion of the character. The result will be the 0 parity ASCII character.
Track 2 & 3 Card data on Track 2 & 3 consists of four binary bits and an odd parity bit for each character. A method for converting ASCII characters to four-bit Card Data (again the parity bit is not included in the calculation) is to subtract 30h from the equivalent ASCII character. For example, the ASCII character that represents the number 7 is 37h. Subtract 30h from 37h and the result is 07h, which represents the four-bit portion of the card data code for the number 7. An odd parity bit must be added to the four-bit portion of the character to complete the Card Data code. A method for converting card data to ASCII characters is to remove the parity bit from the Card Data code, then add 30h to the remaining four-bit portion of the character. The result will be the 0 parity ASCII character.
REGISTERED TO ISO 9001:2000 20725 South Annalee, Carson, CA. 90746 Phone: (310) 631-8602, Help Line (651) 415-6800 Fax (310) 631-3956 http://www.magtek.com P/N 99875063-4, 4/03 Copyright© 1997-2003, Mag-Tek®, Inc.

