REKLAMA

Wiegand RS-232.zip

Czytanie kart zbliżeniowych Wiegand dekodowanie na RS232

Nie gniewaj się, nie czytałem nawet całego postu, użyj tego, działa, sprawdzone. Jest to projekt , który zdobył jedną z nagród w Circuit Cellar.


Pobierz plik - link do postu
  • Wiegand RS-232.zip
    • Pcomm.dll
    • Photos
      • ACC_Wiegand26.jpg
      • ACC_Wiegand37.jpg
      • A3616_Weigand2RS232_Converter.jpg
      • A3616_Complete_Circuit.jpg
      • A3616_Proximity_Reader.jpg
    • Wiegand2RS.asm
    • A3616_Abstract.pdf
    • WiegandCardReaderTest.exe
    • Wiegand2RS_schematic.pdf
    • A3616_Project_Documentation.pdf
    • AVR_Program_Full
      • ISP.LOG
      • Wiegand2RS.avd
      • Wiegand2RS.asm_sym
      • Wiegand2RS.asm
      • Wiegand2RS.apr
      • Wiegand2RS.obj
      • Wiegand2RS.hex
      • Wiegand2RS.map
      • Wiegand2RS.lst
      • 1200def.inc
      • W2RS_PRG.AVR
    • Readme.txt
    • PC_Application_Full
      • Pcomm.dll
      • WiegandReader.pas
      • Pcomm.pas
      • WiegandReaderProject.res
      • ErrorMessage.dfm
      • WiegandCardReaderTest.exe
      • WiegandReaderProject.dof
      • WiegandReader.dcu
      • WiegandReader.dfm
      • WiegandReader.ico
      • Pcomm.dcu
      • WiegandReaderProject.dpr
      • HID_Reader_8bit.bmp
      • ErrorMessage.dcu
      • WiegandReaderProject.cfg
    • 1200def.inc


Wiegand RS-232.zip > A3616_Abstract.pdf

Atmel AVR 2004 Design Contest
Project No: A3616

Wiegand to RS232 Converter
or How to Connect to PC an Access Control Card Reader
Abstract
Wiegand Data Interface is one of the most widespread interfaces in access control industry but
it is completely unknown in PC world. Consequently, experimenting on access control devices or
even simple checking whether data preprogrammed by vendors in access control tags suit the
purchaser's order needs at least an access controller if not the whole access control system. Wiegand
to RS232 converter solves the problem enabling direct connection of the access control card reader
to PC and thus allowing an engineer to play with access control devices on his desk.
Presented in the project Wiegand to RS232 converter obtains the following features:
● support of Wiegand 26 and Wiegand 37 data formats
● automatic recognition of Wiegand 26 and Wiegand 37 data format
● checking parity of Wiegand data block
● transmission via RS232 link card data and card format
● control of the reader's LEDs and beeper.
The block diagram of Wiegand to RS232 converter is shown in figure 1 while the full
schematic is shown in figure 2. As it can be seen, the circuit is the minimalistic one. It contains only
the AVR microcontroller, the rest of needed hardware (e.a. full-duplex UART and Wiegand input
shift register) is emulated in software. The operation of the converter is straightforward. Received
from the reader data are checked for errors and then retransmitted as ASCII characters via RS232
link. In opposite direction control commands are sent on receiving which the converter switches on
and off the reader's LEDs and beeper.

AVR

Open Collect or
Drivers

Microcontroller
Beeper
LED Green
LED Red

Access
Control
Reader
Connector

P D5
P D4
P D3

Overvoltage
Protection

P B1
PD1
PD0

ISP
Connector

P B7..5

/INT 0
Data1
Data0

GoldPin 1x6

P B0

AT 90S1200

RxD

TTL

T xD
RS232
MAX232

RS232
Connector
DB-9F

Figure 1. Block diagram of Wiegand to RS232 converter
Project A3616 – Abstract

1

Figure 2. Schematic of Wiegand to RS232 converter
Project A3616 – Abstract

2

Unlike hardware, software of Wiegand to RS232 converter is rather complicated, mainly due
to limited resources of the microcontroller. Nevertheless, both Wiegand and RS232 interfaces have
been fully implemented. An example snippet of the converter's code is shown in figure 3.
;----------------------------------------------------------------------;
External Interrupt 0 Service Subroutine (vector 0x01)
;----------------------------------------------------------------------; Read bits are stored in Wiegand buffer Wiegand_B0..Wiegand_B4 as:
;
Wiegand_B0:
b19 b20 b21 b22 b23 b24 b25 b26(odd)
;
Wiegand_B1:
b11 b12 b13 b14 b15 b16 b17 b18
;
Wiegand_B2:
b3 b4 b5 b6 b7 b8 b9 b10
;
Wiegand_B3:
x
x
x
x
x
x b1(even) b2
;
Wiegand_B4:
x
x
x
x
x
x
x
x
;
b1 - even parity bit for bits b2..b13
;
b26 - odd parity bit for bits b14..b25
; for Wiegand26 data format and as:
;
Wiegand_B0:
b30 b31 b32 b33 b34 b35 b36 b37(odd)
;
Wiegand_B1:
b22 b23 b24 b25 b26 b27 b28 b29
;
Wiegand_B2:
b14 b15 b16 b17 b18 b19 b20 b21
;
Wiegand_B3:
b6 b7 b8 b9 b10 b11 b12 b13
;
Wiegand_B4:
x
x
x b1(even) b2 b3 b4 b5
;
b1 - even parity bit for bits b2..b19
;
b37 - odd parity bit for bits b19..b37
; for Wiegand37 data format
; The end of the data frame is detected as time_Wgnd time-out
;
ext_INT0: in
SREGcopy,SREG
; save SREG
in
tempINT,PIND
; read Wiagand inputs
andi
tempINT,0b00000011
; extract Data_1 and Data_0 lines
;
cpi
tempINT,0x00
; Data_1Data_0=00?
breq
extERROR
; error - both lines can't be low
cpi
tempINT,0x03
; Data_1Data_0=11?
breq
extERROR
; error - one line should be low
ror
tempINT
; read Wiegand bit (C=0 when Data_0=0
;
C=1 when Data_1=0)
rol
Wiegand_B0
; \
rol
Wiegand_B1
; |
rol
Wiegand_B2
; | complete Wiegand data block
rol
Wiegand_B3
; |
rol
Wiegand_B4
; /
inc
ldi
extERROR: out
reti

Wgnd_count
time_Wgnd,Wgnd_tout

; count read bits
; load time-out timer

SREG,SREGcopy

; restore SREG

Figure 3. Wiegand interface transmission service subroutine
The prototype of Wiegand to RS232 converter has been assembled on two perf-boards, one of
which contains signal conditioning and protection circuits of card reader interface while the second
one carries the microcontroller, RS232 driver and voltage regulator. Originally the converter worked
with MiniProx™ access control proximity card reader made by HID Corporation and such test
circuit is shown in figure 4.

Project A3616 – Abstract

3

Figure 4. Complete circuit: the card reader and Wiegand to RS232 converter
As an example application of Wiegand to RS232 converter, the simple PC program called
Wiegand Card Reader Test has been written. It was designed mainly for visualising programed data
in access control tags (e.a. data format, facility code and card number), but it can be used for testing
access control readers themselves. In figure 5 there is shown the screen shot of Wiegand Card
Reader Test program during read-out of Wiegand 26 card.

Figure 5. Read-out of Wiegand 26 card data

Project A3616 – Abstract

4



Wiegand RS-232.zip > A3616_Project_Documentation.pdf

Atmel AVR 2004 Design Contest
Project No: A3616

Wiegand to RS232 Converter
or How to Connect to PC an Access Control Card Reader
Project Documentation

1. Introduction
Wiegand Data Interface is one of the most widespread interfaces in access control industry.
Originally introduced into magnetic card readers based on Wiegand effect, nowadays it is used in
virtually all kinds of access control tag readers such as proximity, magnetic stripe or bar code ones.
Even biometric devices applied in access control systems are equipped with Wiegand interface.
Unfortunately, this interface is completely unknown in PC world. Consequently, experimenting on
access control devices or even simple checking whether data preprogrammed by vendors in access
control tags suit the purchaser's order needs at least an access controller if not the whole access
control system. Wiegand to RS232 converter solves the problem enabling direct connection of the
access control card reader to PC and thus allowing an engineer to play with access control devices
on his desk.

2. Wiegand Data Interface
Wiegand Data Interface is simplex serial interface used for transmitting data from input
devices (e.g. card readers) to access controllers. It consists of two data lines called “Data 0” and
“Data 1” respectively, and one “Data Return” line, which part in most cases takes ground. The
reader transmits data by pulling low “Data 0” line when sending logic zero and “Data 1” line when
sending logic one. The bit pulse lasts for about 50ms while interval between two bits equals
approximately 2ms. Absence of pulses for about 200ms signals the new data block.
Logic Value

1

0
+5V

Data 1

0V
+5V

Data 0

50us

0V

2ms

Figure 1. Wiegand interface waveforms
Depending on the data block length and structure, a few Wiegand substandards have evolved,
the most widespread of which are Wiegand 26 and Wiegand 37.
Wiegand 26 data block consists of 26 bits. The first bit and the last bit are even parity bit of
the first half of the data block and odd parity bit of the second half of the data block respectively,
while bits b2...b9 and bits b10...b25 represent 8-bit facility code and 16-bit card number
respectively. The structure of Wiegand 26 data block is shown in figure 2.
even parity

odd parity

b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b17 b18 b19 b20 b21 b22 b23 b24 b25 b26

P A A A A A A A A B B B B B B B B B B B B B B B B P
even
parity
bit

8 bit facility code
0...255

16 bit card number
0...65535

odd
parity
bit

Figure 2. Structure of Wiegand 26 data block
Project A3616: Wiegand to RS232 Converter

1

Wiegand 37 data block consists of 37 bits. As in Wiegand 26, the first bit and the last bit are
even parity bit of the first half of the data block and odd parity bit of the second half of the data
block respectively. Owing to the odd number of bits in the data block, the bit b19 is counted for
both even and odd parity. Bits b2...b36 represent 35-bit card number. The structure of Wiegand 37
data block is shown in figure 3.
odd parity
even parity
b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b17 b18 b19 b20 b21 b22 b23 b24 b25 b26 b27 b28 b29 b30 b31 b32 b33 b34 b35 b36 b37

P B B B B B B B B B B B B B B B B B B B B B B B B P B B B B B B B B B B P
even
parity
bit

odd
parity
bit

35 bit card number
0...34359738367

Figure 3. Structure of Wiegand 37 data block
Apart from two data output lines, the standard access control tag reader with Wiegand Data
Interface is equipped with three input control lines:
● LED red
● LED green
● beeper
which are used by the access controller for signaling state of apas (e.a. point actuators and sensors).
LEDs and beeper are switched on when the respective control line is pulled low.

3. Hardware

AVR

Open Collect or
Drivers

Microcontroller
Beeper
LED Green
LED Red

Access
Control
Reader
Connector

P D5
P D4
P D3

Overvoltage
Protection

P B1
PD1
PD0

ISP
Connector

P B7..5

/INT 0
Data1
Data0

GoldPin 1x6

P B0

RxD

TTL

T xD

AT 90S1200

RS232
MAX232

RS232
Connector
DB-9F

Figure 4. Block diagram of Wiegand to RS232 converter
The block diagram of Wiegand to RS232 converter is shown in figure 4. The circuit is the
minimalistic one. It consists of only four parts:

Project A3616: Wiegand to RS232 Converter

2

Figure 5. Schematic of Wiegand to RS232 converter
Project A3616: Wiegand to RS232 Converter

3

AVR microcontroller
● AND gate
● RS232 driver / receiver
● signal conditioning and protection circuits of card reader interface.
As the microcontroller, the simplest member of Atmel AVR family (e.a. AT90S1200) has been
selected. It contains very little hardware but has enough computing power to emulate needed
devices in software. Additional AND gate generates interrupt whenever negative pulse on Data 0 or
Data 1 line appears. The microcontroller communicates with PC via RS232 interface. The operation
of the converter is straightforward. Received from the reader data are checked for errors and then
retransmitted as ASCII characters via RS232 link. In opposite direction control commands are sent
on receiving which the converter switches on and off the reader's LEDs and beeper.


The full schematic of Wiegand to RS232 converter is shown in figure 5. The AVR
microcontroller U1 operates with 7.3728MHz crystal resonator Q1. As the RS232 voltage level
converter U2, MAX232 driver/receiver in standard application circuit has been used. The AND gate
is formed by diodes D8, D9 and internal pull-up circuit of pin PD2. The rest of elements protects
ports of microcontroller against overvoltage (D1...D7) and overcurrent (R1...R3, T1...T3, R7 and
R9), which may occur if the connected card reader uses long cable. The analog voltage regulator U3
with diode D10, which protects the circuit against wrong power supply polarity, completes the
schematic.
The circuit has been assembled on two perf-boards (figure 6), one of which contains signal
conditioning and protection circuits of card reader interface while the second one carries the
microcontroller U1, RS232 driver U2 and voltage regulator U3. The prototype Wiegand to RS232
converter worked with access control proximity card reader made by HID Corporation (figure 7).
The complete system is shown in figure 8.

Figure 6. Wiegand to RS232 converter

Project A3616: Wiegand to RS232 Converter

4

Figure 7. MiniProx™ proximity card reader and two transponders: the key fob and the ISO card

Figure 8. Complete circuit: the card reader and Wiegand to RS232 converter

Project A3616: Wiegand to RS232 Converter

5

4. Software
Software code of Wiegand to RS232 converter has been written in assembler in AVR Studio
3.53 environment. It consists of 3 parts:
● external interrupt 0 service subroutine
● timer T0 overflow service subroutine
● the main loop.
In external interrupt 0 service subroutine transmission from the access control reader is
handled. During each interrupt one bit of the Wiagand data block is read and stored in buffer. The
number of read till timeout event bits reflects Wiegand data format. The detailed flow chart of INT0
service subroutine is shown in figure 9.
interrupt
/INT 0
Store SREG

YES

P IND.1 =0
&
PIND.0 = 0
NO

YES

P IND.1 =1
&
PIND.0 = 1
NO

St ore P IND.0 in Wiegand
data block buffer
Wgnd_count ++
Start Wiegand T ime-out
T imer
Restore SREG

RET I

Variable s
SREG – the AVR st atus register
PIND.1 – Wiegand Data_1 line
PIND.0 – Wiegand Data_0 line
Wgnd_count – Wiegand data block
bit s counter

Figure 9. Flow chart of INT0 service subroutine
Timer T0 overflow interrupt is used for both: running timeout timers of access control reader
and RS232 transmissions as well as for running software full-duplex UART. Due to lack of external
interrupt to independently service UART receiver, reception of bits is done by polling RxD line.
The line is sampled four times faster than the bit rate of RS232 link is. Consequently, during each
bit there are four timer T0 overflow interrupts numbered 0, 1, 2 and 3. On detection of the falling
edge of the START bit, the number of the interrupt in which the middle of the bit appears is
calculated and stored. Then ten bits of the received character is read and the search of the START
bit begins again. UART transmitter is organized in the same way with the exception that the
Project A3616: Wiegand to RS232 Converter

6

transmission of each bit starts always at interrupt number 0. Timer T0 overflow period equal to
208.33ms results in RS232 speed of 1200 bps and character format 8N1.
Operations performed in the main loop are as follows:
● checking parity of Wiegand data block
● analysis of frames incoming via RS232
● transmission via RS232 frames containing card format and card data.
Due to lack of RAM to organize UART receiver and transmitter buffers, reception of incoming
frames as well as transmission is done by two state machines. Their transition charts are shown in
figures 10 and 11 while the detailed list of supported by RS232 link frames is given in table 1.

S2

Rx_char = S
Rx_char = ST X

S0

Rx_char = ST X

S1
Rx_char = S v R

Rx_char = R

S3

Variabl e s
Rx_stat e – state of the receiver state machine
Rx_char – received charact er

Figure 10. Transition chart of RS232 receiver state machine

Wgnd_count = 26
chkWgnd = 0
time_Wgnd = 0

S0

S2

S3

S4

S5

S1

S6
Wgnd_count = 26

chkWgnd = 1

S7

time_Wgnd = 0

S13

S8
S12

S11

S10

S9

Variable s
T x_state – state of the transmitter state machine
time_Wgnd – Wiegand transmission time-out timer
chkWgnd – Wiegand data block parity test result
Wgnd_count – Wiegand data block bits count er

Figure 11. Transition chart of RS232 transmitter state machine

Project A3616: Wiegand to RS232 Converter

7

Table 1. Frames of RS232 data link
No

Frame

Frame structure
Frames transmitted by the converter

1

Card data in Wiegand 26 format

STX S f_8 c_16 ETX

2

Card data in Wiegand 37 format

STX L c_35 ETX

Frames received by the converter
3

Switch red LED on

STX S r ETX

4

Switch red LED off

STX R r ETX

5

Switch green LED on

STX S g ETX

6

Switch green LED off

STX R g ETX

7

Switch beeper on

STX S b ETX

8

Switch beeper off

STX R b EXT

where: STX = 0x02 – Start of Transmission character
ETX = 0x03 – End of Transmission character
f_8 – 8-bit facility code sent as 2 ASCII characters (0..9, A..F)
c_16 – 16-bit card number sent as 4 ASCII characters (0..9, A..F)
c_35 – 35-bit card number sent as 9 ASCII characters (0..9, A..F)

5. PC Application
Wiegand Card Reader Test program was designed mainly for checking on the engineer's desk
data preprogrammed in access control cards by their vendors. Nevertheless, it can be used for
testing card readers as it implements all commands supported by Wiegand to RS232 converter. The
full list of the program features is shown in table 2.
Table 2. Operations performed by Wiegand Card Reader Test program
No

Event

Operation

1

Start of the program

2

COM1 / COM2 serial port selection Swapping the active serial port

3

Reception of the card data frame

Refreshing data card format, facility code and card
number fields on display

4

„LED Red” key pressed down

Sending „Switch red LED on” command

5

„LED Red” key pressed up

Sending „Switch red LED off” command

6

„LED Green” key pressed down

Sending „Switch green LED on” command

7

„LED Green” key pressed up

Sending „Switch green LED off” command

8

„Beeper” key pressed down

Sending „Switch beeper on” command

9

„Beeper” key pressed up

Sending „Switch beeper off” command

10 End of the program

Opening COM1 serial port

Closing active serial port
Project A3616: Wiegand to RS232 Converter

8

The program has been written in Borland Delphi 5. Originally it was intended for operation
with Wiegand to RS232 converter connected to the universal serial ports extension card, type
C104P by Moxa Technologies Co. Therefore it uses, supplied by the card manufacturer, Moxa
program library Pcomm.dll. However, performed tests have shown that Wiegand Card Reader Test
program works with Wiegand to RS232 converter connected to standard PC serial ports COM1 and
COM2. The example screen shots are shown in figures 12 and 13.

Figure 12. Read-out of Wiegand 26 card data

Figure 13. Read-out of Wiegand 37 card data

6. Conclusion
Described in the project Wiegand to RS232 converter is fully-operational device. However, it
can be enhanced by adding support of another Wiegand substandards, especially vendor-specific
ones. Furthermore, presented in the project implementation of Wiegand interface (simple, cheap and
consuming very little CPU resources) can be easily adapted to any AVR microcontroller as a part of
bigger access control project.

Project A3616: Wiegand to RS232 Converter

9

7. Appendix 1 – Bill of Material
WIEGAND TO RS232 CONVERTER - BOM
Value
Package
Count
Designator
--------------------------------------------------------------------------Integrated circuits
AT90S1200-12PC
DIP-20
1
U1
MAX232CPE
DIP-16
1
U2
LM78L05
TO-92
1
U3
Transistors
BC547

TO-92

3

T1

T2

T3

Diodes
1N4001
1N4148
P6KE18A
LED Green

AXIAL
AXIAL
AXIAL
AXIAL 3mm

1
6
3
1

D10
D4
D1
D11

D5
D2

D6
D3

Resistors ±5%, 0.125W
100
220
1k
10k

AXIAL
AXIAL
AXIAL
AXIAL

2
3
1
5

R7
R1
R11
R2

R9
R3

R5

R4

Capacitors ±10%, 63V (unless noted)
27pF
AXIAL
2
100nF
AXIAL
2
22uF/16V
AXIAL
4
47uF/6.3V
AXIAL
1
100uF/16V
AXIAL
1

C1
C7
C3
C9
C10

C2
C8
C4

Others
Crystal 7.3728MHz
HC-49U
Poly Fuse RXE020
AXIAL
Connector DB-9F
Gold Pin 1x6
Terminal Block ARK-7pin
Terminal Block ARK-2pin
IC Socket
DIP-20

1
1
1
1
1
1
1

D7

D8

R6

R8

R10

C5

D9

C6

Q1
F1
J3
J2
J1
J4

8. Appendix 2 – Project files
The complete project comprises the following directories and files:
|
|-|
|-|
|-|-|-|-|-|
|--

AVR_Program_Full
PC_Application_Full
Photos
Wiegand2RS.asm
1200def.inc
WiegandCardReaderTest.exe
Pcomm.dll
A3616_Abstract.pdf

The directory contains Wiegand to RS232 converter
project files for AVR Studio 3.53 Environment
The directory contains project of PC test program in
Delphi 5 Environment
The directory contains photographs of the project
Wiegand to RS232 converter source code
Definitions of bit/register names for AT90S1200
PC test program
Serial Port Library for WiegandCardReaderTest.exe
program
Abstract of the project

Project A3616: Wiegand to RS232 Converter

10

|-- A3616_Project_Documentation.pdf
The full description of the project
|-- Wiegand2RS_schematic.pdf
Schematic of Wiegand to RS232 converter
|-- Readme.txt
List of the project directories and files

9. Appendix 3 – Sources
AT90S1200
ATMEL Corporation
http://www.atmel.com
MAX232
Maxim Integrated Products
http://www.maxim-ic.com
Access Control Reader
HID Corporation
http://www.hidcorp.com
Universal Multiport Serial Board
Moxa Technologies Co., Ltd.
http://www.moxa.com
http://www.moxa.com.tw

Project A3616: Wiegand to RS232 Converter

11


Wiegand RS-232.zip > Readme.txt

The directory Project_A3616 should contain the following directories and files:

Project_A3616
|
|-- AVR_Program_Full Wiegand to RS232 converter program files (AVR Studio 3.53)
|-- PC_Application_Full PC test program files (Delphi 5)
|-- Photos Photographs
|-- Wiegand2RS.asm Wiegand to RS232 converter source code
|-- 1200def.inc Definitions of bit/register names for AT90S1200
|-- WiegandCardReaderTest.exe PC test program
|-- Pcomm.dll Serial Port Library for WiegandCardReaderTest.exe program
|-- A3616_Abstract.pdf Abstract of the project
|-- A3616_Project_Documentation.pdf Full description of the project
|-- Wiegand2RS_schematic.pdf Schematic of Wiegand to RS232 converter
|-- Readme.txt This file