Using the CR95HF library with STM8L microcontrollers
1 Introduction
This document describes the CR95HF library allowing an STM8L 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/IEC15693 contactless tag.
The library was developed to speed up the development of applications using the CR95HF.
The CR95HF library is composed of three layers:
■ Low level CR95HF layer
■ Standard ISO/IEC 15693 protocol layer
■ Product layer (LRIxK and Dual Interface EEPROM contactless tag)
The library code has been developed in ANSI C language, and validated on an STM8L
evaluation board.
AN3985
Application note
The firmware runs either on the STM8L1528-EVAL evaluation board or the STM8LDISCOVERY board. The MCU can be either the STM8L152M8 (on the STM8L1528-Eval
board) or the STM8L152C6 (STM8L-DISCOVERY).
1.1 Reference documents
■ ISO/IEC 15693 specification
■ LRIxK ISO/IEC 15693 contactless memory with 64-bit UID, AFI, DSFID, anti-collision and
kill function datasheet
■ CR95HF 13.56-MHz multi-protocol contactless transceiver IC with SPI and UART serial
access datasheet
■ M24LRxx dual interface EEPROM with password protection datasheet
■ UM1037: STM8L1528-EVAL evaluation board user manual
■ UM0970: STM8L-DISCOVERY evaluation board user manual
M24LR64-RDual interface EEPROM (I2C & RF) with 64-kbit memory size
M24LR16-E
MCUMicrocontroller Unit
MSBMost Significant Bit
NFCNear Field Communication
PORPower On Reset
RTCReal Time Clock
RFRadio Frequency
RFUReserved for Future Use
RFIDRadio Frequency Identification
STVDST Visual Develop
UIDUnique Identifier
Write_DO_CfgWrite Digital Output Configuration (M24LRxx-E command)
Write_EH_CfgWrite Energy Harvesting Configuration (M24LRxx-E command)
Dual interface EEPROM (I2C & RF) with 16-kbit memory size and energy
harvesting functionality
XOReXclusive OR
Doc ID 022255 Rev 29/105
Acronyms and notational conventionsAN3985
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 Significant 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/105Doc ID 022255 Rev 2
AN3985Overview
MS19958V1
ISO15693 RF
MCU
CR95HF
Contactless tag
CR95HF
library
ISO15693 RF
Memory products
Dual IC M24LR*
products
RF communication
3 Overview
3.1 CR95HF overview
The CR95HF is a Radio Frequency (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 frame 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 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 ISO/IEC 15693 specification
●A product layer supporting the commands described in the LRIxK and M24LRxx
datasheets
3.2.1 Example of an application architecture
The library can be downloaded from http://www.st.com.
Figure 2 shows the interaction between a typical user application and the CR95HF library
layers.
Doc ID 022255 Rev 211/105
OverviewAN3985
MS19959V1
User functions
(user application specific)
Standard peripheral driver
(MCU specific layer)
CR95HF library
CR95HF library layer
(embeds the commands defined in CR95HF datasheet)
Protocol layer (embeds commands defined in ISO specification)
ISO15693 library layer
Product layer (embeds commands defined in the product datasheet)
LRI*k layerM24LR* layer
Figure 2.Interaction between typical user application and CR95HF library layers
3.2.2 Types
The CR95HF library functions use the following ANSI C compliant types defined in the
stm8l15x.h file.
Signed integer types
typedefsigned charint8_t;
typedef signed short int16_t;
typedef signed longint32_t;
typedef int32_ts32;
typedef int16_ts16;
typedef int8_ts8;
This 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 u8 CR95HF_Echo (void).
Additional functions are described in Table 8: CR95HF layer additional functions.
Application developers can use the functions described in Table 7: CR95HF layer functions
based on CR95HF commands to create their own higher level functions.
Refer to the CR95HF datasheet for more details on the commands.
4.2 Structures
4.2.1 Command format
A command from MCU to CR95HF is composed of three fields:
●command code
●length
●data
The dedicated structure is CR95HF_CommandSending.
Ta bl e 2 lists the fields of a generic command to CR95HF, the number of bytes and the name
of the dedicated structure member.
Table 2.Command fields formats
FieldLengthDedicated structure
Command code1 bytecmd_code
Length1 bytedata_lenght
DataUp to 255 bytesdata
The structure definition of a command to CR95HF is:
Note:This structure is defined in CR95HF_structure.h file.
For more details about idle command, refer to CR95HF datasheet.
Doc ID 022255 Rev 215/105
CR95HF low level layerAN3985
4.3 CR95HF layer functions
The tables below list the functions available in a CR95HF layer.
Table 7.CR95HF layer functions based on CR95HF commands
Function nameDescription
CR95HF_IDNSends an Idn command.
CR95HF_EchoSends an Echo command.
CR95HF_ProtocolSelectSends a ProtocolSelect command.
CR95HF_SendRecvSends a SendRecv command.
CR95HF_IdleSends an Idle command.
CR95HF_Rd_Wake_up_RegReads the wake-up Register command.
CR95HF_Rd_Analog_Register_Config_B
Reads the analog register configuration B command.
CR95HF_BaudRateSends a BaudRate command.
Table 8.CR95HF layer additional functions
Function nameDescription
CR95HF_SendEOFSends an EOF pulse.
CR95HF_FieldOffSwitches off the RF field.
Table 9.Low Power mode functions
Function nameDescription
CR95HF_HibernateSends an hibernate command to CR95HF.
CR95HF_SleepSends a Sleep command to CR95HF.
CR95HF_IdlebyTimerfunction
Sends a Idle command to CR95HF. The wake-up
source is its internal timer.
CR95HF_TagDetectingSends a Tag detecting command to CR95HF.
Table 10.CR95HF layer IS functions
Function nameDescription
CR95HF_IsReaderResultOKChecks if the returned code is successful.
CR95HF_Is_IRQ_in_Interrupt_Wake_up
_Condition
CR95HF_Is_NSS_Interrupt_Wake_up_
Condition
CR95HF_Is_Tag_Detected_Wake_up_
Condition
CR95HF_Is_Timeout_Wake_up_
Condition
Checks if a pulse on IRQ_IN
condition.
Checks if a pulse on NSS pad is a wake-up
condition.
Checks if a tag detector state is a wake-up
condition.
Checks if an internal timer is a wake-up condition.
pad is a wake-up
16/105Doc ID 022255 Rev 2
AN3985CR95HF low level layer
Table 11.CR95HF layer advanced functions
Function nameDescription
CR95HF_Modify_Baud_RateChanges the UART baud rate of MCU and
CR95HF.
CR95HF_Idle_Detector_CalibrationCarries out a calibration for tag detector mode.
CR95HF_Wait_Wake_up_From_IdleWaits for CR95HF to exit the idle state and retrieve
what caused the wake-up.
CR95HF_Wake_up_CR95HFWakes up CR95HF when exists idle mode.
4.3.1 Command functions
CR95HF_IDN function
This function sends an IDN command to the CR95HF device. It returns its version number.
Table 12.CR95HF_IDN function description
Prototypeu8 CR95HF_IDN (CR95HF_ResponseReceiving* Response);
Input parameterNone
Output parameterResponse: pointer on the response structure
Return parameter
CR95HF_SUCCESS_CODE: The command is successful.
CR95HF_ERROR_CODE: The command failed.
CR95HF_Echo function
This function sends an EchoCode command to the CR95HF which returns an Echo code
response (0x55). The Echo function checks that communications can be started between
the MCU and the CR95HF.
CR95HF_SUCCESS_CODE: The command is successful.
CR95HF_ERROR_CODE: The command failed.
Doc ID 022255 Rev 217/105
CR95HF low level layerAN3985
CR95HF_ProtocolSelect function
This function sends a Protocol Select command to the CR95HF. It selects the RF
communication protocol, configures RF parameters, and switches the RF field on.To set up
communications with a contactless tag, the Protocol Select command shall be sent to the
CR95HF before the SendRecv command.
Table 14.CR95HF_ProtocolSelect function description
1. It is recommended to set the append CRC bit (see Chapter 5.3.4: CRC16 management)
3
0b1: wait for SOF
0b0: 100% modulation
2
0b1: 10% modulation
0b0: single subcarrier
1
0b1: single subcarrier
0b0: don’t append CRC
0
0b1: append CRC
(1)
For more detail concerning this parameter, please refer to the CR95HF datasheet.
18/105Doc ID 022255 Rev 2
AN3985CR95HF low level layer
CR95HF_SendRecv function
This function sends a SendRecv command. The parameter passed to the command is the
frame, which is coded according to the protocol previously selected by issuing a Protocol
Select command. The CR95HF encodes the frame, transmits it at 13.56 MHz, and decodes
the contactless tag response.
Table 16.CR95HF_SendRecv function description
Prototype
Input parameterCommand: the command structure to send to a contactless tag
Output parameterResponse: pointer on the response structure
Return parameter
The Parameters of input parameter depend on the selected protocol. Ta bl e 1 5 gives
ISO/IEC 15693 protocol parameters.
In case of a correct response, the SendRecv response sent to MCU is as follows:
WakeUpFlags: Specifies wake-up condition.
EnterCtrlL: first byte of setting to enter to Idle mode
EnterCtrlH: second byte of setting to enter to Idle mode
WUCtrlL: first byte of setting to wake-up from Idle mode
WUCtrlH: second byte of setting to wake-up from Idle mode
LeaveCtrlL: first byte of setting to leave Idle mode
LeaveCtrlH: second byte of setting to leave Idle mode
WUPreiod: period of time between two tags detection
OscStart: waiting time to stabilize HFO
DacStart: waiting time to stabilize DAC
DacDataL: lower compare value for tag detection
DacDataH: higher compare value for tag detection
SwingsCnt: number of HF swings during tag detection
MaxSleep: maximum number of tag detection trials before timeout
Output parameterIdle_Config: pointer on the Idle structure
Return parameterCR95HF_SUCCESS_CODE: The command is successful.
Note:Some Low power mode commands using the Idle command are defined in Chapter 4.3.3:
Low power mode functions
CR95HF_Rd_Wake_up_Reg function
This function reads the wake-up register of the CR95HF to determine what has caused the
awakening of the CR95HF after an Idle command.
Table 20.CR95HF_Rd_Wake_up_Reg function description
Response: pointer on the structure to fill in with the data retrieved
Idle_Config: pointer on the structure to update
CR95HF_SUCCESS_CODE: The command is successful.
CR95HF_ERROR_INVALID_CMD_LENGTH:The command failed,
invalid length.
CR95HF_ERROR_CODE: Command failed, response contains the
error code.
20/105Doc ID 022255 Rev 2
AN3985CR95HF low level layer
CR95HF_Rd_Analog_Register_Config_B function
This function reads the analog register configuration B of the CR95HF to check the analog
configuration Register containing the modulation depth and reader chain gain.
Note:A CR95HF_Set_Analog_Register_Config_B_Index command must be issued before
reading the register.
Table 21.CR95HF_Rd_Analog_Register_Config_B function description
This function sends a BaudRate command to the CR95HF. It allows to configure the UART
baudrate.
Table 22.CR95HF_Baud_Rate function description
Prototypeu8 CR95HF_Baud_Rate(u8 New_Baud_Rate);
Input parameterNew_Baud_Rate: new baud rate = 13.56/(2*BaudRate+2) Mbps
Output parameterpResponse: pointer on the CR95HF response
CR95HF_SUCCESS_CODE: The command is successful.
Return parameter
CR95HF_ERROR_CODE: Unsuccessful command, UART
communication may be lost.
Doc ID 022255 Rev 221/105
CR95HF low level layerAN3985
4.3.2 Additional functions
CR95HF_SendEOF function
This function sends an EOF. This can be used for instance in an ISO/IEC 15693 inventory or
write command. Right after the EOF, the tag could answer a command (Write or Inventory),
so the response is received and written into the provided structure.
CR95HF_SUCCESS_CODE: The field was successfully turned off
CR95HF_ERROR_INVALID_PROTOCOL: The selected protocol is wrong.
CR95HF_ERROR_INVALID_CMD_LENGTH: The command length is invalid.
CR95HF_ERROR_CODE: The command failed
4.3.3 Low power mode functions
These functions send an idle command with some parameters forced into the function.
CR95HF_Hibernate function
This function sends an Hibernate command to CR95HF and turns the hibernate state on.
This is the lowest consumption state of CR95HF. Only a pulse on
the CR95HF.
Input parameterWakeUpSource: the source of wake-up for CR95HF
Output parameter
Idle_Config: pointer on the structure which contains data about some idle
parameters to update
Return parameter CR95HF_SUCCESS_CODE: The command is successful.
1. e.g.: for a wake-up by a pulse on SPI_NSS pad, use CR95HF_IDLE_WAKEUP_SPIN_SS value. For a
wake- up by a pulse on IRQ_IN
pad, use CR95HF_IDLE_WAKEUP_IRQ_in value.
CR95HF_TagDetecting function
This function sends a Tag detecting command to CR95HF. The CR95HF turns in a low
power mode and periodically checks if a contactless tag is in the operating value. In this last
case, the CR95HF will wake-up by itself.
FALSE_CODE: An interrupt on IRQ_IN pin is not a wake-up condition.
24/105Doc ID 022255 Rev 2
AN3985CR95HF low level layer
Is_NSS_Interrupt_Wake_up_Condition function
This function returns whether an interrupt on NSS is a wake-up condition or not.
Table 31.Is_NSS_Interrupt_Wake_up_Condition function description
Prototypeu8 CR95HF_Is_NSS_Interrupt_Wake_up_Condition(u8 WUFlags);
Input parameterWUFlags: the byte containing the expected data
Output parameter None
Return parameter
TRUE_CODE: An interrupt on IRQ_IN
FALSE_CODE: An interrupt on IRQ_IN is not a wake-up condition.
is a wake-up condition.
Is_Tag_Detected_Wake_up_Condition function
This function returns whether a tag detection is a wake-up condition or not.
Table 32.Is_Tag_Detected_Wake_up_Condition function description
Prototypeu8 CR95HF_Is_Tag_Detected_Wake_up_Condition_(u8 WUFlags);
Input parameterWUFlags: the byte containing the expected data
Output parameter None
Return parameter
TRUE_CODE: A tag detection is a wake-up condition.
FALSE_CODE: A tag detection is not a wake-up condition.
Is_Timeout_Wake_up_Condition function
This function returns whether the internal timer is a wake-up condition.
Table 33.Is_Tag_Detected_Wake_up_Condition function description
Prototypeu8 CR95HF_Is_Timeout_Wake_up_Condition(u8 WUFlags);
Input parameterWUFlags: the byte containing the expected data
Output parameter None
Return parameter
TRUE_CODE: An interrupt on IRQ_IN
FALSE_CODE: An interrupt on IRQ_IN
is a wake-up condition.
is not a wake-up condition.
Doc ID 022255 Rev 225/105
CR95HF low level layerAN3985
4.3.5 Advanced functions
CR95HF_Modify_Baud_Rate function
This function is a procedure to change baud rates in UART communication. The function
calls the CR95HF_Baud_Rate function and changes the MCU internal baud rate. In case of
a failure, the function tries to recover the communication by returning into the previous baud
rate or into the default baud rate.
Table 34.CR95HF_Modify_Baud_Rate function description
Protocol_Settings: pointer on the structure to update the protocol select. (Turn
RF field off)
Idle_Config: pointer on the structure to write the high compare value and low
compare value for tag detection and the last wake-up reason.
CR95HF_SUCCESS_CODE: The command is successful.
CR95HF_ERROR_CODE: The command failed.
26/105Doc ID 022255 Rev 2
AN3985CR95HF low level layer
CR95HF_Wait_Wake_up_From_Idle function
The purpose of this function is to wait for CR95HF to exit the idle state and retrieve what
caused the wake-up. The method proposed is to wait for the CR95HF answer and then to
send several echo commands in order to resume communication and clear the CR95HF
response FIFO stack.
Table 36.CR95HF_Wait_Wake_up_From_Idle function description
pointer on the structure to update with the new last reason of wake-up
Input parameter
Output parameter
Return parameter
Idle_Config:
Number_of_DELAY_BEFORE_TIMEOUT_250MS: number of periods of
250ms duration to wait before aborting the procedure
Idle_Config: pointer on the structure to write the High compare value and low
compare value for tag detection and the last wake-up reason
EXIT_COMMUNICATION_OK (CR95HF_SUCCESS_CODE): communication is
possible.
EXIT_COMMUNICATION_TIMEOUT: communication is not possible.
This function waits for CR95HF to wake-up on its own (internal timer, tag detection).
After this, the CR95HF_Wake_up_CR95HF function may be called to wake-up the CR95HF
with NNS or IRQ_IN
interrupt.
CR95HF_Wake_up_CR95HF function
This function wakes up the CR95HF device from idle mode. The method proposed is to
send several echo commands in order to resume communication and clear the CR95HF
response FIFO stack.
Table 37.CR95HF_Wake_up_CR95HF function description
Prototypeu8 CR95HF_Wake_up_CR95HF(CR95HF_Idle_Config* Idle_Config);
Input parameterIdle_Config: contains the wake-up condition
Output parameter None
Return parameter
CR95HF_SUCCESS_CODE: the CR95HF woke up, communication is possible.
CR95HF_ERROR_CODE: fail to wake-up the CR95HF, either the CR95HF waits
for another event (tag detection, timer) or communication cannot be resumed.
Doc ID 022255 Rev 227/105
CR95HF low level layerAN3985
AI18875
Start
Echo
Echo
response?
Select
protocol
Selected?
SendRecv
Another
protocol?
No
Error code
Yes
No
Yes
Yes
4.3.6 Application example: protocol selection and communication
To communicate with a contactless tag, the application must first select the RF protocol by
sending a ProtocolSelect command. Then the application can use SendRecv commands to
send data to a contactless tag. The user can select another protocol or change RF
parameters (e.g. choose another data rate) by issuing again a ProtocolSelect command
(refer to Figure 3).
Figure 3.Function flowchart example
28/105Doc ID 022255 Rev 2
AN3985ISO/IEC 15693 layer
5 ISO/IEC 15693 layer
This layer is composed of:
●the source file: iso15693_command.c
●the included file: iso15693_command.h
5.1 Overview
The ISO/IEC 15693 specification defines a set of commands to handle one or more
contactless tags, and some commands of a higher level such as read or write commands.
This layer supports all the commands defined in the ISO/IEC 15693 specification and
integrates some functions to facilitate the use of the ISO/IEC 15693 commands.
5.2 Structures
This layer uses a structure to store the information of an ISO/IEC contactless tag.
5.2.1 Structures of command and response of an ISO/IEC 15693 tag
The ISO15693_tag structure contains the different fields associated to an ISO/IEC15693
contactless tag.
Table 38.ISO15693_tag structure description
NameNumber of bytesComment
command_ok1
error_code1
response_flags1Response flag provided by the tag
dataField
receivedDataLength1
UID_TagISO15693_UID_SIZEUID of the contactless tag
AFI_Tag1AFI of the contactless tag
DSFID_Tag1DSFID of the contactless tag
ICRef1
memSize
ISO15693_DATA_RECEIVED_MAX
_SIZE
ISO15693_MEMSIZE_MAX_WORD_
BYTE_SIZE
The command and the response
are ok, the structure is ok.
Error code of a contactless tag or
CRC error
Whole data transmitted by the tag
and CR95HF control byte
Length of data transmitted by the
Ta g
ICRef of the Tag (only for those
manufactured by
STMicroelectronics).
Memfield of getsystem info
command
Doc ID 022255 Rev 229/105
ISO/IEC 15693 layerAN3985
This structure is defined in ISO15693_structure.h.
The commands defined by ISO/IEC 15693 specification have the following structure:
SOFRequest flagCommand codeDataCRCEOF
With:
●SOF: start of frame
●Request flag: 1 byte
●Command code: 1 byte
●Data: 1 or more byte
●CRC: 2 bytes
●EOF: end of frame
5.3.1 SOF and EOF
The SOF and EOF are managed by CR95HF device.
5.3.2 Request flag management
The request flags byte is managed by the user application. Each bit or flag specifies the
actions to be carried out by the contactless tag and whether the corresponding fields are
present or not.
The request flags is a byte integrated on all ISO/IEC 15693 commands, which specifies the
actions to be performed by the contactless tag.
The meaning of bit 1, 2 and 4 is the same for all ISO/IEC 15693 commands.
Bit 3 (Inventory_flag) of the request flag defines the contents of the 4 MSBs (bits 5 to 8).
When bit 3 is reset (0), bits 5 to 8 contain the contactless tag selection criteria. When bit 3 is
set (1), bits 5 to 8 define the contactless tag Inventory parameters.
30/105Doc ID 022255 Rev 2
AN3985ISO/IEC 15693 layer
Table 39.Request flag bits description
Request flagsb1b2b3b4b5b6b7b8
Inventory command
Subcarrier Data rate
Other commandInventory = 0SelectNb slots Option RFU
Table 40.Request flag bits values
Inventory = 1
Protocol
Extension
AFIAddress Option RFU
BitValueDescription
0A single subcarrier frequency is used.
Subcarrier
1Two subcarriers are used.
0Low data rate is used.
Data rate
1High data rate is used.
0Other command.
Inventory
1Inventory command.
Protocol Extension0RFU
Ta bl e 4 1 describes the bit for Request flag if the inventory flag is reset (other command than
inventory).
Table 41.Bit for request flag with inventory flag reset
BitValueDescription
Select
0Request is executed in other state than Selected.
1Request is executed only by the contactless tag in Selected state.
0Request is not addressed. UID field is not present.
Data rate
Request is addressed. UID field is present. The request is executed only
1
by the contactless tag whose UID matches the UID specified in the
request.
Option-Depends on the command.
RFU0RFU
Doc ID 022255 Rev 231/105
ISO/IEC 15693 layerAN3985
Ta bl e 4 2 describes the bit for Request flag if the inventory flag is set (inventory commands)
Table 42.Bit for request flag with inventory flag reset
BitValueDescription
AFI
Data rate
Option0RFU
RFU0RFU
0AFI field is not present.
1AFI field is present.
016 slots
1
1 slot
For more information, please refer to ISO/IEC 15693 specification or ISO/IEC 15693
STMicroelectronics product datasheet.
Request flags and CR95HF_ProtocolSelect functions
The CR95HF_ProtocolSelect function (see Chapter 4.2.3: Protocol selection structure)
selects the RF protocol and defines the CR95HF datarate and contactless tag response
format (single or double subcarrier). Once the protocol and the RF parameters are
configured, the CR95HF can decode only contactless tag responses of same format and
datarate.
The datarate and contactless tag response format are also defined in the request flag byte
of each ISO/IEC 15693 command. The user application must ensure that the data rate and
subcarrier flags match the CR95HF_ProtocolSelect function parameters. This check is
performed by the functions of the ISO/IEC 15693 layer. If the parameters do not match, the
functions are not executed and the corresponding commands are not sent to the CR95HF.
5.3.3 Command code and Data management
The command and data shall be managed by user application.
5.3.4 CRC16 management
The ISO/IEC 15693 specification defines a two bytes CRC. It is appended to ISO/IEC 15693
command in order to check the data transmission between CR95HF and a contactless tag.
Bit 0 of parameter (AppendCRC) of ProtocolSelect command allows to append CRC to all
RF commands. The ISO15693_ComputeParameterByte_ProtocolSelect function
computes the parameter byte for protocol select according to the parameter provided and
sets the append CRC bit.
This bit 0 has to be set because the function in ISO/IEC 15693 and products layers will not
manage the CRC command. And the contactless tag will not answer to RF command.
32/105Doc ID 022255 Rev 2
AN3985ISO/IEC 15693 layer
5.4 ISO/IEC 15693 layer functions
The tables below summarize the available functions in CR95HF layer.
The functions send, through CR95HF, the command of ISO/IEC 15693 specification (refer to
Ta bl e 4 4 ).
Table 43.Functions to compute parameter byte
Function nameBrief description
ISO15693_ComputeParameterByte_
ProtocolSelect
ComputeByte
Computes the Parameter byte for ProtocolSelect
function.
Computes a byte. It can be used to create Request
flags byte.
Table 44.ISO15693 library command based on ISO/IEC 15693 specification
Function nameBrief description
ISO15693_Inventory
ISO15693_Stay_Quiet
ISO15693_Read_Single_Block
ISO15693_Write_Single_Block
ISO15693_Lock_Block
ISO15693_Read_Multiple_Block
ISO15693_Write_Multiple_Block
ISO15693_Select
ISO15693_Reset_to_Ready
ISO15693_Write_AFI
ISO15693_Lock_AFI
ISO15693_Write_DSFID
ISO15693_Lock_DSFID
Emits an inventory command.
Emits a stay quiet command.
Emits a read single block command.
Emits a write single block command.
Emits a lock single block command.
Emits a read multiple block command.
Emits a write multiple block command.
Emits a select command.
Emits a reset to ready command.
Emits a write AFI command.
Emits a lock AFI command.
Emits a write DSFID command.
Emits a lock DSFID command.
ISO15693_Get_System_Info
ISO15693_Get_Multiple_Blocks_Security_
Status
ISO15693_SendEOF
ISO15693_Custom_Commands
Doc ID 022255 Rev 233/105
Emits a get system info command.
Emits a Get multiple block security status
command.
Emits an EOF pulse.
Emits a customs command.
ISO/IEC 15693 layerAN3985
Table 45.Functions to assemble ISO/IEC 15693 command
Checks if the check collision flag added by the
CR95HF is set.
Checks if the check CRC16 flag added by the
CR95HF is set.
Checks if the check CRC16 flag added by the
CR95HF is set.
Checks if the tag has been made by
STMicroelectronics.
Returns if the command performs a memory
programming.
Returns if the DSFID is present.
Returns if the AFI is present.
Returns if the Memsize is present.
ISO15693_Is_ICRef_Present_Infoflag
Returns if the ICREF is present.
34/105Doc ID 022255 Rev 2
AN3985ISO/IEC 15693 layer
Table 46.Get functions
Function nameBrief description
ISO15693_Get_Subcarrier_Flag
ISO15693_Get_DataRate_Flag
ISO15693_Get_Inventory_Flag
ISO15693_Get_ProtocolExtension_Flag
ISO15693_Get_Select_Flag
ISO15693_Get_Address_Flag
ISO15693_Get_AFI_Flag
ISO15693_Get_Slots_Flag
ISO15693_Get_Option_Flag
ISO15693_Get_RFU_Flag
ISO15693_Get_NumberofByte_MemSize_using_
ICREF
ISO15693_Get_Size_of_Block_using_ICRef
ISO15693_Get_Size_of_Block_using_MemSize
ISO15693_Get_MemSize_kbits
ISO15693_Get_MemSize_bits
Returns if the tag's response is made with one
or two subcarriers.
Returns if the tag's response is made in high or
low datarate.
Returns if the inventory flag is set or not.
Returns if the protocol extension flag is set or not.
Returns if the select flag is set or not.
Returns if the address flag is set or not.
Returns if the AFI flag is set.
Returns the number of slots flag.
Returns if the option flag is set or not.
Returns if the RFU is set or not.
Returns the number of bytes used to describe
the memory size of the tag.
Returns the number of bytes of a EEPROM
block.
Returns the number of bytes of a EEPROM
block.
Returns the memory size of the tag in kbits.
Returns the memory size of the tag in bits.
ISO15693_Get_UID_from_EEPROM
Table 47.CRC16 functions
Function nameBrief description
ISO15693_CRC16
ISO15693_IsCorrectCRC16Residue
ISO15693_CRC16_EEPROM
ISO15693_IsCorrectCRC16Residue_EEPROM
Retrieves the UID stored into the EEPROM by
the inventory 16 slots commands.
Computes CRC16 according to ISO/IEC 15693
specification.
Checks CRC16 residue according to ISO/IEC
15693 specification.
Computes the CRC16 of data stored into the
internal EEPROM.
Checks CRC16 residue of data stored into the internal
EEPROM.
Doc ID 022255 Rev 235/105
ISO/IEC 15693 layerAN3985
Table 48.Structure Fill In functions
Function nameBrief description
ISO156693_Check_Data_Received_Start_
Process
ISO15693_Retrieve_UID
ISO15693_Retrieve_ICRef
5.4.1 Compute parameter byte functions
These functions compute a parameter field which will be used in other functions.
ISO15693_ComputeParameterByte_ProtocolSelect function
This function computes the parameter byte for ISO/IEC 15693 ProtocolSelect command,
bit0 is set to 1 to append CRC (see Chapter 5.3.4: CRC16 management).
Table 49.ISO15693_ComputeParameterByte_ProtocolSelect function description
u8
Prototype
Input parameter
Output parameterNone
Return parameterParameter byte for ProtocolSelect command
Bit7: the parameter to place at the MSB bit
Bit6: the parameter of bit number 6
Bit5: the parameter of bit number 5
Bit4: the parameter of bit number 4
Bit3: the parameter of bit number 3
Bit2: the parameter of bit number 2
Bit1: the parameter of bit number 1
Bit0: the LSB bit
For instance, the following function creates a request flags for an Inventory command.
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not
Tag_AFI: AFI field to select a contactless tag family
Input parameter
MaskLength: length of the mask for transmitting
Mask: the mask to transmit
Inventory_16_slots_Nb_UID_Retrieved: pointer to retrieve the number of tags
seen during the inventory 16 slots
Output parameterMyTag: pointer on the structure
SO15693_ERROR_CODE: The command failed. Either there is no tag or the
tag did not manage to perform the request.
Return parameter
ISO15693_ERROR_PARAMETERS_REQUEST_FLAGS: There is an error
within the request flags parameters.
ISO15693_COMMAND_SUCCESS_CODE: Tag answered the command.
1. Inventory shall be set.
2. AFI field is added if AFI flag of request flags is set
3. For example, to transmit a part of the UID of one tag. Masklength represents the numbers of significant
bits. The user should ensure that other bits are reset for padding.
Note:If the inventory flag is not set, the function returns an error code.
ISO15693_StayQuiet function
This function emits a StayQuiet command to Contactless tag.
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not
Tag_UID: pointer on the UID (optional)
block_number: address of the block to read
Block_Length: number of bytes in a block
Data: pointer to data to write into contactless tag memory
(1)
.
ISO15693_ERROR_CODE: The command failed.
Return parameter
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
ISO15693_ERROR_PARAMETERS_REQUEST_FLAGS: There is an error
within the request flags parameters.
ISO15693_SUCCESS_CODE: The contactless tag answered the command.
Note:According to ISO/IEC 15693 specification, the WriteSingleBlock command supports the
Option Flag.
If the Option_flag is not set, the contactless tag shall return its response when it has
completed the write operation.
If it is set, the contactless tag waits for an EOF pulse from the CR95HF.
Doc ID 022255 Rev 239/105
ISO/IEC 15693 layerAN3985
The CR95HF supports these two cases but it has to be configured before sending an Write
command.
This is the meaning of the Flag#3 of parameter of ProtocolSelect command (0: Ensure a
312 µs delay OR 1: Wait for SOF).
Ta bl e 5 5 shows the relationship between option flag of request_flag and:
●312 µs delay; or,
●wait for SOF
Table 55.ISO15693_Write_Single_Block results depending on Option flag
Option flag of RequestFlag
(312 µs or WaitSOF)
0 (312 µs)
Ko (write worked out but CR95HF
does not detect the response tag)
0 (set)1 (reset)
Ok (but required to emit an EOF
pulse)
1 (Wait SOF)Ok
Ok (but required to emit an EOF
pulse)
The ISO15693_Write_Single_Block function returns an error code if the Option Flag is
reset and 312 µs and SOF flag is reset.
If the option flag is set, the EOF pulse is managed by the
ISO15693_Write_Single_Block function.
ISO15693_Lock_Block function
This function sends, through the CR95HF, a lock block command to the contactless tag in
the field or to an unique contactless tag designated by its UID.
whether corresponding fields are present or not
Tag_UID: pointer on the UID (optional)
: Specifies the actions to be performed by the contactless tag and
(1)
.
First_Block_number: address of the first block to read
Number_of_Blocks: number of blocks to read
Output parameterMyTag: pointer on the structure that contains the tag response
ISO15693_ERROR_CODE: The command failed.
Return parameter
ISO15693_ERROR_PARAMETERS_REQUEST_FLAGS: There is an error
within the request flags parameters.
ISO15693_SUCCESS_CODE: The contactless tag answered the command.
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
Note:The data received is stored into the internal EEPROM of the MCU.
ISO15693_Write_Multiple_Block function
This function sends, through the CR95HF, a write multiple block command to the contactless
tag in the field or to a unique contactless tag designated by its UID.
Table 58.ISO15693_Write_Multiple_Block function description
Tag_UID: pointer on the UID (optional).
First_Block_number: address of the first block to read.
Number_of_Blocks: number of blocks to read after the first one.
ISO15693_ERROR_CODE: The command failed.
ISO15693_ERROR_PARAMETERS_REQUEST_FLAGS: There is an error
within the request flags parameters.
ISO15693_SUCCESS_CODE: The contactless tag answered the command.
: Specifies the actions to be performed by the contactless tag and
(1)
.
Doc ID 022255 Rev 245/105
ISO/IEC 15693 layerAN3985
ISO15693_Custom_Commands function
This function sends, through the CR95HF, a custom command to the contactless tag in the
field or to an unique contactless tag designated by its UID. The user should add in
parameters all the data needed. Command size is limited to MAX_DATASENT_LENGTH.
Table 67.ISO15693_Custom_Commands function description
whether corresponding fields are present or not
Tag_UID: pointer on the UID (optional)
Input parameter
Output parameterMyTag: pointer on the structure that contains the CR95HF response
Return parameter
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
Custom: the custom command code
IC_Mfg_Code: the IC manufacturer code designating the manufacturer of the
contactless tag
Parameters_Length: length of parameters
Parameters: data to write
ISO15693_ERROR_CODE: The command failed.
ISO15693_ERROR_PARAMETERS_REQUEST_FLAGS: There is an error
within the request flags parameters.
ISO15693_SUCCESS_CODE: The contactless tag answered the command.
: Specifies the actions to be performed by the contactless tag and
(1)
.
ISO15693_SendEOF function
This function sends through the CR95HF an EOF pulse. This is used for Write Lock and
Inventory 16 slots commands to inform the contactless tag that it can answer now (Write
and Lock commands) or that a new slot is beginning (inventory 16 slots).
Cmd: pointer on the command to fill in
cptr_ToIncrement: pointer on the counter
MaskLength: length of the Mask in bits
Mask: pointer on the mask to add
Doc ID 022255 Rev 247/105
ISO/IEC 15693 layerAN3985
ISO15693_Add_Request_Flags_Command_code_to_command function
This function adds the Request flags into the command's data and increments the counter
of data.
Table 71.ISO15693_Add_Request_Flags_Command_code_to_command function
TRUE_CODE: The contactless tag handled the request.
FALSE_CODE: The contactless tag answered but the frame is an error
message.
ISO15693_Is_Request_Flags_ok function
This function performs several checks to verify that the request flag is not wrong. This is not
a guarantee that the request flag is right (depends on the contactless tag and on some
command particularities).
Table 73.ISO15693_Is_Request_Flags_ok function description
ISO15693_Response_flags: response flag provided by the tag
ISO15693_cmd_code: command code emitted to the contactless tag
FALSE_CODE: An error has been found out within the request flags.
TRUE_CODE: There is no error seen within the request flags.
48/105Doc ID 022255 Rev 2
AN3985ISO/IEC 15693 layer
ISO15693_Is_Collision_Flag_Set function
This function checks if the check collision flag added by the CR95HF is set or not. If it is, it
means that the CRC95HF has detected a collision between two contactless tag answers.
Table 74.ISO15693_Is_Collision_Flag_Set function description
ISO15693_Response_flags: response flag provided by the tag
ISO15693_cmd_code: command code emitted to contactless tag
TRUE_CODE: The collision flag is set.
FALSE_CODE: The collision flag is not set.
ISO15693_IsCRC_Flag_Set function
This function checks if the check CRC flag added by the CR95HF is set or not. If it is, it
means that the CRC95HF has detected an error during the reception.
Table 75.ISO15693_IsCRC_Flag_Set function description
Prototype
Input parameterResponse: response returned by CR95HF containing the data
TRUE_CODE: The CRT flag is set.
FALSE_CODE: The CRT flag is not set.
ISO15693_Is_CorrectCRC16_Check function
This function checks the check CRC flag and the residue of the received command. If there
is any problem (mismatch or error), the function returns an error value.
Table 76.ISO15693_Is_CorrectCRC16_Check function description
ICRef: the ICref to compare with the one referenced in the miscellaneous.h file
(those available at the date of creation of this file; as a matter of fact, an update
should be necessary)
Number_of_Byte: the number of bytes composing a block
ISO15693_BLOCK_SIZE_ERROR: No Icref matches, 0 is returned
Doc ID 022255 Rev 255/105
ISO/IEC 15693 layerAN3985
ISO15693_Get_Size_of_Block_using_MemSize function
This functions returns the size of a block using the MemSize field of the tag structure. A get
system info command should have been performed before calling this function.
Table 95.ISO15693_Get_Size_of_Block_using_MemSize function description
Prototype
Input parameterMyTag: the structure containing the data describing the contactless tag
MemSize: pointer on the bytes describing the memory size
ICRef: ICRef to retrieve the number of bytes if necessary
Output parameterNone
Return parametersize: the size of the memory in kbits
ISO15693_Get_MemSize_bits function
This function returns the memory size of the contactless tag in bits. This function should be
called if the size of the memory is not an integer number of kbits.
Table 97.ISO15693_Get_MemSize_bits function description
Prototype
Input parameterMemSize: pointer on the bytes describing the memory size
Output parameterNone
Return parametersize: the size of the memory in bits (max 1023 bits)
u32 ISO15693_Get_MemSize_bits(u8* MemSize);
56/105Doc ID 022255 Rev 2
AN3985ISO/IEC 15693 layer
ISO15693_Get_UID_from_EEPROM function
This function retrieves the UID stored into the EEPROM by the inventory 16 slots
commands.
Table 98.ISO15693_Get_UID_from_EEPROM function description
Prototype
Input parameterMemSize: pointer on the bytes describing the memory size
DataIn: input data
Length: number of bytes of DataIn
ISO15693_IsCorrectCRC16Residue function
This function computes the CRC16 residue as defined by CRC ISO/IEC 13239 and returns
ISO15693_RESULTOKCRC16 if the residue is compliant the ISO specification.
Table 100. ISO15693_IsCorrectCRC16Residue function description
DataIn: input data
Length: number of bytes of DataIn
ISO15693_RESULTOKCRC16: CRC16 residue is correct.
ISO15693_ERRORCODE_GENERICCRC16: CRC16 residue is false.
Doc ID 022255 Rev 257/105
ISO/IEC 15693 layerAN3985
ISO15693_CRC16_EEPROM function
This function computes the CRC16 residue as defined by CRC ISO/IEC 13239 and returns
ISO15693_RESULTOKCRC16 if the residue is compliant with the ISO specification.
Table 101. ISO15693_CRC16_EEPROM function description
ISO15693_RESULTOKCRC16: CRC16 residue is correct.
ISO15693_ERRORCODE_GENERICCRC16: CRC16 residue is false.
5.4.7 Fill In functions
ISO156693_Check_Data_Received_Start_Process function
This function checks the data integrity (the data is error-free and filled in basic data common
for all responses: copy the whole data, write response_flag and data_length into the
structure).
Table 103. ISO156693_Check_Data_Received_Start_Process function description
Prototype
Input parameterResponse: the response containing the data
Input parameterNone
Output parameterMyTag: pointer on the structure to complete
Return parameterNone
Doc ID 022255 Rev 259/105
LRIxK layerAN3985
6 LRIxK layer
6.1 Overview
LRIxK devices are compliant with ISO/IEC 15693 specifications. Several functions of the
LRIxK-R layer are identical to ISO/IEC 15693 functions.
This layer includes all the commands defined in the LRIxK datasheets.
The LRIX layer applied to LRI1k, LRIS2k and LRI2k and is composed of:
●LRIxK_command.c
●LRIxK_command.h
6.2 Command format
6.2.1 CRC16 management
The LRIxK datasheet defines a two bytes CRC. It is appended to the RF command in order
to check the data transmission between CR95HF and a contactless tag.
Bit 0 of parameter (AppendCRC) of ProtocolSelect command is set in the ProtocolSelect
function. Thus the CR95HF manages the CRC of the RF command.
6.2.2 Request flag management
The request flag is detailed in Chapter 5.3.2: Request flag management.
The request flag byte is managed by the user application. Each bit or flag specifies the
actions to be performed by the contactless tag and whether the corresponding fields are
present or not. Bit 3 (Inventory_flag) of the request flag defines the contents of the 4 MSBs
(bits 5 to 8). When bit 3 is reset (0), bits 5 to 8 define the contactless tag selection criteria.
When bit 3 is set (1), bits 5 to 8 define the contactless tag Inventory parameters.
Some commands of LRIxK datasheet required specific request flags. Those Request flags
are forced inside the LRIxK layer function.
60/105Doc ID 022255 Rev 2
AN3985LRIxK layer
Table 106 lists the request flags witch are forced inside the M24LRxx layer functions:
●0 means the flag is reset.
●1 means the flag is set.
●- means the user application manages the flag.
Table 106. Request flag management description
Command
Inventory1-00--
Stay Quiet00001-
Read Single block0--0--
Write Single Block0--0--
Lock Block0-00--
Read Multiple Blocks0--0--
Select00001-
Reset to ready0-00--
Write AFI0--0--
Lock AFI0--0--
Write DSFID0--0--
Lock DSFID0--0--
Get system Info0-00--
Get multiple blocks status0-00--
Kill0--0--
Write Kill0--0--
Lock Kill---0-1
Inventory
Flag
Select
Flag
Option
Flag
Protocol
Extension flag
Address
flag
RFU
flag
Fast Read Single Block0--0--
Fast Inventory Initiated0-00--
Fast Initiate00000-
Fast Read multiple blocks0--0--
Inventory Initiated1-00--
Initiate00000-
For more information, please refer to the ISO/IEC 15693 specification and to the LRIxK
datasheets.
6.2.3 Request flags and CR95HF_ProtocolSelect functions
The CR95HF_ProtocolSelect function (defined into the CR95HF layer) selects the RF
protocol and defines, for the CR95HF device, the datarate and contactless tag response
format (single or double subcarrier). Once the protocol and the RF parameters are
configured, CR95HF is able to decode only contactless tag responses with the same format
and datarate.
Doc ID 022255 Rev 261/105
LRIxK layerAN3985
The datarate and contactless tag response format are also defined in the request flag byte
of each command. The user application must ensure that the datarate and subcarrier flags
match the CR95HF_ProtocolSelect function parameters. This check is performed by the
ISO/IEC 15693 layer functions. If the parameters do not match, the functions are not
executed and the corresponding commands are not sent to the CR95HF.
6.3 LRIxK layer commands
LRIxK devices are compliant with ISO/IEC 15693 specification. Thus the LRIxK functions
call the ISO/IEC 15693 functions. Furthermore the LRIxK functions carry out some
additional check and modifies some parameter as defined in the LRIxK datasheet.
The table below shows the relationship between LRIxK and ISO/IEC 15693 layers. The
"function name" column presents the LRIxK functions.
The next column gives the functions called in the ISO15593 layer. If the function does not
exist in the ISO/IEC 15693 layer, the cell is empty.
Table 107. LRIxK layer commands description
LRIxK_InventoryISO15693_Inventory
LRIxK_Stay_QuietISO15693_Stay_Quiet
Function nameNew or equivalent functionBrief description
LRIxK_Inventory_InitiatedSends an Inventory Initiated
ISO15693_Get_Multiple_Block_
Security_Status
command.
LRIxK_InitiateSends an Initiate command.
LRIxK_Fast_Read_Single_BlockSends an Fast Read Single Block
command.
62/105Doc ID 022255 Rev 2
AN3985LRIxK layer
6.3.1 LRIxK command functions
This chapter describes the specific LRIxK layer functions.
LRIxK_Kill function
This function sends, through the CR95HF, a kill command to the unique contactless tag
designated by its UID and belonging to the LRIxK family. On receiving the kill command, the
contactless tag compares the kill code added to the command and checks if it matches with
the kill code previously written into the code. The contactless tag answers to the command
before being deactivated.
Table 108. LRIxK_Kill function description
u8 LRIXK_Kill(ISO15693_Tag* MyTag, const u8
Prototype
Input parameter
Output parameterMyTag: pointer on the structure that contains the tag response
Request_flags: option flag to indicate the parameters to use for the flag
response and if UID is present (addressed).
Tag_UID: pointer on the UID of the tag.
Kill_Code: kill code to compare with the one inside the contactless tag in order
to perform the kill command.
LRIxK_ERROR_CODE: The command failed. Either there is no tag or the tag
did not manage to perform the request.
LRIxK_ERROR_REQUEST_FLAGS_CODE: The inventory flag is set.
LRIxK_COMMAND_SUCCESS_CODE: The tag answered the command.
LRIxK_Write_Kill function
This function sends, through the CR95HF, a write kill command to an LRIxK contactless tag
present in the RF field or designated by its UID. The kill code provided is transmitted to the
contactless tag and will be required to deactivate the LRIxK product.
Table 109. LRIxK_Write_Kill function description
Prototype
Input parameter
Output parameterMyTag: pointer on the structure that contains the tag response
Return parameter
Note:A lock kill command is necessary after this command to protect the kill code.
Request_flags: option flag to indicate the parameters to use for the flag
response and if UID is present (addressed)
Tag_UID: pointer on the UID of the tag
LRIxK_ERROR_CODE: The command failed. Either there is no tag or the tag
did not manage to perform the request.
LRIxK_ERROR_REQUEST_FLAGS_CODE: The inventory flag is set.
LRIxK_COMMAND_SUCCESS_CODE: The tag answered the command.
LRIxK_Inventory_Initiated function
This function sends, through the CR95HF, an initiate command to an LRIxK contactless tag
present in the field or designated by its UID. On receiving the initiate command, the LRIxK
contactless tag sets the internal initiate flag (to send an inventory initiated command) and
returns its UID and its DSFID.
Table 111. LRIxK_Inventory_Initiated function description
u8 LRIxK_Inventory_Initiated(ISO15693_Tag* MyTag,
Prototype
Input parameter
Output parameterMyTag: pointer on the structure
Return parameter
1. Masklength represents the number of significant bits. The user should ensure that other bits are reset for
padding.
Request_flags: option flag to indicate the parameters to use for the flag
response
Tag_AFI: the optional AFI to select a tag family
MaskLength: length of the mask for transmitting
Mask: the mask to transmit
Inventory_16_slots_Nb_UID_Retrieved: pointer to retrieve the number of tags
seen during the inventory 16 slots
LRIxK_ERROR_CODE: The command failed. Either there is no tag or the tag
did not manage to perform the request.
LRIxK_ERROR_REQUEST_FLAGS_CODE: The inventory flag is not set.
LRIxK_COMMAND_SUCCESS_CODE: The tag answered the command.
(1)
(2)
64/105Doc ID 022255 Rev 2
AN3985LRIxK layer
LRIxK_Initiate function
This function sends, through the CR95HF, an initiate command to an LRIxK contactless tag
present in the RF field or designated by its UID. On receiving the initiate command, the
LRIxK contactless tag sets the internal initiate flag (to send an inventory initiated command)
and returns its UID and its DSFID.
Output parameterMyTag: pointer on the structure that contains the tag response
Return parameter
1. Masklength represents the numbers of significant bits. The user should ensure that others bits are reset for
padding.
Request_flags: option flag to indicate the parameters to use for the flag
response
LRIxK_ERROR_CODE: The command failed. Either there is no tag or the tag
did not manage to perform the request.
LRIxK_ERROR_REQUEST_FLAGS_CODE: The inventory flag is not set.
LRIxK_COMMAND_SUCCESS_CODE: The tag answered the command.
(1)
Note:The command should not be in addressed or selected mode.
ISO15693_Fast_Read_Single_Block function
This function sends, through the CR95HF, a read single block command to the LRIxK
contactless tag in the field. The particularity of this command is the data rate used by the
contactless tag to answer: 53kbits/s.
Table 113. ISO15693_Fast_Read_Single_Block function description
Request_flags: option flag to indicate the parameters to use for the flag
response and if UID is present (addressed)
Tag_UID: pointer on the UID of the tag
Block_number: address of the block to read
Output parameterMyTag: pointer on the structure that contains the tag response
Return parameterNone
Doc ID 022255 Rev 265/105
M24LRxx layerAN3985
7 M24LRxx layer
The M24LRxx layer is composed of:
●M24LRxx_command.c
●M24LRxx_command.h
7.1 Overview
The library includes all the commands defined in the M24LRxx datasheets.
Since M24LRxx-R devices are compliant with ISO/IEC 15693 specifications, several
M24LRxx layer functions are identical to ISO/IEC 15693 functions.
7.2 Command format
7.2.1 CRC16 management
The M24LRxx datasheet defines a two bytes CRC. It is appended to the RF command in
order to check the data transmission between CR95HF and a contactless tag.
Bits 0 of parameter (AppendCRC) of ProtocolSelect command allow to append CRC to all
RF commands.
The ISO15693_ComputeParameterByte_ProtocolSelect function computes the
parameter byte for protocol select according to the parameter provided and sets the append
CRC bit.
Bit 0 has to be set because the function in ISO/IEC 15693 and product layers will not
manage the CRC command. And the contactless tag will not answer to RF command.
7.2.2 Request flag management
The request flag byte is detailed in Chapter 5.3.2: Request flag management.
Some commands of M24LRxx datasheet require specific request flags.
66/105Doc ID 022255 Rev 2
AN3985M24LRxx layer
Table 114 lists the request flags witch are forced inside the M24LRxx layer functions:
●0 means the flag is reset.
●1 means the flag is set.
●- means the user application manages the flag.
Table 114. M24LR* layer forced request flags
Protocol
Extension
flag
Option Flag
Address
flag
Select flag
Function
Inventory
Flag
Inventory100--
Stay Quiet00010
Read Single block0----
Write Single Block0----
Read Multiple Blocks0----
Select00010
Reset to ready 000--
Write AFI00---
Lock AFI00---
Write DSFID00---
Lock DSFID00---
Get system Info010--
Get multiple blocks status010--
Write Sector Password00---
Present Sector Password00---
Fast Read Single Block0----
Fast Inventory Initiated100--
Fast Initiate00000
Fast Read multiple blocks0----
Inventory Initiated100--
Initiate00000
ReadCfg000--
WriteEHCfg00---
SetRstEHEn000--
CheckEHEn000--
WriteDOCfg00---
For more information, please refer to ISO/IEC 15693 specification and to the LRIxK
datasheets.
Doc ID 022255 Rev 267/105
M24LRxx layerAN3985
7.2.3 Request flags and CR95HF_ProtocolSelect functions
The CR95HF_ProtocolSelect function (defined into CR95HF layer) selects the RF protocol
and defines, for a CR95HF device, the datarate and contactless tag response format (single
or double subcarrier). Once the protocol and the RF parameters are configured, the
CR95HF is able to decode only contactless tag responses with same format and datarate.
The datarate and contactless tag response format are also defined in the request flag byte
of each command. The user application must ensure that the datarate and subcarrier flags
match the CR95HF_ProtocolSelect function parameters. This check is performed by the
ISO/IEC 15693 layer functions. If the parameters do not match, the functions are not
executed and the corresponding commands are not sent to the CR95HF.
7.3 M24LRxx commands
M24LRxx devices are based on ISO/IEC 15693 specification. Thus the M24LRxx functions
call the ISO/IEC 15693 functions. Furthermore the M24LRxx functions carry out some
additional checks and modify some parameter as defined in the M24LRxx datasheet.
Table 115 shows the relationship between M24LRxx and ISO/IEC 15693 layer. The "function
name" column presents the M24LRxx functions.
The next column gives the ISO15593 layer functions called. If the functions does not exist in
the ISO/IEC 15693 layer, the "New function" idiom is display.
Table 115. Relationship between M24LRxx and ISO/IEC 15693 layer
Function name
M24LRxx_InventoryISO15693_Inventory
M24LRxx_Stay_QuietISO15693_Stay_Quiet
M24LRxx_Read_Single_BlockNew function
M24LRxx_Write_Single_BlockNew function
M24LRxx_Read_Multiple_BlockNew function
M24LRxx_SelectISO15693_Select
M24LRxx_Reset_to_Ready
M24LRxx_Write_AFIISO15693_Write_AFI
M24LRxx_Lock_AFIISO15693_Lock_AFI
M24LRxx_Write_DSFID
M24LRxx_Lock_DSFIDISO15693_Lock_DSFID
M24LRxx_Get_System_InfoNew functions
New or equivalent
function
ISO15693_Reset_to_R
eady
ISO15693_Write_DSFI
D
Brief description
Sends a ReadSingleBlock
command
Sends a WriteSingleBlock
command
Sends a ReadMultipleBlock
command
Sends a GetSystemInfo
command
68/105Doc ID 022255 Rev 2
AN3985M24LRxx layer
Table 115. Relationship between M24LRxx and ISO/IEC 15693 layer
Function name
M24LRxx_Get_Multiple_Blocks_
Security_Status
M24LRxx_Write_Sector_Password New functions
M24LRxx_Lock_Sector_PasswordNew functions
M24LRxx_Present_Sector_Password
M24LRxx_Fast_Read_Single_Block
M24LRxx_Fast_Inventory_Initia
ted
M24LRxx_Fast_InitiateNew functionSends a FastInitiate command
M24LRxx_Fast_Read_Multiple_Bl
ock
M24LRxx_Inventory_InitiatedNew function
New or equivalent
function
New functions
New functions
New functions
New functionSends a FastInventoryInitiated
New function
Brief description
Sends a GetMultiple
BlocksSecurityStatus
command
Sends A WriteSectorPassword
command
Sends a LockSectorPassword
command
Sends a
PresentSectorPassword
command
Sends a FastReadSingleBlock
command
Sends a
FastReadMultipleBlock
command
Sends a InventoryInitiated
command
M24LRxx_InitiateNew functionSends a Initiate command
M24LRxx_ReadCfg
M24LRxx_WriteEHCfg
M24LRxx_SetRstEHEn
M24LRxx_CheckEHEn
M24LRxx_WriteDOCfg
1. Commands specific to M24LRxx-E device. These commands manage the energy harvesting feature.
7.3.1 M24LRxx command functions
This chapter describes the specific M24LRxx layer functions.
New function
(1)
Sends a ReadCfg command
Sends a WriteEHCfg
command
Sends a SetRstEHen
command
Sends a CheckEHEn
command
Sends a WriteDOCfg
command
Doc ID 022255 Rev 269/105
M24LRxx layerAN3985
M24LRxx_Read_Single_Block function
This function sends, through the CR95HF, a read single block command to a contactless tag
in the field.
Table 116. M24LRxx_Read_Single_Block function description
Prototype
Input parameter
Output parameter MyTag: pointer on the structure that contains the tag response
Return parameter
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
2. If the memory size is more than 8 kbit, the protocol extension flag of request flags should be set.
3. If the memory size is more than 8 kbit, the block number is composed by two bytes.
Request_flags: specifies the actions to be performed by the contactless tag and
whether corresponding fields are present or not.
(1) (2)
Tag_UID: pointer on the UID (optional)
block_number: address of the block to read
(3)
ISO15693_COMMAND_ERROR_CODE: The command failed.
ISO15693_ERROR_REQUEST_FLAGS_CODE: The inventory flag is set.
ISO15693_COMMAND_SUCCESS_CODE: The tag answered the command.
M24LRxx_Write_Single_Block function
This function sends, through the CR95HF, a write single block command to a contactless tag
in the field.
Table 117. M24LRxx_Write_Single_Block function description
Request_flags: specifies the actions to be performed by the contactless tag and
whether corresponding fields are present or not.
Input parameter
Tag_UID: pointer on the UID (optional)
First_Block_number: address of the first block to read
Number_of_Blocks: number of blocks to read after the first one
Output parameter MyTag: pointer on the structure that contains the tag response
M24LRxx_ERROR_CODE: The command failed.
Return parameter
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
2. If the memory size is more than 8 kbit, the protocol extension flag of request flags should be set.
3. If the memory size is more than 8 kbit, the block number is composed by two bytes.
Note:Received data is stored into the internal EEPROM of the MCU.
M24LRxx_Get_System_Info function
This function sends, through the CR95HF, a Get System Information command to a
contactless tag in the field.
Table 119. M24LRxx_Get_System_Info function description
Prototype
Input parameter
Output parameter MyTag: pointer on the structure that contains the tag response
Request_flags: specifies the actions to be performed by the contactless tag and
whether corresponding fields are present or not.
(1)
Tag_UID: pointer on the UID (optional)
Password_Number: number identifying the password (between 1 and 3)
Password: password to compare
M24LRxx_ERROR_CODE: The command failed.
Return parameter
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
Doc ID 022255 Rev 273/105
M24LRxx layerAN3985
M24LRxx_Fast_Read_Single_Block function
This function sends, through the CR95HF, a fast read single block command to a
contactless tag in the field. The datarate of the response is multiplied by 2 (52 kbit/s in this
case).
Table 124. M24LRxx_Fast_Read_Single_Block function description
Request_flags: specifies the actions to be performed by the contactless tag and
whether corresponding fields are present or not.
Tag_UID: pointer on the UID (optional)
Block_number: address of the block to read
(1) (2)
(3)
Output parameter MyTag: pointer on the structure that contains the tag response
M24LRxx_ERROR_CODE: The command failed.
Return parameter
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
2. If the memory size is more than 8 kbit, the protocol extension flag of request flags should be set.
3. If the memory size is more than 8 kbit, the block number is composed by two bytes.
M24LRxx_Fast_Read_Multiple_Block function
This function sends, through the CR95HF, a read multiple block command to a contactless
tag in the field. The datarate of the response is multiplied by 2 (52 kbit/s in this case).
Table 125. M24LRxx_Fast_Read_Multiple_Block function description
Output parameter MyTag: pointer on the structure that contains the tag response
Return parameter
1. AFI field is added if AFI flag of requests flags is set.
2. For example, to transmit a part of the UID of one tag. Masklength represents the number of significant bits.
The user should ensure that other bits are reset for padding.
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not.
Tag_AFI: AFI field to select a contactless tag family (optional)
MaskLength: length of the mask for transmitting
(2)
(1)
Mask: the mask to transmit
Inventory_16_slots_Nb_UID_Retrieved: pointer to retrieve the number of tags
seen during the inventory 16 slots
M24LRxx_ERROR_CODE: The command failed.
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
M24LRxx_Fast_Inventory_Initiated function
This function sends, through the CR95HF, a fast inventory command to a contactless tag in
the field. The datarate of the response is multiplied by 2 (52 kbit/s in this case).
Table 127. M24LRxx_Fast_Inventory_Initiated function description
u8 M24LRxx_Fast_Inventory_Initiated(ISO15693_Tag*
Prototype
Input parameter
Output parameter MyTag: pointer on the structure that contains the tag response
Return parameter
1. AFI field is added if AFI flag of requests flags is set
2. For example to transmit a part of the UID of one tag. Masklength represents the number of significant bits.
The user should ensure that other bits are reset for padding.
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not.
(1)
Tag_UID: pointer on the UID (optional)
Sector_Number: one of the block addresses contained into the sector
Sector_Security_Status: Defines the read write protection and the number of
password protecting the sector.
M24LRxx_ERROR_CODE: The command failed.
Return parameter
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
Doc ID 022255 Rev 277/105
M24LRxx layerAN3985
M24LRxx_Present_Sector_Password function
This function sends, through the CR95HF, a present sector password command to a
contactless tag in the field.
Table 132. M24LRxx_Present_Sector_Password function description
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not.
Tag_UID: pointer on the UID (optional)
(1)
Password_Number: number identifying the password (between 1 and 3)
Password: password to compare
Output parameter MyTag: pointer on the structure that contains the tag response
M24LRxx_ERROR_CODE: The command failed.
Return parameter
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: Tag answered the command.
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
M24LRxx_Fast_Read_Single_Block function
This function sends, through the CR95HF, a fast read single block command to a
contactless tag in the field. The datarate of the response is multiplied by 2 (52 kbit/s in this
case)
Table 133. M24LRxx_Fast_Read_Single_Block function description
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not.
(1) (2)
Tag_UID: pointer on the UID (optional)
Block_number: address of the block to read
(3)
M24LRxx_ERROR_CODE: The command failed.
Return parameter
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
2. If the memory size is more than 8 kbit, the protocol extension flag of request flags should be set.
3. If the memory size is more than 8 kbit, the block number is on two bytes.
78/105Doc ID 022255 Rev 2
AN3985M24LRxx layer
M24LRxx_Fast_Read_Multiple_Block function
This function sends, through the CR95HF, a fast read multiple block command to a
contactless tag in the field. The datarate of the response is multiplied by 2 (52 kbit/s in this
case).
Table 134. M24LRxx_Fast_Read_Multiple_Block function description
Request_flags: specifies the actions to be performed by the contactless tag and
whether corresponding fields are present or not.
Tag_AFI: AFI field to select a contactless tag family (optional)
MaskLength: length of the mask for transmitting
(2)
(1)
Mask: the mask to transmit
Inventory_16_slots_Nb_UID_Retrieved: pointer to retrieve the number of tags
seen during the inventory 16 slots.
Output parameter MyTag: pointer on the structure that contains the tag response
M24LRxx_ERROR_CODE: The command failed.
Return parameter
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
1. AFI field is added if AFI flag of requests flags is
2. For example, to transmit a part of the UID of one tag. Masklength represents the numbers of significant
bits. The user should ensure that others bits are reset for padding.
Doc ID 022255 Rev 279/105
M24LRxx layerAN3985
M24LRxx_Fast_Inventory_Initiated function
This function sends, through the CR95HF, a fast inventory command to a contactless tag in
the field. The datarate of the response is multiplied by 2 (52 kbit/s in this case).
Table 136. M24LRxx_Fast_Inventory_Initiated function description
u8 M24LRxx_Fast_Inventory_Initiated(ISO15693_Tag*
Prototype
Input parameter
Output parameter MyTag: pointer on the structure that contains the tag response
Return parameter
1. AFI field is added if AFI flag of requests flags is
2. For example, to transmit a part of the UID of one tag. Masklength represents the numbers of significant
bits. The user should ensure that others bits are reset for padding.
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not.
(1)
Tag_UID: pointer on the UID (optional)
M24LRxx_ERROR_CODE: The command failed.
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
80/105Doc ID 022255 Rev 2
AN3985M24LRxx layer
M24LRxx_Fast_Initiate function
This function sends, through the CR95HF, a fast initiate command to a contactless tag in the
field. The datarate of the response is multiplied by 2 (52 kbit/s in this case).
Table 138. M24LRxx_Fast_Initiate function description
Prototype
Input parameter
Output parameter MyTag: pointer on the structure that contains the tag response
Return parameter
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not.
(1)
Tag_UID: pointer on the UID (optional)
M24LRxx_ERROR_CODE: The command failed.
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: Tag answered the command.
7.3.2 M24LRxx Energy Harvesting functions
These functions are specific to energy harvesting M24LRxxE-R devices.
Compilation management
The USE_ENERGY_HARVESTING_COMMANDS constant allows to compile or not these
commands.
M24LRxx_ReadCfg function
This function sends, through the CR95HF, read Config command to a contactless in the
field. On receiving the read Config command the M24LRxxE-R contactless tag reads the
configuration byte and sends back its value.
Table 139. M24LRxx_ReadCfg function description
Prototype
Input parameter
Output parameter MyTag: pointer on the structure that contains the tag response
Return parameter
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not.
(1)
Tag_UID: pointer on the UID (optional)
M24LRxx_ERROR_CODE: The command failed.
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
Doc ID 022255 Rev 281/105
M24LRxx layerAN3985
M24LRxx_Write_EH_Cfg function
This function sends, through the CR95HF, Write_EH_Cfg command to a contactless tag in
the field.
contactless tag writes the data provided to the configuration byte and reports the status of
the command.
Table 140. M24LRxx_Write_EH_Cfg function description
Prototype
Input parameter
Output parameter MyTag: pointer on the structure that contains the tag response
Return parameter
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
2. Only bits 0 to 2 are written, bit 3 is ignored.
On receiving the write Energy Harvesting Configuration command, the
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not.
Tag_UID: pointer on the UID (optional)
Configuration_Byte: the byte to write to the configuration byte
M24LRxx_ERROR_CODE: The command failed.
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
(1)
M24LRxxE-R
(2)
M24LRxx_Write_DO_Cfg function
This function sends, through the CR95HF, Write_DO_Cfg command to a contactless tag in
the field. On receiving the Write_DO_Cfg command the M24LRxxE-R contactless tag writes
the data provided to the configuration byte and reports the status of the command.
Caution:M24LRxx_Write_DO_Cfg function description
Prototype
Input parameter
Output parameter MyTag: pointer on the structure that contains the tag response
Return parameter
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
2. Only bits 0 to 2 are written, bit 3 is ignored.
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not.
(1)
Tag_UID: pointer on the UID (optional)
Configuration_Byte: the byte to write to the configuration byte
(2)
M24LRxx_ERROR_CODE: The command failed.
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
82/105Doc ID 022255 Rev 2
AN3985M24LRxx layer
M24LRxx_SetRst_EH_en function
This function sends, through the CR95HF, a SetRst_EH_en command to a contactless tag
in the field.
contactless tag set or reset the EHenable bit, within the volatile control register.
Table 141. M24LRxx_SetRst_EH_en function description
Prototype
Input parameter
Output parameter MyTag: pointer on the structure that contains the tag response
Return parameter
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
2. Value to enable the energy harvesting: M24LRxx_CONTROL_BYTE_EH_ENABLE
Value to disable the energy harvesting: M24LRxx_CONTROL_BYTE_EH_DISABLE
On receiving the set reset Energy Harvesting Enable command, the
Request_flags: Specifies the actions to be performed by the contactless tag
and whether corresponding fields are present or not.
Tag_UID: pointer on the UID (optional)
Set_Reset: Enable or disable the energy harvesting.
M24LRxx_ERROR_CODE: The command failed.
M24LRxx_ERROR_PARAMETERS_REQUEST_FLAGS: The inventory flag is
set.
M24LRxx_SUCCESS_CODE: The tag answered the command.
(1)
(2)
M24LRxxE-R
M24LRxx_Check_EH_En function
This function sends, through the CR95HF, a Check_EH_En command to a contactless tag
in the field. On receiving the Check Energy Harvesting enabled command, the M24LRxxE-R
contactless tag reads the control register and sends back its value.
Table 142. M24LRxx_Check_EH_En function description
Prototype
Input parameter
Output parameter MyTag: pointer on the structure that contains the tag response
Return parameter
1. The Address flag indicates if Tag_UID field will be added to the command (addressed mode).
Configuration_Byte: the byte containing the data available in the tag structure
at dataField[M24LRxx_CONFIGURATION_BYTE_CURSOR]
Output parameter None
M24LRxx_CONFIGURATION_BYTE_EH_ENABLED: The energy harvesting is
Return parameter
enabled.
M24LRxx_CONFIGURATION_BYTE_EH_DISABLED: The energy harvesting
is disabled.
Doc ID 022255 Rev 285/105
Application exampleAN3985
8 Application example
The application example provided with this firmware illustrates the library functions within an
application environment. The application example focuses on the management of an
inventory command and on the low power state of STM8L and CR95HF devices. Different
low power states can be issued by using the joystick of STM8L Eval board.
This application example configures the STM8L and CR95HF in order to illustrate some
CR95HF and STM8L functionalities.
86/105Doc ID 022255 Rev 2
AN3985Application example
MS19960V1
Power On Reset
Board Initialization
(1)
ISO/IEC 15693 Protocol
Selection (4)
Tag Hunting
(5)
Display Initialization
(2)
Configuration
success
No
Yes
Communication Test
(7)
User Application
(6)
Test Config
(3)
Display Configuration
test error
Report of
communication
failure
No
Yes
Communication
resumed
No
Yes
8.1 Main functions
Figure 4 presents the main function. Some details are given below in the next chapter.
Figure 4.Application example main functions
The application example is located in the main.c file and user_application.c files.
Doc ID 022255 Rev 287/105
Application exampleAN3985
8.1.1 Board initialization
This function configures the STM8L resources needed:
●Interface bus to communicate with CR95HF device (through SPI or UART bus)
●Timers
●LCD
●I2C
●GPIO (LED & joystick)
Delay management
The delays are handled by two timers. Timer #4 allows to introduce a delay between two
instructions, whereas timer #2 is used with interrupts to control the execution time of a group
of instructions.
8.1.2 Display initialization
The LCD screen is initialized with the Logo of the STMicroelectronics company and the
CR95HF product name.
8.1.3 Test configuration
This function configures the CR95HF for the application example.
Table 147. Test config procedure
StepAction
1The first step is to display the interface bus selected to communicate with CR95HF device.
2A pulse is sent to CR95HF to wake it up.
An ECHO command is sent while there is no valid answer. If the echo fails, a message is
displayed on the screen and the following procedure is repeated while the echo command
fails:
– Send a pulse to CR95HF
3
– Echo command
– SPI Reset
At this point, STM8L and CR95HF can communicate which each other.
4The internal EEPROM of the STM8L is unlocked.
5A protocol select command is issued.
6A calibration of the tag detection feature is launched.
7A success message is displayed.
88/105Doc ID 022255 Rev 2
AN3985Application example
MS19964V1
Start of Wait for interrupt mode
End of Wait for interrupt mode
Wake Up STM8L
STM8L timeout
= 5s ?
No
Yes
CR95HF Detect
a tag ?
No
Yes
Test communication
Ok ?
Yes
Wake Up CR95HF
Wake Up CR95HF
Wake Up STM8L
Put to sleep CR95HF
Figure 5 details these different steps.
Figure 5.Test config procedure flowchart
8.1.4 ISO/IEC 15693 Protocol selection
8.1.5 Tag hunting
Before beginning to communicate with a contactless tag, the RF protocol and its parameters
should be set. This step ensures that it is done before entering the main loop.
The Tag Hunting function sends an inventory and a Get system Info command. The
contactless tag responses are stored into the MyTag15693 structure.
The inventory sent is an inventory 16 slots, therefore if several contactless tags answer the
command, then only one UID will be retrieved or potentially 16 structures will be needed.
The solution proposed and used in the inventory 16 slots is to store the UIDs retrieved into
the internal EEPROM of the STM8L. When the inventory is finished, the number of
contactless tags seen is available thanks to the
ISO15693_Inventory_16slots_Nb_UID_Retrieved variable.
Commands may be addressed to each tag seen individually. The procedure is exposed
using the Get System Info Command. If only one tag answers the inventory, its UID is stored
in the STM8L EEPROM, and on top of that the UID is written in the Tag structure.
Doc ID 022255 Rev 289/105
Application exampleAN3985
MS19962V1
Joystick
Left State :
A calibration of the tag detector
is launched.
Then a test is done in cleared
field.
This procedure has a duration of
around 6 seconds during while
the CR95HF is in Idle State and
looks for contactless tag.
The STM8L displays the number
of seconds remaining with dots.
Right State :
Low power mode.
When pressed, the STM8L and
the CR95HF turn into one of
three low power modes
described below. (1)
Up state :
An IDN command is sent to the
CR95HF and its response is
displayed on LCD.
Down State :
RF Field is alternatively turned
on and turned off.
For one slot inventory, only UID can be retrieved or there will be a collision. To prevent a
collision (with 1 or 16 slots), a mask can be added to the inventory command. The mask
corresponds to the LSB bits of the UID, the contactless tag compares those with its UID and
answers only if they match. The length of the mask is in bits, unused bits in the byte must be
reset in order to transmit whole bytes.
8.1.6 Display
If the inventory and Get System Info commands passed, then the UID and the ICRef of the
tag are displayed. Note that as the MSB byte is common to all contactless tags, it is not
displayed.
For STMicroelectronics manufactured contactless tags, a database containing the ICref is
present in the miscellaneous files.
8.1.7 User application
User application is based on the utilization of the joystick present on the STM8L 1528-Eval
board. This enables the user to perform the actions described in Figure 6:
Figure 6.Joystick utilization
1. A detection of a contactless tag or pressing the Reset button can exit this mode.
8.1.8 Low power modes
90/105Doc ID 022255 Rev 2
The CR95HF embeds a low power state named "tag detector state". In this state, the
CR95HF device is turned in Idle state and will periodically check if a tag is present in the
volume operation. If a tag is detected, the CR95HF devices will wake-up.
The STM8L integrates different low power modes. Once STM8L is turned in low power
mode, it can be waken up by itself using an internal timer or by an external interruption.
AN3985Application example
MS19963V1
CR95HF
(1) Contactless tag
into operating
volume
2) STM8L send an pulse to
wake up CR95HF
1) internal timer
wakes up STM8L
3) A tag is detected, CR95HF
sent a pulse to wake up STM8L
2) A tag is detected,
CR95HF will wake up
STM8L
Table 148 sums up the three low power modes available in this application example.
Table 148. Low power modes descriptions
Mode
Periodical
wake-up
1STM8L
2CR95HF
3CR95HF
Low power modeWake-up sourceLow power mode Wake-up source
Wait For Interrupt
HaltCR95HFTag Detection Tag Detection
HaltCR95HF
STML8CR95HF
– Internal RTC clock
– CR95HF
Tag Detection
– Tag Detection
–Timer
– Tag Detection
–STM8L
– Tag Detection
– Internal Timer
In each case, both CR95HF and STM8L devices are turned into low power state and the Tag
detection states are activated. The difference between the three states is the second source
of the system wake-up. It can be issued either by CR95HF or by STM8L.
Mode#1: Wait For Interrupt mode
In this state, the CPU of the STM8L is deactivated. An RTC interrupt is sent every 5 seconds
to STM8L. If the CR95HF has not seen a tag during 5 seconds, the STM8L's RTC clock
wakes up the MCU which sends an Interrupt to wake up the CR95HF. Then the
communication between CR95HF and STM8L is tested and the CR95HF is turned into Idle
state again before the STM8L returns into Wait For Interrupt mode. Figure 7 schematizes
these actions.
Figure 7.Wait for interrupt mode schematic
Doc ID 022255 Rev 291/105
Application exampleAN3985
MS19964V1
Start of Wait for interrupt mode
End of Wait for interrupt mode
Wake Up STM8L
STM8L timeout
= 5s ?
No
Yes
CR95HF Detect
a tag ?
No
Yes
Test communication
Ok ?
Yes
Wake Up CR95HF
Wake Up CR95HF
Wake Up STM8L
Put to sleep CR95HF
MS19965V1
CR95HF
1) Contactless tag
into operating
volume
2) A tag is detected, CR95HF
sent a pulse to wake up STM8L
STM8L
Figure 8.Wait for interrupt mode flowchart
92/105Doc ID 022255 Rev 2
Mode#2: Halt Mode
The Halt State is the low power consumption state of the STM8L. The main clock and all
peripherals are switched off. Only an interrupt on I/O pin or reset can wake up the STM8L. In
this state, only tag detection or a pressure on the reset button can wake up the system.
Figure 9.Halt mode schematic
AN3985Application example
MS19966V1
Start of Halt mode
End of Halt mode
Turn CR95HF in Idle mode
CR95HF Detect
a tag ?
No
Yes
Turn STM8L in halt mode
MS19967V1
CR95HF
1) Contactless tag
into operating
volume
2) If a tag is detected or
CR95HF timout is over,
CR95HF sent a pulse to
wake up STM8L
STM8L
1) CR95HF timer
Figure 10. Halt mode flowchart
Mode#3: Halt CR95HF Timer mode
In this state, the STM8L is turned into halt state and the CR95HF wakes up periodically
around every 5 seconds thanks to its internal Timer. So when the CR95HF wakes up, it does
so with the STM8L which determines what caused the waking up. If it is the timer, then the
STM8L sends again the Idle command. If a tag has been detected, the field is turned on in
ISO/IEC 15693 protocol to communicate with the contactless tag.
Note:An IRQ_IN
recommended to keep an external interrupt as a way of waking up the CR95HF.
Figure 11. Halt CR95HF Timer mode schematic
interrupt can wake up the CR95HF in all modes. Indeed, it is warmly
Doc ID 022255 Rev 293/105
Application exampleAN3985
MS19968V1
Start of CR95HF Timer Mode
End of Wait for interrupt mode
Turn CR95HF in Idle mode
CR95HF timeout
= 5s ?
No
No
Yes
CR95HF Detect
a tag ?
No
Yes
Tag detected ?
Yes
Turn STM8L in halt mode
Wake Up CR95HF
Wake Up STM8L
Check Wake up cause
Figure 12. Halt CR95HF Timer mode flowchart
8.1.9 Communication test
While waiting for an answer from the CR95HF, a timer is launched and the polling procedure
is active during a limited period. If, at the end of this period, no answer is ready, the STM8L
assumes that no answer will come and it increments a global counter called
communication_watchdog. At the end of the secondary loop, this counter is checked and
compared with a maximum value of tolerance. If it overtakes this value, a procedure is
launched in order to resume the communication possibly lost.
94/105Doc ID 022255 Rev 2
AN3985Application example
MS19969V1
END
CR95HF Interrupt
Send Echo command
Send Echo command
Report of
communication
failure ?
No
Yes
Echo passed
Yes
No
Reset CR95HF
CR95HF Interrupt
Echo passed
Yes
No
Figure 13. Communication test flowchart
Note:While the communication_watchdog variable is not reset, this function will be called
within the main loop.
Doc ID 022255 Rev 295/105
Application exampleAN3985
8.2 Hardware
Two STM8L boards can be used with this firmware:
●The STM8L discovery board. It can be used as a demonstration board.
●The STM8L evaluation board. It can be used as a development board.
8.2.1 STM8L discovery board
The STM8L Discovery board helps you to discover the STM8L ultra low power features and
to develop and share your applications. It is based on an STM8L152C6T6 and includes an
ST-Link embedded debug tool interface, an LCD, LEDs and push buttons.
The LCD of the discovery board used the most of available GPIO and the available GPIO is
not enough to communicate with the CR95HF devices. This is the reason why the LCD of
STM8L discovery board is deactivated.
The LEDs are the only information source for the user application.
The STM8L discovery board documentation is available on STM website.
8.2.2 STM8L evaluation board
The STM8L1528-EVAL evaluation board is designed as a complete demonstration and
development platform for the STM8 core based STM8L152M8T6 microcontroller with I2C,
two SPI channels, 3 USART channels, 12-bit ADC, two 12-bit DACs, an LCD driver, internal
SRAM, data EEPROM and Flash program memory as well as SWIM debugging support.
The full range of hardware features on the board is provided to help you evaluate all the
MCU peripherals (motor control, USART, microphone, audio DAC, LCD, IR LED, IrDA, SPI
Flash, MicroSD card, temperature sensor, EEPROM… etc.) and develop your own
applications. Extension headers make it possible to easily connect a daughter board or
wrapping board for your specific application.
An ST-LINK V2 is integrated on the board as an embedded in-circuit debugger and
programmer for the STM8 MCU.
The STM8L evaluation documentation is available on STM website.
8.2.3 CR95HF plug board
The PLUG-CR95HF-B is a board which includes a CR95HF device and a matched antenna.
A host configured as a master can communicate with CR95HF through the SPI bus.
The PLUG-CR95HF-B is powered through the Vps pin and no external power supply is
required. It includes a CR95HF contactless transceiver, a 47 x 34 mm 13.56 MHz inductive
etched antenna and its associated tuning components.
96/105Doc ID 022255 Rev 2
AN3985Application example
8.3 Software
8.3.1 ST Visual Develop
ST Visual Develop (STVD) provides an easy-to-use, efficient environment for start-to-finish
control of application development - from building and debugging the application code to
programming the microcontroller.
Cosmic is the compiler toolchain used by ST Visual Develop. There is a 1 year free license
limited to 32 Kbytes of code and data which requires registration.
For further information about the license, see the Cosmic Software website.
8.4 Project
The project was built using the MCD standard library which is included in the
STM8L15x_StPeriph_Driver folder. In order to update the library, a copy of the
stm8l15x_it.h, stm8l15x_it.c and the stm8l15x_conf.h is required to store the modifications
made within those files. Then the whole folder can be updated with the latest version before
replacing the three files previously copied.
8.4.1 Opening the Project:
First step: Launch ST Visual Develop
Second Step: In the File menu, open Workspace, browse to the project folder and select
CR95HF_STM8L.stw
Figure 14. Project tree structure
Doc ID 022255 Rev 297/105
Application exampleAN3985
8.4.2 Compilation / Debug
In order to compile and debug the project, there are few steps to perform.
1) First step: Build
On menu bar, click on Build menu, then click on Build; the project will be built and any
errors will be displayed on the lower part of the screen.
2) Second Step: Configure the Debug Instruments
Connect a USB cable or an ST-Link between the board and the USB port of the
computer. Note that using the Swim, instead of ST-Link embedded, requires a power
supply device.
See the board datasheet and User Manual for further information.
->DebugInstruments Settings, Select Swim ST-Link, the target Port Selection should be
updated automatically. If not, select Add and select the USB port or let the software
detect the port automatically.
Figure 15. Debug Instruments Settings dialog box
3) Third Step: Launch the debugger
->Debug-> Start Debugging or press the button
Once the debugger is launched, the following menu allows to run the application, run it
step by step, by function, etc… and to observe the behavior of the code and the values
taken by the different variables.
Refer to ST Visual Develop Information Manuals for further information about the debugging
mode.
98/105Doc ID 022255 Rev 2
AN3985Application example
8.5 Compilation management
This firmware embeds all the commands of CR95HF devices, LRIxK and M24LRxx
contactless tag. Furthermore, some advanced functionalities are available such as the tag
detection state or the read/write multiple block process. All these features consume memory
space and can be removed to minimize the code size.
8.5.1 Conditional compilation
In order to save STM8L memory space, several actions have been performed. The main
one is the conditional compilation. This allows to determine what is needed. There are three
levels of conditional compilation.
Level 1
: STM8L15x_StPeriph_Driver
All the functions that are not called within the library are not compiled. In order to use those
functions, there are two solutions:
Solution 1
after the includes) //#define USE_FULL_"peripheral concerned"_ Board
: Locate in the .h file of the peripheral concerned the following command (right
(a)
and
uncomment the line. As a consequence, all the functions will become available.
Solution 2
: Locate the function to release and erase the #ifdef USE_FULL_"peripheralconcerned"_ Board and #endif commands. If the function
is in a group of functions, insert a #endif before the function and a #ifdef USE_FULL_"peripheralconcerned"_ Board right after. This procedure should be
done in both the .c and the .h files.
Level 2
: Board Specificities
This level is completely transparent because it is related to boards. The specific I/O
configurations linked to one board (STM8L 1528-Eval for example) are not compiled on the
other board (STM8L Discovery for example).
Level 3
: Functionalities
Several functionalities are available within the libraries. Table 149 lists the functionalities and
the commands to uncomment to use them.
Table 149. Functionalities description
Name of the
functionality (brief)
Description
Code line to
uncomment
Location
STM8L-1528 Eval
STM8L-Discovery
Board
RTC clock function
a. Where "peripheral concerned" is the name of the peripheral as written in its file.
To use the STM8L1528 Eval board
To use the STM8LDiscovery board
Used in Low Power
Mode, allows to
generate an interruption
at programmed time
contactless tag and
then to store it into the
external EEPROM of
the STM8L
Release the Write
Multiple Block
command
Release the Energy
Harvesting commands
related to M24LRX-E
devices
Demonstration of some
commands
8.5.2 Polling method
In SPI communication, the application must ensure that the CR95HF is ready to transmit
data before trying to receive a response. This could be performed by two ways:
●Polling byte: the STM8L transmits a control byte (0b11) to the CR95HF, and checks the
byte received in response.
●Polling IRQ_OUT (CR95HF): when the CR95HF is ready to transmit data, a transition
on its IRQ_OUT
pin can be seen.
Description
Code line to
uncomment
#define
USE_EXTERN_EEPROM
_FUNCTION
(STM8L-1528 Eval
Functionality should be
used)
#define
USE_FULL_ISO15693
_COMMANDS
#define
USE_ENERGY_HARVES
TING_COMMANDS
#define
USE_USER_APPLICAT
ION
Location
Board_config.h
ISO15693_command.h
M24LRxx_command.h
Main.c
The software lets the user chose its method by changing the value of the constant below in
the CR95HF_driver.h
#define WAITING_CR95HF_RESPONSE_METHOD WAITING_USING_IRQ
The two choices are WAITING_USING_IRQ and WAITING_USING_POLLING
8.6 Hardware layout and configuration
The STM8L1528-EVAL evaluation board is designed around the STM8L152M8T6 (80-pin
LQFP package). Figure 16 illustrates the connection between STM8L152M8T6 and
peripherals (CR95HF device, LCD screen, EEPROM, USART, and embedded STLINK).
100/105Doc ID 022255 Rev 2
Loading...
+ 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.