ST AN3255 Application note

AN3255
Application note
Building an RFID short-range reader
using the STM8S-DISCOVERY
Application overview
High frequency 13,56 MHz RFID solutions offer ideal close-proximity identification for product authentication, parcel tracking, document management, library and ticketing applications.
This application note describes how to build an RFID (radio frequency identification) short­range reader using STMicroelectronics STM8S-DISCOVERY and ISO14443 type-B CR14 contactless coupler. The STM8S-DISCOVERY and the CR14 communicate through an I bus.
The resulting RFID reader can exchange data with ISO 14443-2 type-B proximity PICCs (proximity integrated coupling cards) also called tags. Communications are possible only when the tags are present in the electromagnetic field generated by the reader built-in antenna.
Once the STM8S-DISCOVERY is powered up through a USB cable connected to the host PC, an electromagnetic field is generated by the RFID reader. A beep is emitted and the LED LD1 briefly lights up when an ISO 14443-2 type-B proximity tag is detected by the reader and its unique identifier (UID) successfully read.
2
C
The STM8S-DISCOVERY can be used to evaluate the main features of all STM8S MCUs, even if it is built on an STM8S105C6T6.
Reference documents
STM8S-DISCOVERY evaluation board user manual (UM0817).
Developing and debugging your STM8S-DISCOVERY application code (UM0834).
User manual “CR14 and CRX14 reference design PCB Gerber files” (UM0672) and RFID
Gerber files.
CR14 datasheet: “Low cost ISO14443 type-B contactless coupler chip with anti-collision
and CRC management”
SRI2K datasheet: “13,56 MHz short-range contactless memory chip with 2048 bit
EEPROM and anti-collision functions”
Application note “Antenna (and associated components) matching-circuit calculation of
the CRX14 coupler” (AN1806)
Application note “How to design a 13.56 MHz customized antenna” (AN2866)
These documents can be downloaded from http://www.st.com.
October 2010 Doc ID 17784 Rev 1 1/24
www.st.com
Contents AN3255
Contents
1 Application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Short-range contactless communication principles . . . . . . . . . . . . . . . . . . 6
1.2.1 CR14 contactless coupler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.2 I
1.2.3 Reader-tag protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.4 Commands and tag states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3 Hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.4 Application schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2 STM8S-DISCOVERY configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.1 Power supply configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2
C polling using Ack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Option byte configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3 Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.1 STM8S peripherals used by the application . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Configuring the STM8S standard firmware library . . . . . . . . . . . . . . . . . . 15
3.3 Application principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Appendix A I2C memory addressing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Appendix B I2C Read and Write functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
B.1 I2C Page Write flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
B.2 I
2
C post polling buffer read flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2/24 Doc ID 17784 Rev 1
AN3255 List of tables
List of tables
Table 1. CR14 control registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Table 2. List of PCB passive components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 3. List of PCB packaged components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Table 4. List of tag packaged components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Table 5. List of other passive components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Table 6. TAG commands used within this application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Table 7. Device Select code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Table 8. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Doc ID 17784 Rev 1 3/24
List of figures AN3255
List of figures
Figure 1. Short range RFID reader solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 2. Ack Polling flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 3. TAG state transition diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 4. Contactless RFID reader schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 5. Main application loop flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Figure 6. I Figure 7. I
2
C Page Write flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2
C post polling buffer read flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4/24 Doc ID 17784 Rev 1
AN3255 Application description

1 Application description

1.1 Overview

This application is built around a short range RFID reader PCB developed by STMicroelectronics. The PCB Gerber files and the user manual "CR14 and CRX14 reference design PCB Gerber files" (UM0672) are available from http://www.st.com.
This board is designed to be connected to a digital host, in this case an STM8S­DISCOVERY, which manages data transmission and reception through an I (see Figure 1).
The tags supported by this application must be based on ST contactless memories compliant with ISO 14443 part2 type-B standard for the radio-frequency power and signal interface.
This application has been tested using a tag based on ST SRI2K short range contactless EEPROM. Refer to application note AN2866 explaining how to design a 13.56 MHz tag antenna.
Figure 1. Short range RFID reader solution
Resistors
TS1
GPIO's
LD1
Buzzer
USB
STLINK
SWIM
5V
3V3
STM8S105C6T6
SO16
footprint
2
C interface
RP1
RP2
I2C bus
J1
HE10
STMicroelectronics
CR14
STM8S-DISCOVERY
RFID reader PCB
Doc ID 17784 Rev 1 5/24
Application description AN3255

1.2 Short-range contactless communication principles

1.2.1 CR14 contactless coupler

The CR14 is the main component of the RFID reader PCB. It interfaces with the following components:
The contactless tags
The data frames exchanged with the tags are compliant with ISO14443 type-B radio frequency protocol. Data are stored in the CR14 input/output Frame registers (see
Table 1: CR14 control registers).
The STM8S105C6T6 through the I
The CR14 is organized as 4 functional blocks:
The I²C bus controller
It handles the serial connection with the STM8S105C6 application host, and controls the read/write accesses to all CR14 registers. It is compliant with the 400 KHz I specification.
The RAM buffer
The RAM buffer is bidirectional. It stores all the request frame bytes to be transmitted to the tag, plus all the received bytes sent back by the tag on the answer frame.
The transmitter
It powers the tag by generating a 13,56 MHz signal on an external antenna. The resulting field is 10% modulated using ASK (amplitude shift keying) modulation to transmit data.
The receiver
It demodulates the signal generated on the antenna by the load variation of the tag. The resulting signal is decoded by an 847 KHz BPSK (binary phase shift keying) sub­carrier decoder.
2
C bus.
2
C bus
The CR14 generates an electromagnetic field which is rectified to power the tag. The reader transmits information to the tag by modulating the carrier wave. To transmit information back to the reader, the tag backscatters the carrier wave by modifying its own impedance thereby perturbing the field.
The CR14 chip contains six volatile registers of which three allow to configure the CR14 and to transmit/receive frames to/from the tag (see Ta bl e 1 ):
Parameter register
Input/Output Frame register
Slot Marker register
For details regarding registers description and CR14 I datasheet.
Table 1. CR14 control registers
Address Description Access Purpose
00h Parameter register 1 byte
6/24 Doc ID 17784 Rev 1
2
C protocol, refer to the CR14
W Set parameter register
R Read parameter register
AN3255 Application description
Table 1. CR14 control registers (continued)
Address Description Access Purpose
Store and send request
01h
02h ST reserved N/A
03h Slot Marker register 1 byte
04h ST reserved N/A R and W
Input/Output Frame register
36 bytes
W
R
W
R
W
R Return FFh
frame to the tag. Wait for tag answer frame
Transfer tag answered frame data to host
ST reserved, must not be used
Launch the automated anti­collision process from Slot_0 to Slot_15
ST reserved, must not be used
05h ST reserved N/A R and W

1.2.2 I2C polling using Ack

During radio frequency data exchange, the CR14 disconnects itself from the I2C bus. The time needed to complete the exchange is not fixed as it depends on the tag command format. To know when the exchange is complete before starting reading the data in the Input/Output Frame register, the bus master uses an Ack polling sequence that performs the following actions:
1. Initial condition: a radio frequency data exchange is in progress.
2. Step 1: the master issues a START condition followed by the first byte of the new instruction (Device Select Code plus R/W bit = 1) (see Appendix A: I2C memory
addressing).
3. Step 2: if the CR14 is busy, no Ack is returned and the master goes back to Step 1. If the CR14 has completed the radio frequency data exchange, it responds by sending back an ACK, thus indicating that it is ready to receive the second part of the next instruction (the first byte of this instruction has been sent during Step 1).
Figure 2 shows the detailed I²C Ack polling flowchart.
ST reserved, must not be used
Doc ID 17784 Rev 1 7/24
Application description AN3255
2ADIO&REQUENCY
DATAEXCHANGE
INPROGRESS
3END
34!24CONDITION
3END#2
$EVICE3ELECT
#ODEWITH27
!#+
RETURNED
./
2EADDATABYTES
FROM#2
9%3
#2)£#
DISCONNECTED
AI
Figure 2. Ack Polling flowchart

1.2.3 Reader-tag protocol

Standard tag commands such as Read and Write are generated by the CR14 using its Input/Output Frame register. To send a command to the tag, the STM8S105C6 host first generates internally the complete frame containing the command code followed by the command parameters (if required). Only the 2 CRC bytes must not be generated as the CR14 automatically adds them during the RF transmission.
Once the frame is ready, the host writes it into the Input/Output Frame register using an I Write command.
If the tag answers, the characters received are demodulated, decoded and stored into the input/output frame buffer. During the entire RF transmission, the CR14 disconnects itself from the I the I
2
C bus. On reception of the tag EOF, the CR14 checks the CRC and reconnects to
2
C bus. The host can then get the tag answer frame by issuing an Input/Output Frame
Register Read command on the I
Refer to the CR14 datasheet for details on Read and Write commands.

1.2.4 Commands and tag states

The tag can be switched into different states (see Figure 3). The tag only answers specific commands depending on its current state. These states are specified by the ISO 15693 standard. For details concerning these states, refers to one of ST short range contactless EEPROM datasheet (for example SRI2K) available from http://www.st.com.
2
C bus.
2
C
8/24 Doc ID 17784 Rev 1
Loading...
+ 16 hidden pages