Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
RFID: Data Acquisition Author: Student I.D.: Supervisor: Associate Examiner: Lee Kin Bong 02657852 Professor K.K. Cheng Professor S.P. Wong
A project report presented to the Chinese University of Hong Kong in partial fulfilment of the Degree of Bachelor of Engineering
April, 2006
Abstract:
RFID, Radio Frequency Identification, is a popular technology nowadays. It will replace the traditional bar codes soon as it have advantages on large informationcarrying capacity, physically strong, able to recognize from a distance. Most importance is it can be completely automatic if we can solve the collision problem between tags. This can save manpower and prevent man-made mistakes if we can achieve that.
In this project, my main job is to build up an anti-collision system between the tags and the reader. The collision problems are due to all the tags in the environment reply and send their own serial number to the reader. Therefore, the reader has to classify the serial number step by step. I have successfully built up the anti-collision arbitration system on reader side by binary tree method with the aids of the Manchester coding.
Acknowledgements
Special thanks to my supervisor, Professor Michael Cheng Kwok Keung (B.Sc., Ph.D. (London), Sr.MIEEE, MIEE, CEng (IEE)), for his useful advice and support on my project, RFID: Data Acquisition.
Content
ABSTRACT: ACKNOWLEDGEMENTS CONTENT INTRODUCTION
Forward Link Encoding Pulse Interval Encoding --- Type A Manchester Coding --- Type B Return Link Encoding FM0 --- Type A and B Collision Arbitration ALOHA procedure --- Type A Binary Tree --- Type B Error Detection CRC Procedure --- Type A and B
2 3 4 6
9 9 10 11 11 12 12 12 13 13
THEORY
Hardware Microcontroller Reset Circuit Oscillator Circuit Traffic control Circiut Power Supply Circuit RS-232 interface conversion circuit Circuit Design Component List Software Programming Principle Program Flow 1) Reader Program 2) Tag Program Serial Communication
15
15 16 16 17 17 18 19 20 21 22 22 29 29 31 32
40
41 45 47
57 59 60 61
61 68
75 76
Introduction
Radio Frequency Identification (RFID) Systems fall into two basic categories. The categories are broadly determined by how the tags powered, which in turn reflects the average transponder price. The transponder categories are:
Active RFID tags backscatter modulation (battery on board) [cost EU 10 40] Passive RFID tags backscatter modulation (RF powered) [cost less than EU 2.50]
My project is focus on the passive RFID, which is cheaper but comparably with a shorter transmitting distance than active one. But with the backscattering technique, it can still typically achieve 3m transmitting length, which are suitable for most of application. Also, because of the cost and the size, passive RFID have a potential to replace the bar code in the future.
Radar can be considered as the technology precursor to RFID. They are both using the phenomenon of RF reflection. The radar use the time difference between the signal sent and reflected back to calculate the distance from an object. For RFID, the reflected signal carries importance information to the reader (e.g. the serial number of the product). This technique is using the method of backscattering.[1]
Like WLAN card, we need to define the standard for the RFID to assure the communication is universal. There are many standards for RFID, but the common use is the ISO18000 (Information technology -- Radio frequency identification for item management). ISO18000 divide into six parts: ISO18000-1: ISO18000-2: ISO18000-3: ISO18000-4: ISO18000-6: ISO18000-7: Reference architecture and definition of parameters to be standardized Parameters for air interface communications below 135 kHz Parameters for air interface communications at 13,56 MHz Parameters for air interface communications at 2,45 GHz Parameters for air interface communications at 860 MHz to 960 MHz Parameters for active air interface communications at 433 MHz
My project follows some of the requirements in ISO18000-6. According to ISO18000-6, the RFID in to two types: Type A and Type B [2]
For the protocol of reader, there is some points importance: 1) Forward Link Encoding 2) Return Link Encoding 3) Collision arbitration 4) Error Detection
Forward Link Encoding Pulse Interval Encoding --- Type A Because this coding has the short pulse duration, it can give continuous power supply. As a result, it is mainly use in Reader to Transponder. Original Data Logic 0 Logic 1 Signal Sent A pulse of duration 2t before next pulse A pulse of duration t before next pulse Table 1.2a --- Logic table of Pulse Interval code
Manchester Coding --- Type B The Machester code is often used for data transmisson from the transponder to the reader based upon load modulation using a subcarrier. [3] The princple of signal coding is stated at below table: Value Sent Logic 0 Logic 1 0 to 1 (upward transition at bit centre) 1 to 0 (downward transition at bit centre) Table 1.2b --- Logic table of Manchester code For example:
10
Return Link Encoding FM0 --- Type A and B FM0 is usually used for the signal receiving. The level is inverted at the start of every bit period, so that the bit pulse can be more easily reconstructed in the receiver if necessary. The princple of signal coding is stated at below table: Value Sent Logic 0 Logic 1 Changing pulse(1 to 0 or 0 to 1) Constant Pulse Table 1.3 --- Logic Table for FM0 For example:
11
Collision Arbitration ALOHA procedure --- Type A This is method using the technique of Carrier Sense Multiple Access. The procedure is used exclusively with read-only transponders, which generally have to transfer only a small amount of data (serial numbers), this data being sent to the reader in a cyclical sequence. The data transmission time represents only a fraction of the repetition time, so there are relatively long pause between transmissions. Furthermore, the repetition times for the individual transponders differ slightly. There is therefore a certain probability that two transponders can transmit their data packets at different times and the data packets will not collide with one another.
The binary tree method uses the principle of tree diagram to filter out the binary serial number step by step until no collision occurs. I will discuss it later on page 22.
12
Error Detection CRC Procedure --- Type A and B CRC (cyclic redundancy check) procedure was originally used in disk drives, and can generate a checksum that is reliable enough even for large data quantities. However, it is also excellently suited for error recognition in data transfer via wire-bound (telephone) or wireless interface (radio RFID) [3]. The principle of CRC is base on polynomial division. First we need to define the CRC checksum, which is calculated by the division of a polynomial We can consider the binary number as polynomial, e.g. 10011 = X^4 + 0^3 + 0^2 + X^1 + X^0 = X^4 + X^1 +1
T - It is k+n bits long P - A pattern of n+1 bits First we convert all of them to polynomial, and let T = M*x^n + F If we divide M*x^n with P, M*x^n/P = Q +R/P We let the remainder R as F, T = M*x^n +R T/P = M*x^n/P +R/P = Q + R/P + R/P = Q +(R+R)/P As binary number added to itself in a modulo 2 field is zero, therefore: T/P = Q no remainder
13
We can consider: M as Original Frame , F as CRC checksum value T as Resulting Frame to transmit P as generator polynomial
The principle of CRC is to check whether T is divided by P We have to pre-define the generator polynomial before the system can communicate: Here is some standard CRC-8 Generator Polynomial CRC-16/disk controller Generator Polynomial CRC-16/CCITT Generator Polynomial X^8+X^4+X^3+X^2+1 X^16+X^15+X^2+1 X^16+X^12+X^5+1
For my project, I will base on type B requirement. Therefore, the protocol will base on, a) Forward Link encoding: b) Return Link encoding: c) Collision Arbitration: d) Error Detection: Manchester Code Manchester Code (for collision detection) Binary Tree Error Check Method of UART
14
Theory
For my project, it includes hardware and software. For hardware part, it includes the traffic control circuit, MCU and the circuit for RS-232 communication. For software parts, it includes the control program of MCU.
RS-232
RF Circuit
Computer
MCU
Hardware
First, I would like to discuss my hardware design. I am focus on the accessory circuit of MCU and the communication between MCU and computer using the RS-232 interface at this moment. For the MCU accessory circuit, it includes the reset circuit, the clock cycle circuit, the travel control circuit and the power supply circuit. Also MCU cant communicate by RS-232 interface as they with different logic level (i.e. one use TTL, one use computer logic). As a result, we need circuit acts as a communication channel.
15
Microcontroller For the MCU, I will choose to use AT89S52 8-bit Microcontroller with the following main characteristic: - 8K Bytes In-System Programmable Flash - 32 Programmable I/O Lines - Full Duplex UART Serial Channel Figure 2.2 --- AT89S51 Pin assignment
Reset Circuit All microcontrollers need to reset before functioning. Generally speaking, reset time of microcontroller not less than 5ms. When the power on, C1 will act as short circuit. As a result, high voltage (Vcc) drop at R1 => Reset After C1 will charge up and then finally become open circuit. Reset will become low voltage.
The circuit can be verify to manual control reset by adding a switch across the capacitor.
0
Figure 2.3 --- Reset Circuit
16
Oscillator Circuit It is a circuit to provide clock pulse to Microcontroller. According the specification of AT89S52, I use a crystal with the frequency 11.0592 MHz with two 39pF load capacitor need to build the Oscillator Circuit. Figure 2.4 --- Oscillator Circuit Traffic control Circiut As the reader needs to send signal to the tags and the computer separately, it need to control the path of transmission. By a control signal from MCU and an AND gate, it can be achieved easily.
U4A
Tags
Computer
Table 2.1--- Transmission Control of reader For UART transmission, it stays at logic high when there is no transmission. As a result, the reader uses an OR-gate with a control signal to control the transmission. When
17
the control input (P0_0/P0_1) is high, that means the transmission is off as the output is always high. The transmission is on only if the control signal is low. For the tags side, it has to combine three outputs of tags just like in the usual environment. So, using OR-gate is a choice. You can imagine if there is a logic high signal sending from a tag in the environment, the reader will receive a logic high signal even if there is a tag sending a logic low signal at the same time. The principle is same as using an OR-gate. Even through the tag does not sending a signal, it will disturb the transmission as for UART transmission; it stays at logic high when there is no transmission. Therefore, tags output needs to pass through an AND-gate with a control input before get into an OR-gate. If the tags dont reply after receiving the signal from reader, set the control input be low. For other cases, set the control input be high.
Tag 1 TXD Tag 1 P0_0 Tag 2 TXD Tag 2 P0_0 Tag 3 TXD Tag 3 P0_0
U3A 1 3 2 74LS08
U3A 1 3 2 74LS08
U2A 1 2 8 9 74HC4075
Reader RXD
U3A 1 3 2 74LS08
As MCU needs a steady power supply and protect it form a large current, a voltage regulator is needed. The voltage regulator use in the current is L7805CV. It can give a output voltage 5 + 0.2V if the range of input is 8V to 20V. The output voltage can reach the VCC requirement of AT89S52 (4.0 to 5.5V)
18
RS-232 interface conversion circuit The circuit contains the IC MAX232, manufactured by Texas Intrument, which can perform the translation between TTL logic and RS-232 standard TTL 2-5V 0-0.8V RS-232 -15V 15V
Logic 1 Logic 0
Table 2.2 Comparing the TTL logic with RS-232 standard Here is the reference design:
RS-232 is simple, universal, well understood and supported but it has some serious shortcomings as a data interface. The standards to 256kbps or less and line lengths of 15M (50 ft) or less but today we see high speed ports on our home PC running very high speeds and with high quality cable maxim distance has increased greatly. The rule of thumb for the length a data cable depends on speed of the data, quality of the cable.
19
Figure 2.8 --- Pin function of RS-232 The data transferring for RS-232 can be asynchronous, which can save one transmission line comparing to synchronous one. As the data transmission is asynchronous, we need to define transfer rate first before communication, which is calls the baud rates. For example Baud Rate = 9600 means the data rate is 9600 bits per one second
Circuit Design
U1 1 39 38 37 36 35 34 33 32 11.0592 C6 1 2 3 4 5 6 7 8 19 18 31 9 C8 1n R1 1k AT89S53 U5 V2 9Vdc L7805/TO220 1 VIN VOUT 2 C3 1u C4 1u 40 P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P1.0/T2 P1.1/T2EX P1.2 P1.3 P1.4/SS P1.5/MOSI P1.6/MISO P1.7/SCK XTAL1 XTAL2 EA/VPP RST VCC MAX232 P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD PSEN ALE/PROG 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17 C1 29 30 1u C2 1u 1 3 4 5 2 6 3 2 U7A 1 3 2 74LS32 U3 13 8 11 10 R1IN R2IN T1IN T2IN C1+ C1C2+ C2V+ VR1OUT R2OUT T1OUT T2OUT 12 9 14 7 74LS32 U4A
C5 40u
Tags
40u
V1 5Vdc
3 5
0
20
U3A 1 3 2 74LS08 U1 39 38 37 36 35 34 33 32 11.0592 C11 1 2 3 4 5 6 7 8 19 18 31 9 R1 1k AT89S53 40 P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P1.0/T2 P1.1/T2EX P1.2 P1.3 P1.4/SS P1.5/MOSI P1.6/MISO P1.7/SCK XTAL1 XTAL2 EA/VPP RST VCC P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD PSEN ALE/PROG 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17 29 30 31 9 40 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 19 18 2 1
U4A 1 3 2 74LS08 U1 P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P1.0/T2 P1.1/T2EX P1.2 P1.3 P1.4/SS P1.5/MOSI P1.6/MISO P1.7/SCK XTAL1 XTAL2 EA/VPP RST VCC AT89S53 C9 C9 P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD PSEN ALE/PROG 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17 29 30
U6A U2A 3 74LS08 74HC4075 U1 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 19 18 31 9 40 P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P1.0/T2 P1.1/T2EX P1.2 P1.3 P1.4/SS P1.5/MOSI P1.6/MISO P1.7/SCK XTAL1 XTAL2 EA/VPP RST VCC AT89S53 P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD PSEN ALE/PROG 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17 29 30 1 2 8 9
Reader
C9 40u
40u
V1 5Vdc
0
U5 V2 9Vdc L7805/TO220 1 VIN VOUT 2
40u
Component List Components Microcontroller Regulator Logic Gate Crystal Resistor Capacitor Value/Model AT89S52 MAX232 L7805CV AND gate 11.0592MHz 1k 1n 1uF 40uF Number 1 1 1 1 1 1 1 4 2 1 1 1
21
Software
The Software part is the main part of my project. I will introduce the basic principle of my program to achieve the anti-collision system first, and then I will go into discuss the flow of my program
Programming Principle
I will use the case of an area contain three tags to explain the principle of binary tree:
Firstly I have to define some commands for reader to communicate with tags
Command
Tags Response
REQUEST
Tags with smaller or equal serial number will send it back its own serial number
Remain its state of waiting REQUEST or SELECT commands only Change to state of waiting CONTROL commands except it will not response to REQUEST and SELECT commands
SELECT
Tags with equal serial number will send it back its own serial number
CONTROL Tags will perform specific function follow the reader request
Remain its state of waiting CONTROL commands except it will not response to REQUEST and SELECT commands
22
a) Tag 1: 11001111
b) Tag 2: 11100011
c) Tag 3: 11000111
At first step reader will send a REQUEST command to the tags. The REQUEST command contains a request number. If the tags in the area contain the serial number smaller or equal to the request number, it will send back its own serial number to the reader.
Therefore, if we want to check whether there are tags in the area. We need to send a REQUEST command with a maximum request number (e.g. if the system serves for tags with 8 bits serial number: the maximum request number = 11111111). As a result, all the tags should response as they will not have a serial number larger than that. If the reader cant receive anything, it will keep sending the maximum REQUEST command until ther is response.
23
2) When the tags reply together, collisions occur. The Reader will due with the highest collision bits first.
3) To handle the collision problem. The reader will send a REQUEST command with specific request number according to the collision situation. The rule of defining the request number is:
Bit(compare to the maximum collision bit) Setting Upper Equal Lower Same as what the reader receive 0 1
According the above rule, the resultant request number of our example is: 11011111.
24
Figure 2.12 --- Send the request number to due with collision at bit 5
4) As Tag 2 has the serial number which larger than the request number, it does not response to the reader. The reader can filter out Tag 2. In other words, it can filter out the Tags with 1 at bit 5 of their serial number
25
5) Using the same principle before and repeat the procedures. The reader will get the smallest serial number from the environment.
Figure 2.14 --- Send the request signal for collision at bit 3
Tag 3 (11000111)
6) After we can get the serial number without collision, the reader still have to send a SELECT signal to the tags with the select number (same value as the serial number received), there are two reasons of doing that:
a) Let the tag to enter the stage of ready to receive CONTROL command
b) If the tag still response to the REQUEST command, we cannot find the other serial number as the method always find the smallest serial number first.
26
Only the tag with the same serial number as the select number replies to SELECT command.
Tag 1 (11001111) Reader (Select)11000111 Tag 2 (11100011) Tag 3 (11000111) Select Number
Tag 3 will then send back its serial number for confirmation. It will now ready to response to the CONTROL commands to perform specific function. The reader will check whether the received serial number same as the one received before. If it is, the reader will send the serial number to computer through the RS-232 interface.
27
The principle of binary tree I have discussed in introduction. I want to say just a few more words on this topic related to the collision detection. For the detection of collision bits, Manchester code acts a very important role on this. Let verify it by the about example:
Figure 2.17 --- Collision for NRZ coding [3] From the figure, we can see even there is collision occurs for NRZ coding, MCU can still receive a data signal from the tags. The serial number returned may neither equal to any one of the tags
28
Recall the memory for the Manchester coding; the value a bit is defined by the change in level (negative or positive transition) within a bit window. Logic 0 in this example is coded by positive transition. Logic 1 is coded by a negative transition. The no transition state is not permissible during data transmission and is recognized as an error [3]. An error may occur when there are collisions. Therefore, collision is detected.
Program Flow
Beside the reader program, I have also written the program for tag. The tag program is used to verify whether my reader program function correctly. The program flow is basic on the theory which stated at above.
1) Reader Program First, MCU need to initialize condition first before it function. For example we need to preset the value of global variable and the state of register. Then the MCU will send the REQUEST signal with the largest request number to the tags. It is because all the tags will response to this request signal if its serial number is less than it.
29
If there no tags near, MCU will sent the request signal again until there is a reply. If there are tags replies with collision, the MCU will change the request number and send again the REQUEST signal until there is no collision. Then, the MCU will send a SELECT signal to the tags. The tag with the identical tags address will become available for the processing of CONTROL command. Tag with different addresses will there after only respond to a REQUEST command. Then the MCU can send the serial number to the computer through RS-232 for further function.
30
2) Tag Program
First, initialize the MCU condition. Then the tags will wait for the REQUEST or SELECT command. If it received a REQUEST command, compare the serial number with the request number. If it is larger or equal to the request number, send its own serial number to reader. Otherwise, it will not reply. Then, wait for the REQUEST or SELECT signal again.
If the tags receive a SELECT signal with the same serial number as request number, it will enter a state of waiting the CONTROL signal. It will not response to REQUEST or SELECT commands anymore.
31
Serial Communication
The transmitting and receiving of signal is serial. Therefore we need to use the serial interface of MCU: UART.
The Universal Asynchronous Receiver/Transmitter (UART) controller is the key component of the serial communications subsystem of a computer. The UART takes bytes of data and transmits the individual bits in a sequential fashion. At the destination, a second UART re-assembles the bits into complete bytes
Asynchronous transmission allows data to be transmitted without the sender having to send a clock signal to the receiver. Instead, the sender and receiver must agree on timing parameters in advance and special bits are added to each word which are used to synchronize the sending and receiving units.
When a word is given to the UART for Asynchronous transmissions, a bit called the "Start Bit" is added to the beginning of each word that is to be transmitted. The Start Bit is used to alert the receiver that a word of data is about to be sent, and to force the clock in the receiver into synchronization with the clock in the transmitter. These two clocks must be accurate enough to not have the frequency drift by more than 10% during the transmission of the remaining bits in the word.
32
After the Start Bit, the individual bits of the word of data are sent, with the Least Significant Bit (LSB) being sent first. Each bit in the transmission is transmitted for exactly the same amount of time as all of the other bits, and the receiver looks at the wire at approximately halfway through the period assigned to each bit to determine if the bit is a 1 or a 0. For example, if it takes two seconds to send each bit, the receiver will examine the signal to determine if it is a 1 or a 0 after one second has passed, then it will wait two seconds and then examine the value of the next bit, and so on.
The sender does not know when the receiver has looked at the value of the bit. The sender only knows when the clock says to begin transmitting the next bit of the word.
When the entire data word has been sent, the transmitter may add a Parity Bit that the transmitter generates. The Parity Bit may be used by the receiver to perform simple error checking. Then at least one Stop Bit is sent by the transmitter.
When the receiver has received all of the bits in the data word, it may check for the Parity Bits (both sender and receiver must agree on whether a Parity Bit is to be used), and then the receiver looks for a Stop Bit. If the Stop Bit does not appear when it is supposed to, the UART considers the entire word to be garbled and will report a Framing Error to the host processor when the data word is read. The usual cause of a Framing Error is that the sender and receiver clocks were not running at the same speed, or that the signal was interrupted.
33
Regardless of whether the data was received correctly or not, the UART automatically discards the Start, Parity and Stop bits. If the sender and receiver are configured identically, these bits are not passed to the host.
If another word is ready for transmission, the Start Bit for the new word can be sent as soon as the Stop Bit for the previous word has been sent.
Because asynchronous data is self synchronizing, if there is no data to transmit, the transmission line can be idle.
8051 provides a transmit channel and a receive channel of serial communication. The transmit data pin (TXD) is specified at P3.1, and the receive data pin (RXD) is at P3.0. The serial signals provided on these pins are TTL signal levels and must be boosted and inverted through a suitable converter(MAX232 is used in my project) to comply with RS232 standard. All modes are controlled through SCON, the Serial control register. The SCON bits are defined as SM0, SM1, SM2, REN, TB8, RB8, TI, RI from MSB to LSB. The timers are controlled using TMOD, the Timer mode register, and TCON, the Timer control register.
34
Bit 7 SM0 0
Bit 6 SM1 1
Bit 5 SM2 0
Bit 4 REN 1
Bit 3 TB8 0
Bit 2 RB8 0
Bit 1 TI 0
Bit 0 RI 0
SM0 0 0 1 1
SM1 0 1 0 1
Mode 0 1 2 3
Mode 0
Each transmitted bit is valid on RXD pin for one machine cycle. Reception is initiated as soon as REN bit is set to 1 and the receive interrupt (RI) bit is cleared. Usually, REN is set at the beginning of the program to initialize the serial port, then RI is cleared to start a data input operation. As soon as RI is cleared, the shift clock will be produced on the TXD pin. At the beginning of the following machine cycle, data will be clocked in from the RxD line. After the 8th clocking cycle, the data is copied to SBUF and the RI bit is
35
set. It is up to the attached circuitry to provide data on RXD line synchronized by the clock signal on TXD. Receive and Transmit cannot be done at the same time.
Mode 1
Mode 1 is an 8-bit UART with variable baud rate. 10 bit data are transmitted on TXD or received on RXD. These consist of a start bit (always 0), eight data bits (LSB first) and stop bit (always 1). Baud rate is set by timer 1.
Transmission is initiated by writing to SBUF. The shifted data are outputted on the TXD line beginning with start bit and followed by eight bit data bits then stop bit. The transmit interrupt (TI) flag is set as soon as the stop bit appears on TXD.
Reception is initiated by a 1 to 0 transition on RXD (assuming REN is 1). The start bit is skipped and eight data bits are clocked into the serial port shift register. When all eight bits have been clocked in, the following occur:
36
Mode 2
Mode 2 is 9-bit UART with fixed baud rate. Eleven bits are transmitted or received: a start bit, eight data bits, a programmable ninth bit and a stop bit On transmission, the ninth bit is whatever has been put in TB8 in SCON. On reception, the ninth bit received is placed in RB8.
Mode 3
Mode 3 is 9-bit UART with variable baud rate. Mode 3 is same as Mode 2 except baud rate is programmable and provided by Timer 1
REN = 0 (Cleared by software) disable reception. REN = 1 (Set by software) enable reception
3) TB8 The 9th data bit that will be transmitted in Modes 2 and 3. Set or clear by software as desired.
4) SCON.2 / RB8 In modes 2 and 3, the 9th data bit that was received. In Mode 1, if SM2 = 0, RB8 is the stop bit that was received. In Mode 0, RB8 is not used.
37
Set by hardware at the end of the 8th bit time in Mode 0, or at the beginning of the stop bit in the other modes, in any serial transmission. It must be cleared by software.
Set by hardware at the end of the 8th bit time in Mode 0, or halfway through the stop bit time in the other modes, in any serial reception (except see SM2). It must be cleared by software.
Baud Rate Calculation The transmitting and receiving rate, which is called Baud rate, is controlled by Timer 1 at mode 1. The relation between Baud Rate and Timer1: 2 SMOD x (Osillator Frequency) 384 x (Baud Rate)
TH1 =
256
SMOD is the bit 7 of PCON, power control register. Set it equal to zero and, as I mention before, the oscillator frequency equal to 11.0592MHz, the equation become: 28800 Baud Rate
TH1 =
256
As the TH1 must be a positive value, the baud rate can only be 1200, 2400, 4800, 9600.
38
Baud Rate/bps 62.5K 19.2K 9.6K 4.8K 2.4K 1.2K 300 110
TH1 Value FFH FDH FDH FAH F4H E8H CCH 72H
Table 2.8 --- Relation between Baud Rate and TH1 register
In my program, I use 9.6Kbps Baud Rate and using Timer1 interrupt. The setting of the register becomes:
39
40
Equipment 1) A computer 2) A RS-232 cable 3) Testing Board for MCU with RS-232 interface 4) Testing Program --- PortTest V1.3 [5] Testing Setup
41
Signal Transmission
Signal Received
Procedure 1) Connect the Pin 11(TXD) of MCU to Pin 11 of MAX232 2) Connect the Pin 10(RXD) of MCU to Pin 12 of MAX232 3) Open the testing program PortTest V1.3 4) Connect power to the testing board 5) Connect the testing board and computer through RS-232 cable 6) Push the reset button 7) See whether the computer can receive a signal FFAAAA (hex). Where FF (hex) is the request command and AAAA (hex) is the maximum request number by Manchester Form 8) See whether the signal FFAAAA (hex) continue to send if there is no reply 9) Ask the program to send 5656 to the reader
42
10) Check whether the reader reply F05656 (hex). Where F0 (hex) is the SELECT command and 5656 (hex) is the received serial number without collision 11) Send again the 5656 (hex) immediately to the reader if F05656 (hex) is received. Check whether the reader replies 11(hex), the decoded serial number. 11) Repeats the procedure (9) - (11) by sending different Manchester Code 12) Repeat the procedure (9) by sending Manchester Code at different Bits, check whether it can detect the collision bit and perform specific action.
Result A) Receiving Manchester code without collision I have try several code: 5656, 69A6, 9AA5, A595, AA55
Code sent(hex)
Code sent(binary)
0101011001010110 11 0110100110100110 6D
43
Request Number 2
11
Request Number Sent (by the reader) 7FH BFH 5FH AFH 57H ABH 51H AAH
6
11
5
11
4
11
3
11
1
11
0
11
Sent (by the rule) 7FH BFH 5FH AFH 57H ABH 51H AAH
10
11
01
10
10
11
01
11
01
10
11
11
01
11
01
10
10
01
10
11
11
01
10
01
01
10
01
10
11
01
11
01
10
01
10
01
10
11
10
01
01
10
01
10
01
01
11
11
10
01
10
01
10
01
10
11
44
Equipment 1) A computer 2) A RS-232 cable 3) Testing Board for MCU with RS-232 interface 4) Testing Program --- PortTest V1.3 [5]
Testing Setup
45
Procedure 1) Connect the Pin 11(TXD) of MCU to Pin 11 of MAX232 2) Connect the Pin 10(RXD) of MCU to Pin 12 of MAX232 3) Open the testing program PortTest V1.3 4) Connect power to the testing board 5) Connect the testing board and computer through RS-232 cable 6) Push the reset button 7) Check the response by sending different commands
Result Setting the serial number of tag to 1F(hex) by program Command Request Number/ Select Number Larger than 1F(hex) REQUEST Smaller than 1F(hex) Equal to 1F(hex) Larger than 1F(hex) SELECT Smaller than 1F(hex) Equal to 1F(hex) Yes No Yes No No Yes Will not response to REQUEST and SELECT commands afterwards Still will response to REQUEST and SELECT commands afterwards Tag Reply Tag State
46
Reader
Or-Gate
Tag 1
Tag 2
Tag 3
47
Procedure 1) On the tags side, connect the output of OR-gate(74HC4075) to Pin 10 (RXD) of Reader MCU 2) Connect the Pin 11 (TXD) of Reader MCU to Pin 10 (RXD) of all Tag MCU 3) Connect the Pin 11 (TXD) of Reader to Pin 11 of MAX232 4) Connect the testing board for reader to computer through RS232 cable 5) Connect power supply for both testing board with same grounding 6) Push the reset button for tag board 7) Push the reset button for reader board 8) Check the reader whether it can recognize the serial number by four sets of serial number Serial number The first and second highest collision bit Bit 7 Bit 6
Set 1
Set 2
Set 3
Set 4
01111000 (78 H) 10110111 (B7 H) 11111000 (F8 H) 10001011 (8B H) 10100100 (A4 H) 10111101 (BD H) 11100111 (E7 H) 11101011 (EB H) 11101111 (EF H) 11001001 (C9 H) 11001010 (CA H) 11001011 (CB H)
Bit 5 Bit4
Bit 3 Bit 2
Bit 1 Bit 0
Table 3.4 --- Set of tags to test the reader system As the system can determine the serial number of the tags by the first two highest collision bits if there are only three tags in the environment, this testing procedure can confirm the reader have the ability due with collision condition at different bit.
48
Result Set 1 Tag 1 2 3 Serial Number 78 H B7 H F8 H Serial Number in Manchester Form 6A05 H 9A6A H AA95 H
FF AA AA
Select Signal with Maximum Request Number, all the tags will reply.
FF 6A AA
Tag 2 and Tag 3 will filter out as its serial number is larger.
F0 6A 05
Send the Select Signal to tag 1 with its serial number to make sure tag 1 will not response to select and request signal again.
78
Receive the Serial Number from tag 1 again. Convert to NRZ code and send to computer.
FF AA AA
Select Signal with Maximum Request Number, all the tags will reply except tag 1
FF 9A AA
49
F0 9A 6A
Send the Select Signal to tag 2 with its serial number to make sure tag 2 will not response to select and request signal again.
BF
Receive the Serial Number from tag 2 again. Convert to NRZ code and sending to computer.
FF AA AA
Select Signal with Maximum Request Number, but this time only tag 3 reply
F0 AA 95
Send the Select Signal to tag 3 with its serial number to make sure tag 3 will not response to select and request signal again.
F8
Receive the Serial Number from tag 3 again. Convert to NRZ code and sending to computer.
FF AA AA
Sending Select Signal with Maximum Request Number Continuously, because all the tags are selected so will not response to the select and request signal
50
Set 2 Tag 1 2 3 Serial Number 8B H A4 H BD H Serial Number in Manchester Form 959A H 9965 H 9AA6 H
FF AA AA
Select Signal with Maximum Request Number, all the tags will reply.
FF 96 AA
Tag 2 and Tag 3 will filter out as its serial number is larger.
F0 95 9A
Send the Select Signal to tag 1 with its serial number to make sure tag 1 will not response to select and request signal again.
8B
Receive the Serial Number from tag 1 again. Convert to NRZ code and send to computer.
FF AA AA
Select Signal with Maximum Request Number, all the tags will reply except tag 1
FF 99 AA
51
F0 99 65
Send the Select Signal to tag 2 with its serial number to make sure tag 2 will not response to select and request signal again.
A4
Receive the Serial Number from tag 2 again. Convert to NRZ code and sending to computer.
FF AA AA
Select Signal with Maximum Request Number, but this time only tag 3 reply
F0 9A A6
Send the Select Signal to tag 3 with its serial number to make sure tag 3 will not response to select and request signal again.
BD
Receive the Serial Number from tag 3 again. Convert to NRZ code and sending to computer.
FF AA AA
Sending Select Signal with Maximum Request Number Continuously, because all the tags are selected so will not response to the select and request signal
52
Set 3 Tag 1 2 3 Serial Number E7 H EB H EF H Serial Number in Manchester Form A96A H A99A H A9AA H
FF AA AA
Select Signal with Maximum Request Number, all the tags will reply.
FF A9 6A
Tag 2 and Tag 3 will filter out as its serial number is larger.
F0 A9 6A
Send the Select Signal to tag 1 with its serial number to make sure tag 1 will not response to select and request signal again.
E7
Receive the Serial Number from tag 1 again. Convert to NRZ code and send to computer.
FF AA AA
Select Signal with Maximum Request Number, all the tags will reply except tag 1
FF A9 9A
53
F0 A9 9A
Send the Select Signal to tag 2 with its serial number to make sure tag 2 will not response to select and request signal again.
EB
Receive the Serial Number from tag 2 again. Convert to NRZ code and sending to computer.
FF AA AA
Select Signal with Maximum Request Number, but this time only tag 3 reply
F0 A9 AA
Send the Select Signal to tag 3 with its serial number to make sure tag 3 will not response to select and request signal again.
EF
Receive the Serial Number from tag 3 again. Convert to NRZ code and sending to computer.
FF AA AA
Sending Select Signal with Maximum Request Number Continuously, because all the tags are selected so will not response to the select and request signal
54
Set 4 Tag 1 2 3 Serial Number C9 H CA H CB H Serial Number in Manchester Form A596 H A599 H A59A H
FF AA AA
Select Signal with Maximum Request Number, all the tags will reply.
FF A5 96
Tag 2 and Tag 3 will filter out as its serial number is larger.
F0 A5 96
Send the Select Signal to tag 1 with its serial number to make sure tag 1 will not response to select and request signal again.
C9
Receive the Serial Number from tag 1 again. Convert to NRZ code and send to computer.
FF AA AA
Select Signal with Maximum Request Number, all the tags will reply except tag 1
FF A5 99
55
F0 A5 99
Send the Select Signal to tag 2 with its serial number to make sure tag 2 will not response to select and request signal again.
CA
Receive the Serial Number from tag 2 again. Convert to NRZ code and sending to computer.
FF AA AA
Select Signal with Maximum Request Number, but this time only tag 3 reply
F0 A5 9A
Send the Select Signal to tag 3 with its serial number to make sure tag 3 will not response to select and request signal again.
CB
Receive the Serial Number from tag 3 again. Convert to NRZ code and sending to computer.
FF AA AA
Sending Select Signal with Maximum Request Number Continuously, because all the tags are selected so will not response to the select and request signal
56
57
Further Improvement 1) Adding Error Correction System: For example, Cyclic Redundancy Check (CRC) and Parity Checking This can make sure if the reader can recover the signal if which is missing or disturbed.
2) Bi direction transmission, After the computer gets the serial number of tags, it can order the tags to perform some function (e.g. switch on the light) by calling its serial number.
58
Cost Summary
Components Microcontroller Regulator Logic Gate Quartz Crystal Resistor Capacitor Value/Model AT89S52 MAX232 LT7805CV 74LS08 11.0592MHz 1k 1n 1uF 40uF DB9 Unit Cost/HKD 22 20 20 5 5 0.5 0.5 0.5 0.5 1.2 5 5 4 8 16 Number 1 1 1 1 1 1 1 4 2 1 1 1 Cost/HKD 22 20 20 5 5 1 0.5 2 1 1.2 5 5 5 32 16 140.7
59
Reference
[1] Steven Shepard RFID Radio Frequency Identification [2] ISO/IEC FDIS 18000-6:2003(E) [3] Klaus Finkenzeller RFID Handbook Fundamentals and Applications in Contactless Smart Cards and Identification [4] Manish Bhuptani, Shahram Moradpour RFID Field Guide - Deploying Radio Frequency Identification Systems [5] http://big5.china.com/gate/big5/download.china.com/soft/0900/0906/index.html
60
void putc(char c); void demanch(); void uart(unsigned short int a); void manch(unsigned short int manch_in); unsigned short int b[8], c[16]; unsigned short int a; int i, j=15, col, col_b, rec_data, rec_data_temp=0; unsigned short int bytedata[2]={0,0}; unsigned short int byte_rec=0; unsigned short int end=0;
void main() { unsigned short int con_sig=0xFF; int x, y, z; while(1) { P0_0=0; /*open transmission to tags*/ P0_1=1; byte_rec=0; rec_data=0; SCON = 0x50; /*uart in mode 1 (8 bit), REN=1*/ TMOD = 0x20; /* Timer 1 in mode 2*/ TH1 = 0xA0; /*300 Bds at 11.059MHz*/ TL1 = 0xA0; /*300 Bds at 11.059MHz*/ ES = 1; /*Enable serial interrupt*/ EA =1; /*Enable global interrupt*/ TR1 = 1; /*Timer 1 run*/
61
/*continue sending the request signal until reply*/ while((bytedata[0]==0&&bytedata[1]==0)||(bytedata[0]==1&&bytedata[1]==1)) { putc(0xFF); /*Request command*/ manch(con_sig); /*Request Number*/ for(x=0; x<300; x++) /*wait 0.3 second*/ for(y=0; y<10;y++) for(z=0; z<120; z++); } demanch(); /*Manchester Decode*/
if (col==1) /*If collision occur*/ { switch(col_b) /*Setting the request number for specific collision*/ { case 7: con_sig=0x7F; break; case 6: con_sig=0x3F; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 5: con_sig=0x1F; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 4: con_sig=0x0F; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break;
62
case 3: con_sig=0x07; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 2: con_sig=0x03; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 1: con_sig=0x01; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 0: con_sig=0; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; default: con_sig=0xFF; } } else /*if no collision occur*/ { rec_data_temp=rec_data; con_sig=0xFF; byte_rec=0; rec_data=0; putc(0xF0); /*send the SELECT signal*/ manch(rec_data_temp); for(x=0; x<300; x++) /*delay 0.3 seconds*/ for(y=0; y<10; y++) for(z=0; z<120; z++); demanch();
63
/*send to computer if the serial number received is same as before*/ if (rec_data_temp==rec_data) { P0_0=1; P0_1=0; putc(rec_data); } } } }
void putc(char c) /*send 8bit number through UART*/ { SBUF=c; while(!TI); TI=0; }
void demanch() /*Manchester Decoding*/ { j=15; rec_data=0; col=0; col_b=0; for (i=15; i>=8; i--) { c[i] = (int)(bytedata[0]/pow(2, (i-8))); bytedata[0] = bytedata[0]%(int)(pow(2, (i-8))); } for (i=7; i>=0; i--) { c[i] = (int)(bytedata[1]/pow(2, i)); bytedata[1] = bytedata[1]%(int)(pow(2, i)); }
64
for (i=7; i>=0; i--) { if (c[j]==1) { if (c[j-1]==0) { b[i]=1; j=j-2; } else /*collision occur*/ { col=1; col_b=i; break; } } else { if (c[j-1]==1) { b[i]=0; j=j-2; } else /*collision occur*/ { col=1; col_b=i; break; } } } if (col==0) { for (i=7; i>=0; i--) rec_data = rec_data + (int)(b[i]*pow(2, i)); } bytedata[0]=0; bytedata[1]=0;
65
void manch(unsigned short int manch_in) /*Manchester Coing*/ { j=15; for (i=7; i>=0; i--) { b[i] = (int)(manch_in/pow(2, i)); manch_in = manch_in%(int)(pow(2, i)); } for (i=7; i>=0; i--) { if (b[i]==1) { c[j]=1; c[j-1]=0; j=j-2; } else { c[j]=0; c[j-1]=1; j=j-2; } } a=0; for (j=15; j>=0; j--) { a=a+c[j]*(pow(2, j)); } uart(a); }
66
void uart(unsigned short int a) /*send 16bits signal through UART*/ { SBUF = (a>>8); while(TI!=1); TI = 0; SBUF = a; while(TI!=1); TI = 0; }
67
Tag Program:
#include <stdio.h> #include <math.h> #include <regx51.h> void demanch(); void uart(unsigned short int a); void manch(unsigned short int manch_in); void putc(char c); int b[8], i, j=15, k, c[16]; int col, col_b; int rec_data; int bytedata[3]=(0,0,0); int byte_rec=0; int end=0;
void main() { unsigned short int sn=0xCB; int mode=1; P0_0=1; SCON=0x50; TMOD=0x20; TH1=0xA0; TL1=0xA0; ES=1; EA=1; TR1=1;
/*open the transmission*/ /*UART in mode 1 (8 bit), REN=1*/ /*Timer 1 in mode 2*/ /*300 Bds at 11.059MHz*/ /*300 Bds at 11.059MHz*/ /*Enable serial interrupt*/ /*Enable global interrupt*/ /*Timer 1 run*/
while (mode==1) { do{ }while(end==0); /*Wait Command*/ P0_0=1; /*open the transmission*/
68
if (bytedata[0]==0xF0) /*if SELECT command received*/ { demanch(); if (sn==rec_data) { P0_0=1; manch(sn); P0_0=0; mode=2; /*enter mode 2, not response to SEL and REQ command*/ } else /*if the serial number received before and after the SEL signal sent not the same, set the transmission close. { P0_0=0; manch(sn); P0_0=1; } bytedata[3]=(0,0,0); byte_rec=0; end=0; } else if (bytedata[0]==0xFF) /*if REQUEST command received*/ { demanch(); if(sn<=rec_data) /*for the case serial number small then the REQ signal, reply*/ { P0_0=1; manch(sn); } else /*for the case serial number larger then the REQ signal, reply*/ P0_0=0; /*close the transmission*/ bytedata[3]=(0,0,0); byte_rec=0; end=0; } }
69
while(mode==2) /*After receiving the select signal*/ { do{ }while(end==0); if (bytedata[0]==0xFF) /*if received a request signal, close the transmission, dont disturb the other*/ { demanch(); if(sn<=rec_data) { P0_0=0; manch(sn); } else P0_0=0; bytedata[3]=(0,0,0); byte_rec=0; end=0; } }
70
void demanch() /*Manchester Decoding*/ { j=15; rec_data=0; col=0; col_b=7; for (i=15; i>=8; i--) { c[i] = (int)(bytedata[1]/pow(2, (i-8))); bytedata[1] = bytedata[1]%(int)(pow(2, (i-8))); } for (i=7; i>=0; i--) { c[i] = (int)(bytedata[2]/pow(2, i)); bytedata[2] = bytedata[2]%(int)(pow(2, i)); }
71
for (i=7; i>=0; i--) { if (c[j]==1) { if (c[j-1]==0) { b[i]=1; j=j-2; } else { col=1; col_b=i; break; } } else { if (c[j-1]==1) { b[i]=0; j=j-2; } else { col=1; col_b=i; break; } } }
72
void manch(unsigned short int manch_in) /*Manchester Coding*/ { unsigned short int a; j=15; for (i=7; i>=0; i--) { b[i] = (int)(manch_in/pow(2, i)); manch_in = manch_in%(int)(pow(2, i)); } for (i=7; i>=0; i--) { if (b[i]==1) { c[j]=1; c[j-1]=0; j=j-2; } else { c[j]=0; c[j-1]=1; j=j-2; } } a=0; for (j=15; j>=0; j--) { a=a+c[j]*(pow(2, j)); } uart(a); }
73
void uart(unsigned short int a) /*send 16 bits signal through UART*/ { SBUF = (a>>8); while(TI!=1); TI = 0; SBUF = a; while(TI!=1); TI = 0; }
74
Photo of Circuit
Appendix
76
77
78
79
80
81