CR95HF library for ISO/IEC 14443-3 and SRIX contactless tag ICs
1 Introduction
This document describes the ISO/IEC 14443-3 libraries used by a microcontroller to drive
the CR95HF 13.56 MHz multiprotocol contactless transceiver using an SPI or UART
interface in order to perform wireless communications with ISO/IEC 14443 Type A or B
contactless tag.
The library was developed to speed up the development of applications using the CR95HF.
The CR95HF library is composed of three layers:
■ CR95HF low level layer
■ Standard ISO/IEC 14443-3 protocol layer (type A and type B)
■ SRIX4K product specific layer
The library code has been developed in ANSI C language, and validated on an STM32
evaluation board.
SRIXShort Range Interface with anti clone function
UIDUnique Identifier
WUPAWake-Up A command Type A
WUPBWake-Up A command Type B
XOReXclusif OR
Doc ID 022017 Rev 19/68
Acronyms and notational conventionsAN3955
2.2 Notational conventions
The following conventions and notations apply in this document unless otherwise stated.
2.2.1 Binary number representation
Binary numbers are represented by strings of digits 0 and 1 shown with the Most Significant
Bit (MSB) on the left, the Least Signifcant Bit (LSB) on the right, and “0b” added at the
beginning.
For example: 0b11110101
2.2.2 Hexadecimal number representation
Hexadecimal numbers are represented by using the numbers 0 to 9, the characters A - F,
and a “0x” added at the beginning. The Most Significant Byte (MSB) is shown on the left and
the Least Significant Byte (LSB) on the right.
For example: 0xF5
2.2.3 Decimal number representation
Decimal numbers are represented as is, without any trailing character.
For example: 245
10/68Doc ID 022017 Rev 1
AN3955Overview
AI18873a
ISO15693 RF
MCU
CR95HF
Contactless tag
CR95HF
library
14443 type A
Or
14443 type B
13,56 MHz RF commands
3 Overview
3.1 CR95HF overview
The CR95HF is a Radio Frenquency (RF) transceiver Integrated Circuit (IC) for 13.56 MHz
contactless tags, which includes ISO/IEC 14443, ISO/IEC 15693 and ISO/IEC 18092
protocols. It manages the RF communication with Radio Frequency Identification (RFID) or
Near Field Communication (NFC) tags. It includes trame coding, RF modulation and
contactless tag response decoding.
The CR95HF is a slave device and must be controlled by a host (Microcontroller Unit). This
library is an interface between user application function and standard peripheral driver.
The library was written in compliance with ANSI C standards.
Figure 1 describes a typical application block diagram.
Figure 1.Typical application block diagram
For more details concerning the CR95HF, please refer to CR95HF datasheet.
3.2 ISO/IEC 14443-3 overview
The ISO/IEC 14443-3 is a standard, which specifies two different RF protocols (Type A and
Type B). It describes low-level functions allowing to handle one ore more contactless tags.
As an example, the ISO/IEC 14443-3 commands can be used to read the Unique Identifier
(UID) or to perform anti-collision.
The higher level commands to read or write the user memory of contactless tags are not
described in ISO/IEC 14443-3 specifications. These commands are defined in the
contactless datasheet. For instance, the SRIX4K datasheet defines Read, Write and other
specific commands.
For more information about Read, Write or other commands, refer to the SRIX4K datasheet.
Since the frames coding specified by ISO/IEC 14443 Type A differ from Type B, the CR95HF
cannot communicate with an ISO/IEC 14443 Type A and an ISO/IEC 14443 Type B
contactless tag at the same time.
Doc ID 022017 Rev 111/68
OverviewAN3955
MS19951V1
User functions
(user application specific)
Standard peripheral driver
(MCU specific layer)
CR95HF library
CR95HF library layer
(integrates the commands defined in CR95HF datasheet)
Protocol layer (embeds commands defined in the ISO/IEC 14443-3 specification)
ISO14443_3 type A library layerISO14443_3 type B library layer
Product layer (embeds commands defined in the product datasheet)
SRiX4K layer
3.3 SRIX4K product overview
The SRIX4K is an STMicroelectronics contactless tag powered by an RF field. It contains
a 4-kbit EEPROM memory that can be accessed by using RF commands.
For more information about low-level commands to handle a tag and an upper level to read,
write or lock memory, refer to the SRIX4K datasheeet.
SRIX4K is compliant with ISO/IEC 14443-3 Type B frame format specification.
3.4 Library overview
The library described in this application note is composed of three layers:
●A low-level layer supporting the commands described in the CR95HF datasheet. This
level is fully supported by the CR95HF library.
●An intermediate layer based on the ISO/IEC 14443-3 protocol. This layer is divided in
two files, one for Type A and another for Type B.
●An upper layer supporting the commands described in the SRIX4K datasheet.
The library can be downloaded from STMicroelectronics internet site at http://www.st.com.
Figure 2 shows an example of application architecture and describes the interaction
between a typical user application and the CR95HF library layers.
Figure 2.Interaction between typical user application and CR95HF library layers
12/68Doc ID 022017 Rev 1
AN3955CR95HF low level layer
4 CR95HF low level layer
For a brief description of CR95HF, refer to Section 3.1: CR95HF overview.
This layer is composed of:
●the lib_CR95HF.c source file
●the lib_CR95HF.h include file
4.1 Types
The CR95HF library functions use the following ANSI C compliant types:
typedefunsigned charuint8_t;
typedefsigned charint8_t;
typedefconst uint8_tuc8;
typedefsigned short intint16_t;
4.2 Definition
The layer supports all the commands defined in the CR95HF datasheet. Each CR95HF
command corresponds to a specific function. As an example, the function calling the ECHO
command is int8_t CR95HF_Echo (uint8_t *pResponse).
Additional functions are described in Table 3: CR95HF layer additional functions.
Application developers can use the functions described in Table 2: CR95HF layer functions
based on CR95HF commands to create their own higher level functions.
For more details about commands, refer to the CR95HF datasheet.
Doc ID 022017 Rev 113/68
CR95HF low level layerAN3955
4.3 CR95HF layer functions
The tables below introduce the functions available in the CR95HF layer.
.
Table 2.CR95HF layer functions based on CR95HF commands
Function nameBrief description
Sends an IDN command to CR95HF device. It returns its version
CR95HF_IDN
CR95HF_Echo
CR95HF_ProtocolSelect
CR95HF_SendRecv
CR95HF_Idle
CR95HF_RdReg
CR95HF_BaudRate
number. For more details about CR95HF_IDN function, refer to
Section 4.4: IDN function.
Sends an Echo command to CR95HF device which returns an Echo
response. The Echo function checks if communications can be
started between the MCU and the CR95HF. For more details about
CR95HF_Echo function, refer to Section 4.5: ECHO function.
Sends a ProtocolSelect command to CR95HF device. It selects the
RF communication protocol, configures RF parameters and switches
the RF field on. For more details about CR95HF_ProtocolSelect
function, refer to Section 4.6: ProtocolSelect function.
Sends a SendRecv command. The parameter sent to the command
is the frame which is coded according to the protocol previously
selected by issuing a ProtocolSelect command. For more details
about CR95HF_SendRecv function, refer to Section 4.7: SendRecv
function.
Sends an Idle command to the CR95HF device to switch it into low
consumption mode. For more details about CR95HF_Idle function,
refer to Section 4.8: Idle function.
Sends a ReadRegister command to the CR95HF device to read the
CR95HF internal register. For more details about CR95HF_RdReg
function, refer to Section 4.9: RdReg function.
Sends a Baudrate command to the CR95HF device. It changes the
CR95HF UART baudrate. For more details about
CR95HF_BaudRatefunction, refer to Section 4.10: BaudRate
function.
14/68Doc ID 022017 Rev 1
AN3955CR95HF low level layer
.
Table 3.CR95HF layer additional functions
Function nameBrief description
Sends an RF pulse (EOF). For more details about
CR95HF_SendEOF
CR95HF_FieldOff
CR95HF_HexCommandToStringCommand
CR95HF_GetReaderErrorCode
CR95HF_IsReaderResultCodeOk
CR95HF_IsReaderErrorCode
CR95HF_IsCommandExists
CR95HF_SendEOF function, refer to Section 4.11:
SendEOF function.
Switches off the RF field. For more details about
CR95HF_FieldOff function, refer to Section 4.12:
FieldOff function.
Translates hexadecimal command code to command
name. It returns the ASCII code of the command. For
more details about
CR95HF_HexCommandToStringCommand function,
refer to Section 4.13: HexCommandToStringCommand
function.
Translates hexadecimal error code to error code
description. It returns a description of the error
contained in the ReaderReply parameter. For more
details about CR95HF_GetReaderErrorCode, refer
to Section 4.17: GetReaderErrorCode function.
Checks if returned code is a successful code. It returns
CR95HF_SUCCESS_CODE if the CR95HF command is
successful. For more details about
CR95HF_IsReaderResultCodeOk function, refer to
Section 4.14: IsReaderResultCodeOk function.
Checks if returned code is an error code. It returns
CR95HF_SUCCESS_CODE value if the CR95HF
command has returned an error code. For more details
about CR95HF_IsReaderErrorCode function, refer
to Section 4.15: IsReaderErrorCode function.
Checks if command is available. It returns
CR95HF_SUCCESS_CODE if the CmdCode value
exists. For more details about
CR95HF_IsCommandExists function, refer to
Section 4.16: IsCommandExists function.
Doc ID 022017 Rev 115/68
CR95HF low level layerAN3955
4.4 IDN function
The CR95HF_IDN function sends an IDN command to the CR95HF device.
Table 4.CR95HF_IDN function description
Prototype
Input parameterNone
Output parameterpResponse: Pointer to CR95HF response
Return parameterCR95HF_SUCCESS_CODE: Function is successful.
result = int8_t CR95HF_IDN (uint8_t *pResponse)
4.5 ECHO function
The CR95HF_Echo function sends an ECHO command to the CR95HF device.
Table 5.CR95HF_Echo function description
Prototype
Input parameterNone
Output parameterpResponse: Pointer to CR95HF response
result = int8_t CR95HF_Echo (uint8_t *pResponse)
Return parameterCR95HF_SUCCESS_CODE: Function is successful.
4.6 ProtocolSelect function
The CR95HF_ProtocolSelect function sends a ProtocolSelectcommand to the CR95HF
device.
To set up communications with a contactless tag, the ProtocolSelect command must be sent
to the CR95HF before the SendRecv commands.
Table 6.CR95HF_ProtocolSelect function description
Prototype
Input parameter
Output parameterpResponse: Pointer to CR95HF response
Return parameter
1. ISO/IEC 15693, ISO/IEC 18092, ISO/IEC 14443-3 Type A or Type B RF protocols.
result = int8_t CR95HF_ProtocolSelect(uc8
Length,uc8 Protocol,uc8 *Data,uint8_t *pResponse)
Length: Number of data bytes
Protocol: Type of protocol
Data input:Pointer to data
CR95HF_ERRORCODE_PARAMETER: Function failed
CR95HF_SUCCESS_CODE: Function is successful.
CR95HF_ERRORCODE_PARAMETERLENGTH: Parameter length is
incorrect.
(1)
The Data input parameter depends on the selected protocol. This application note applies to
ISO/IEC 14443-3 Type A and ISO/IEC 14443-3 Type B products.
16/68Doc ID 022017 Rev 1
AN3955CR95HF low level layer
Ta bl e 7 describes the ProtocolSelect command in ISO/IEC 14443-3 Type A case.
Table 7.CR95HF_ProtocolSelect ISO/IEC 14443-3 Type A protocol parameter
Parameter name ByteBitValue Example
Command Code
Length
Protocol
Parameter
1. Optional. If not specify default FWT~86 µs
2. PP <= 0x0E and 0x01 <= MM <= 0xFE
07:00x020x02020200
17:00x02
27:0
37:6
5:4
3:0
5:47:0
0x02
protocol
Transmission data rate
Reception data rate
RFU
FWT= (256*16/fc)*(2*PP)*(MM+1)
where “PP” represents byte 4 and “MM”
byte 5.
: ISO/IEC 14443-3 Type A
ISO/IEC 14443-3 Type
A with reception and
transmission data
rates at 106 kbps
(1) (2)
Ta bl e 8 describes the ProtocolSelect command in ISO/IEC 14443-3 Type B case.
Table 8.CR95HF_ProtocolSelect ISO14443-3 Type B protocol parameter
Parameter name ByteBitValue Example
Command Code
Length
Protocol
07:0 0x020x02020301
17:0 0x02
27:0
37:6
0x03
Transmission data rate
: ISO/IEC 14443-3 Type B protocol
ISO/IEC 14443-3 Type
B with reception and
transmission data
rates at 106 kbps
Reception data rate
5:4
RFU
3:0
Append CRC
Parameter
5:47:0
1. Optional. If not specify default FWT~300µs.
2. PP <= 0x0E and 0x01 <= MM <= 0xFE
0
1: CR95HF appends CRC
0: CR95HF does not append CRC
FWT= (256*16/fc)*(2*PP)*(MM+1)
where “PP” represents byte 4 and “MM”
byte 5.
Doc ID 022017 Rev 117/68
(1) (2)
The CR95HF
manages the CRC.
CR95HF low level layerAN3955
4.7 SendRecv function
The CR95HF_SendRecv function sends a SendRecv command. The CR95HF encodes the
frame, transmits it at 13.56 MHz, and decodes the contactless tag response.
The contactless tag response is then sent back in the pResponse parameter.
Table 9.CR95HF_SendRecv function description
Prototype
result = int8_t CR95HF_SendRecv (uc8
Length,uc8 *Parameters,uint8_t *pResponse)
Input parameter
Output parameterpResponse : Pointer to CR95HF response
Return parameter
Length: Number of bytes in Parameters input
Parameters input: Pointer to data
CR95HF_ERRORCODE_PARAMETER: Function failed
CR95HF_SUCCESS_CODE: Function is successful.
CR95HF_ERRORCODE_PARAMETERLENGTH: Parameter
length is incorrect.
The Parameters input depends on the selected protocol. This application note applies to
ISO/IEC 14443-3 Type A and ISO/IEC 14443-3 Type B products.
Ta bl e 1 0 describes the SendRecv command in ISO/IEC 14443-3 Type A case.
Table 10.SendRecv command in ISO/IEC 14443-3 Type A case
Parameter nameByteBitValue CommentsExample
Command Code
Length
Data
07:00x04
17:00xXX
2:X7:00xXX
X+17
-RFU
60b0
Number of Data
bytes and
transmission flag
Data
Split frame
-
REQA command:
0x04022607
26:
Data (REQA
command code)
07:
number
of significant bits
(REQA is coded on 7
bits)
with
1: CR95HF
5
appends CRC
Transmission flag
0: CR95HF
does not
append CRC
40b0
3:0
18/68Doc ID 022017 Rev 1
0xX
Append CRC
RFU
Number of
significant bits
AN3955CR95HF low level layer
Ta bl e 1 1 describes the SendRecv command in ISO/IEC 14443-3 Type B case.
Table 11.SendRecv command in ISO/IEC 14443-3 Type B case
Parameter nameByteBitValue CommentsExample
Command Code
Length
Data
07:00x04
17:00xXX
2:X7:00xXX
Length of entire
data
Data
-
REQB command:
0x040305000
For more information, refer to CR95HF datasheet.Ta ble 12 describes the CR95HF success
response value for ISO/IEC 14443-3 Type A.
Table 12.CR95HF success response value for ISO/IEC 14443-3 Type A
Parameter
name
Result
Code
Length
Data
Byte BitValueCommentsExample
07:0 0x04
17:0 0xXX
2:X 7:0 0xXX
X+17
1: CR95HF has
detected a collision
0: No collision detected
60
Success code
Number of bytes of Data
+ control bytes
Contactless tag response
Collision between two
contactless tag
responses
RFU
0X80054400280000
where:
80: success
05: Number of bytes
4400: ATQA
28: CRC error
Number of significant
bits: 8
00 00: No collision
detected
(1)
&
1: CRC error
5
0: No CRC error
1: Parity error
4
Control
bytes
0: No Parity error
3:0
X+2 7:0 0xXX
X+3 7:4 0b000
3:0 0bXXXX
1. CRC error bit is set but there is no CRC on ATQA response. So this bit is not significant.
2. Since the ISO/IEC 14443-3 Type A is a bit-oriented protocol, CR95HF can receive a non integer amount of
bytes.
3. To calculate the point of collision between two contactless tag responses, the user application must refer to
the control bytes. The byte where the collision is detected is indicated by Control Byte X+2 (Index of first
byte), and the specific bit in the byte where the collision is detected is indicated by Control Byte X+3 (Index
of first bit). Both indices start from 0 and the bit index can be 8, meaning that the collision affected parity.
This information is only valid if the Collision Dectected bit (Bit 7 of control Byte X+1) is set.
CRC error on contactless
response
Parity error on
contactless response
Number of significant bits
in the first byte
Index of the first byte
where the collision is
detected
RFU
Index of the first bit where
the collision is detected
(2)
(3)
Doc ID 022017 Rev 119/68
CR95HF low level layerAN3955
CR95HF returns a specific correct code for ACK or NAK contactless response, coded on 4
bits, as described in Tabl e 1 3.
Table 13.Specific success code for ACK or NAK contactless response
Parameter nameByteBitValue Comments
Result Code
Length
07:00x90
17:00x04
Success code
Number of valid bits: 4
2:X7:00x01: NAK
Data
0x05: NAK
Contactless tag response
0x0A: ACK
Ta bl e 1 4 describes the CR95HF success response value for ISO/IEC 14443-3 Type B.
Table 14.CR95HF success response value for ISO/IEC 14443-3 Type B
Parameter
name
Result Code
Length
Data
ByteBitValueCommentsExample
07:0 0x80
17:0 0xXX
2:X7:0 0xXX
X+17:2 0b0000
Success code
Number of bytes of
Data + control bytes
Contactless tag
response
RFU
0x800F50AA0B000500
000000B371716A2100
where:
80: Success
0F: Number of byte
50AA0B000500000000
B371716A21:
ATQB
00: CRC Ok
Control
bytes
11: CRC error
0: no CRC error
CRC error or
contactless
response
0
-RFU
For more information, refer to CR95HF datasheet.
If CR95HF_SendRecv function fails, the CR95HF returns an error code in the pResponse
parameter (see Ta bl e 1 5 ). As an example, if no contactless tag is present in the RF field, the
CR95HF response is 0x8700.
Table 15.CR95HF error response value for ISO/IEC 14443-3 Type A and B
Parameter nameByteBitValueExample
Result code
Length
07:00x08
17:00x00
For more information about CR95HF error code, refer to CR95HF datasheet.
20/68Doc ID 022017 Rev 1
0x8700
tag in the field
: no contactless
AN3955CR95HF low level layer
4.8 Idle function
This function sends an Idle command to the CR95HF to switch the CR95HF device into low
consumption mode. Ta b le 1 6 describes the CR95HF_Idle function.
Table 16.
Prototype
Input parameter
Output parameterpResponse : Pointer to the CR95HF response
Return parameter
CR95HF_Idle function description
result = int8_t CR95HF_Idle(uc8
Length,uc8 *Data,uint8_t *pResponse);
Length: Number of data bytes
Data: Pointer to data
CR95HF_ERRORCODE_PARAMETER: Function failed
CR95HF_SUCCESS_CODE: Function is successful.
CR95HF_ERRORCODE_PARAMETERLENGTH:
Parameter length is incorrect.
4.9 RdReg function
This function sends an RdReg command to the CR95HF in order to read the CR95HF
internal register. Ta ble 17 describes the CR95HF_RdReg function.
Table 17.CR95HF_RdReg function description
result = int8_t CR95HF_RdReg(uc8
Prototype
Input parameter
Output parameterpResponse : Pointer to CR95HF response
Return parameterCR95HF_SUCCESS_CODE: Function is successful.
Length : Number of bytes (Address+RegCount+Flags)
Address: Register address
RegCount: Number of bytes to read
Flags: ST reserved (must be 0x00)
4.10 BaudRate function
This function sends a BaudRate command to the CR95HF. It allows configuring the UART
baudrate. Ta bl e 1 8 describes the CR95HF_BaudRate function.
Table 18.CR95HF_BaudRate function description
Prototype
Input parameterBaudRate: New baud rate = 13.56/(2*BaudRate+2) Mbps
Output parameterpResponse : Pointer to the CR95HF response
Return parameterCR95HF_SUCCESS_CODE: Function is successful.
For more information about this command, please refer to CR95HF datasheet.
result = int8_t CR95HF_BaudRate (uc8
BaudRate,uint8_t *pResponse);
Doc ID 022017 Rev 121/68
Loading...
+ 47 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.