AN3985
Application note
Using the CR95HF library with STM8L microcontrollers
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.
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).
■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
February 2012 |
Doc ID 022255 Rev 2 |
1/105 |
www.st.com
Contents |
AN3985 |
|
|
Contents
1 |
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. 1 |
|
|
1.1 |
Reference documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
1 |
2 |
Acronyms and notational conventions . . . . . . . . . . . . . . . . . . . . . . . . . . |
9 |
|
|
2.1 |
List of terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
9 |
|
2.2 |
Notational conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
10 |
2.2.1 Binary number representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.2.2 Hexadecimal number representation . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.2.3 Decimal number representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 |
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
11 |
|
|
3.1 |
CR95HF overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
11 |
|
3.2 |
Library overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
11 |
3.2.1 Example of an application architecture . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.2.2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 |
CR95HF low level layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
13 |
|
|
4.1 |
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
13 |
|
4.2 |
Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
13 |
4.2.1 Command format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.2.2 Response format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.2.3 Protocol selection structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.2.4 Idle structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.3 CR95HF layer functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.3.1 Command functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.3.2 Additional functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.3.3 Low power mode functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.3.4 Is functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.3.5 Advanced functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.3.6 Application example: protocol selection and communication . . . . . . . . . 28
5 |
ISO/IEC 15693 layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
29 |
|
|
5.1 |
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
29 |
|
5.2 |
Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
29 |
2/105 |
Doc ID 022255 Rev 2 |
AN3985 |
Contents |
|
|
5.2.1 Structures of command and response of an ISO/IEC 15693 tag . . . . . . 29
5.3 ISO/IEC 15693 command format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.3.1 SOF and EOF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.3.2 Request flag management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.3.3 Command code and Data management . . . . . . . . . . . . . . . . . . . . . . . . 32 5.3.4 CRC16 management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
|
5.4 |
ISO/IEC 15693 layer functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
33 |
|
|
|
5.4.1 |
Compute parameter byte functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
36 |
|
|
5.4.2 |
ISO/IEC 15693 command functions . . . . . . . . . . . . . . . . . . . . . . . . . . . |
38 |
|
|
5.4.3 |
Build up functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
47 |
|
|
5.4.4 |
Is Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
48 |
|
|
5.4.5 |
Get functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
52 |
|
|
5.4.6 |
CRC16 functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
57 |
|
|
5.4.7 |
Fill In functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
58 |
6 |
LRIxK layer . |
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
60 |
6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 6.2 Command format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
6.2.1 CRC16 management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 6.2.2 Request flag management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 6.2.3 Request flags and CR95HF_ProtocolSelect functions . . . . . . . . . . . . . 61
|
6.3 |
LRIxK layer commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
62 |
|
|
6.3.1 LRIxK command functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
63 |
7 |
M24LRxx layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
66 |
|
|
7.1 |
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
66 |
|
7.2 |
Command format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
66 |
7.2.1 CRC16 management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 7.2.2 Request flag management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 7.2.3 Request flags and CR95HF_ProtocolSelect functions . . . . . . . . . . . . . 68
7.3 M24LRxx commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
7.3.1 M24LRxx command functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 7.3.2 M24LRxx Energy Harvesting functions . . . . . . . . . . . . . . . . . . . . . . . . . 81
8 |
Application example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
86 |
|
8.1 Main functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
87 |
Doc ID 022255 Rev 2 |
3/105 |
Contents |
AN3985 |
|
|
8.1.1 Board initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 8.1.2 Display initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 8.1.3 Test configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 8.1.4 ISO/IEC 15693 Protocol selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 8.1.5 Tag hunting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 8.1.6 Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 8.1.7 User application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 8.1.8 Low power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 8.1.9 Communication test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
8.2 |
Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
96 |
|
|
8.2.1 |
STM8L discovery board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
96 |
|
8.2.2 |
STM8L evaluation board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
96 |
|
8.2.3 |
CR95HF plug board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
96 |
8.3 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
|
8.3.1 |
ST Visual Develop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
97 |
|
8.3.2 |
Cosmic compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
97 |
8.4 |
Project |
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
97 |
|
8.4.1 |
Opening the Project: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
97 |
|
8.4.2 |
Compilation / Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
98 |
8.5 |
Compilation management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
99 |
8.5.1 Conditional compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 8.5.2 Polling method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
8.6 Hardware layout and configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 8.7 Pinout description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
8.7.1 PLUG-CR95HF-B Board pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
8.8Switching between STM8L 1528-Eval and STM8L Discovery boards . . 103
9 |
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
104 |
4/105 |
Doc ID 022255 Rev 2 |
AN3985 |
List of tables |
|
|
List of tables
Table 1. List of terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Table 2. Command fields formats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Table 3. Response field formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Table 4. Protocol parameter formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Table 5. Protocol values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Table 6. Idle structure parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Table 7. CR95HF layer functions based on CR95HF commands . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Table 8. CR95HF layer additional functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Table 9. Low Power mode functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Table 10. CR95HF layer IS functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Table 11. CR95HF layer advanced functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Table 12. CR95HF_IDN function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Table 13. CR95HF_Echo function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Table 14. CR95HF_ProtocolSelect function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Table 15. Input parameters settings for ISO/IEC 15693 protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Table 16. CR95HF_SendRecv function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Table 17. SendRecv correct response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Table 18. SendRecv error response. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Table 19. CR95HF_Idle function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Table 20. CR95HF_Rd_Wake_up_Reg function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Table 21. CR95HF_Rd_Analog_Register_Config_B function description . . . . . . . . . . . . . . . . . . . . . 21 Table 22. CR95HF_Baud_Rate function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Table 23. CR95HF_SendEOF function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Table 24. CR95HF_FieldOff function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Table 25. CR95HF_Hibernate function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Table 26. CR95HF_Sleep function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Table 27. CR95HF_TagDetecting function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Table 28. CR95HF_IdlebyTimer function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Table 29. CR95HF_IsReaderResultOK function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Table 30. Is_IRQ_in_Interupt_Wake_up_Condition function description . . . . . . . . . . . . . . . . . . . . . . 24 Table 31. Is_NSS_Interrupt_Wake_up_Condition function description . . . . . . . . . . . . . . . . . . . . . . . 25 Table 32. Is_Tag_Detected_Wake_up_Condition function description . . . . . . . . . . . . . . . . . . . . . . . 25 Table 33. Is_Tag_Detected_Wake_up_Condition function description . . . . . . . . . . . . . . . . . . . . . . . 25 Table 34. CR95HF_Modify_Baud_Rate function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Table 35. CR95HF_Idle_Detector_Calibration function description . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Table 36. CR95HF_Wait_Wake_up_From_Idle function description . . . . . . . . . . . . . . . . . . . . . . . . . 27 Table 37. CR95HF_Wake_up_CR95HF function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Table 38. ISO15693_tag structure description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Table 39. Request flag bits description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Table 40. Request flag bits values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Table 41. Bit for request flag with inventory flag reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Table 42. Bit for request flag with inventory flag reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Table 43. Functions to compute parameter byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Table 44. ISO15693 library command based on ISO/IEC 15693 specification . . . . . . . . . . . . . . . . . 33 Table 45. Functions to assemble ISO/IEC 15693 command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Table 46. Get functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Table 47. CRC16 functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Table 48. Structure Fill In functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Table 49. ISO15693_ComputeParameterByte_ProtocolSelect function description . . . . . . . . . . . . . 36 Table 50. ComputeByte function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Table 51. ISO15693_Inventory function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Doc ID 022255 Rev 2 |
5/105 |
List of tables |
AN3985 |
|
|
Table 52. ISO15693_StayQuiet function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Table 53. ISO15693_Read_Single_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Table 54. ISO15693_Write_Single_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Table 55. ISO15693_Write_Single_Block results depending on Option flag . . . . . . . . . . . . . . . . . . . 40 Table 56. ISO15693_Lock_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Table 57. ISO15693_Read_Multiple_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Table 58. ISO15693_Write_Multiple_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Table 59. ISO15693_Select function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Table 60. ISO15693_Reset_to_Ready function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Table 61. ISO15693_Write_AFI function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Table 62. ISO15693_ Lock_AFI function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Table 63. ISO15693_ WriteDSFID function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Table 64. ISO15693_Lock_DSFID function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Table 65. ISO15693_Get_System_Info function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Table 66. ISO15693_Get_Multiple_Blocks_Security_Status function description . . . . . . . . . . . . . . . 45 Table 67. ISO15693_Custom_Commands function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Table 68. ISO15693_SendEOF function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Table 69. ISO15693_Add_UID_to_command description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Table 70. ISO15693_Add_Mask_to_command function description . . . . . . . . . . . . . . . . . . . . . . . . . 47 Table 71. ISO15693_Add_Request_Flags_Command_code_to_command function description . . . 48 Table 72. ISO15693_Is_ResponseFlags_noError_Detected function description . . . . . . . . . . . . . . . 48 Table 73. ISO15693_Is_Request_Flags_ok function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Table 74. ISO15693_Is_Collision_Flag_Set function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Table 75. ISO15693_IsCRC_Flag_Set function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Table 76. ISO15693_Is_CorrectCRC16_Check function description . . . . . . . . . . . . . . . . . . . . . . . . . 49 Table 77. ISO15693_Is_TagConstructor_STM function description . . . . . . . . . . . . . . . . . . . . . . . . . 50 Table 78. ISO15693_Is_Memory_programming function description. . . . . . . . . . . . . . . . . . . . . . . . . 50 Table 79. ISO15693_Is_DSFID_Present_Infoflag function description . . . . . . . . . . . . . . . . . . . . . . . 50 Table 80. ISO15693_Is_AFI_Present_Infoflag function description . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Table 81. ISO15693_Is_MemSize_Present_Infoflag function description . . . . . . . . . . . . . . . . . . . . . 51 Table 82. ISO15693_Is_ICRef_Present_Infoflag function description . . . . . . . . . . . . . . . . . . . . . . . . 51 Table 83. ISO15693_Get_Subcarrier_Flag function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Table 84. ISO15693_Get_DataRate_Flag function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Table 85. ISO15693_Get_Inventory_Flag function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Table 86. ISO15693_Get_ProtocolExtension_Flag function description . . . . . . . . . . . . . . . . . . . . . . 53 Table 87. ISO15693_Get_Select_Flag function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Table 88. ISO15693_Get_Address_Flag function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Table 89. ISO15693_Get_AFI_Flag function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Table 90. ISO15693_Get_Slots_Flag function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Table 91. ISO15693_Get_Option_Flag function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Table 92. ISO15693_Get_RFU_Flag function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Table 93. ISO15693_Get_NumberofByte_MemSize_using_ICREF function description. . . . . . . . . . 55 Table 94. ISO15693_Get_Size_of_Block_using_ICRef function description . . . . . . . . . . . . . . . . . . . 55 Table 95. ISO15693_Get_Size_of_Block_using_MemSize function description . . . . . . . . . . . . . . . . 56 Table 96. ISO15693_Get_MemSize_kbits function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Table 97. ISO15693_Get_MemSize_bits function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Table 98. ISO15693_Get_UID_from_EEPROM function description. . . . . . . . . . . . . . . . . . . . . . . . . 57 Table 99. ISO15693_CRC16 function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Table 100. ISO15693_IsCorrectCRC16Residue function description . . . . . . . . . . . . . . . . . . . . . . . . . 57 Table 101. ISO15693_CRC16_EEPROM function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Table 102. ISO15693_IsCorrectCRC16Residue_EEPROM function description. . . . . . . . . . . . . . . . . 58 Table 103. ISO156693_Check_Data_Received_Start_Process function description . . . . . . . . . . . . . 58 Table 104. ISO15693_Retrieve_UID function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Table 105. ISO15693_Retrieve_ICRef function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
6/105 |
Doc ID 022255 Rev 2 |
AN3985 |
List of tables |
|
|
Table 106. Request flag management description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Table 107. LRIxK layer commands description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Table 108. LRIxK_Kill function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Table 109. LRIxK_Write_Kill function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Table 110. LRIxK_Lock_Kill function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Table 111. LRIxK_Inventory_Initiated function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Table 112. LRIxK_Initiate function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Table 113. ISO15693_Fast_Read_Single_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . 65 Table 114. M24LR* layer forced request flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Table 115. Relationship between M24LRxx and ISO/IEC 15693 layer . . . . . . . . . . . . . . . . . . . . . . . . 68 Table 116. M24LRxx_Read_Single_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Table 117. M24LRxx_Write_Single_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Table 118. M24LRxx_Read_Multiple_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Table 119. M24LRxx_Get_System_Info function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Table 120. M24LRxx_Get_Multiple_Blocks_Security_Status function description. . . . . . . . . . . . . . . . 72 Table 121. M24LRxx_Write_Sector_Password function description . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Table 122. M24LRxx_Lock_Sector_Password function description . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Table 123. M24LRxx_Present_Sector_Password function description . . . . . . . . . . . . . . . . . . . . . . . . 73 Table 124. M24LRxx_Fast_Read_Single_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . 74 Table 125. M24LRxx_Fast_Read_Multiple_Block function description . . . . . . . . . . . . . . . . . . . . . . . . 74 Table 126. M24LRxx_Inventory_Initiated function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Table 127. M24LRxx_Fast_Inventory_Initiated function description . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Table 128. M24LRxx_Get_System_Info function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Table 129. M24LRxx_Get_Multiple_Blocks_Security_Status function description. . . . . . . . . . . . . . . . 76 Table 130. M24LRxx_Write_Sector_Password function description . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Table 131. M24LRxx_Lock_Sector_Password function description . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Table 132. M24LRxx_Present_Sector_Password function description . . . . . . . . . . . . . . . . . . . . . . . . 78 Table 133. M24LRxx_Fast_Read_Single_Block function description . . . . . . . . . . . . . . . . . . . . . . . . . 78 Table 134. M24LRxx_Fast_Read_Multiple_Block function description . . . . . . . . . . . . . . . . . . . . . . . . 79 Table 135. M24LRxx_Inventory_Initiated function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Table 136. M24LRxx_Fast_Inventory_Initiated function description . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Table 137. M24LRxx_Initiate function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Table 138. M24LRxx_Fast_Initiate function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Table 139. M24LRxx_ReadCfg function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Table 140. M24LRxx_Write_EH_Cfg function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Table 141. M24LRxx_SetRst_EH_en function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Table 142. M24LRxx_Check_EH_En function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Table 143. M24LRxx_Get_Energy_Harvesting_Range function description . . . . . . . . . . . . . . . . . . . . 84 Table 144. M24LRxx_Get_RF_BUSY_WIP function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Table 145. M24LRxx_Get_EH_mode_Configuration_Byte function description . . . . . . . . . . . . . . . . . 85 Table 146. M24LRxx_Get_EH_mode_Control_Register function description . . . . . . . . . . . . . . . . . . . 85 Table 147. Test config procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Table 148. Low power modes descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Table 149. Functionalities description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Table 150. Communication with CR95HF I/Os . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Table 151. Board STM8L-1528Eval Specific I/Os . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Table 152. Board STM8L-Discovery Board Specific I/Os . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Table 153. Switching procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Table 154. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Doc ID 022255 Rev 2 |
7/105 |
List of figures |
AN3985 |
|
|
List of figures
Figure 1. Typical application block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 2. Interaction between typical user application and CR95HF library layers . . . . . . . . . . . . . . 12 Figure 3. Function flowchart example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Figure 4. Application example main functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Figure 5. Test config procedure flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Figure 6. Joystick utilization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Figure 7. Wait for interrupt mode schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Figure 8. Wait for interrupt mode flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Figure 9. Halt mode schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Figure 10. Halt mode flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Figure 11. Halt CR95HF Timer mode schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Figure 12. Halt CR95HF Timer mode flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Figure 13. Communication test flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Figure 14. Project tree structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Figure 15. Debug Instruments Settings dialog box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Figure 16. STM8L1528-EVAL hardware block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Figure 17. PLUG-CR95HF-B Board I/Os . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
8/105 |
Doc ID 022255 Rev 2 |
AN3985 |
Acronyms and notational conventions |
|
|
2.1List of terms
Table 1. |
List of terms |
|
Acronyms |
Definitions |
|
|
|
|
AFI |
|
Application Family Identifier |
|
|
|
CRC |
|
Cyclic Redundancy Check |
|
|
|
CPU |
|
Central Processing Unit |
|
|
|
DAC |
|
Digital to Analog Converter |
|
|
|
DSFID |
|
Data Storage Format IDentifier |
|
|
|
EEPROM |
|
Electrically Erasable Programmable Read-Only Memory |
|
|
|
EOF |
|
End Of Frame |
|
|
|
HFO |
|
High Frequency Oscillator |
|
|
|
IC |
|
Integrated Circuit |
|
|
|
IEC |
|
International Electrotechnical Commission |
|
|
|
ISO |
|
International Organization for Standardization |
|
|
|
FIFO |
|
First In First Out |
|
|
|
LRI |
|
Long Range Interface |
|
|
|
LSB |
|
Least Significant Bit |
|
|
|
M24LR64-R |
|
Dual interface EEPROM (I2C & RF) with 64-kbit memory size |
|
|
|
M24LR16-E |
|
Dual interface EEPROM (I2C & RF) with 16-kbit memory size and energy |
|
harvesting functionality |
|
|
|
|
|
|
|
MCU |
|
Microcontroller Unit |
|
|
|
MSB |
|
Most Significant Bit |
|
|
|
NFC |
|
Near Field Communication |
|
|
|
POR |
|
Power On Reset |
|
|
|
RTC |
|
Real Time Clock |
|
|
|
RF |
|
Radio Frequency |
|
|
|
RFU |
|
Reserved for Future Use |
|
|
|
RFID |
|
Radio Frequency Identification |
|
|
|
STVD |
|
ST Visual Develop |
|
|
|
UID |
|
Unique Identifier |
|
|
|
Write_DO_Cfg |
Write Digital Output Configuration (M24LRxx-E command) |
|
|
|
|
Write_EH_Cfg |
Write Energy Harvesting Configuration (M24LRxx-E command) |
|
|
|
|
XOR |
|
eXclusive OR |
|
|
|
Doc ID 022255 Rev 2 |
9/105 |
Acronyms and notational conventions |
AN3985 |
|
|
The following conventions and notations apply in this document unless otherwise stated.
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
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
Decimal numbers are represented as is, without any trailing character.
For example: 245
10/105 |
Doc ID 022255 Rev 2 |
AN3985 |
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
|
|
|
|
|
|
|
|
Contactless tag |
|
|
|
|
|
|
|
|
|
ISO15693 RF |
|
CR95HF |
|
|
|
|
|
|
|
|
|
|
|
|
Memory products |
|
|||||
library |
|
|
|
|
|
|
|
|
|
|
|
|
|
CR95HF |
RF communication |
|
|
|
|
MCU |
|
|
|
|
|
||||
|
|
|
Dual IC M24LR* |
|
|||||
|
|
|
|
|
|||||
|
|
|
|||||||
|
|
|
|
|
|
|
|
products |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MS19958V1 |
For more details concerning the CR95HF, please refer to CR95HF datasheet.
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
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 2 |
11/105 |
Overview |
AN3985 |
|
|
Figure 2. Interaction between typical user application and CR95HF library layers
User functions (user application specific)
Product layer (embeds commands defined in the product datasheet)
M24LR* layer |
|
LRI*k layer |
|
|
|
Protocol layer (embeds commands defined in ISO specification)
ISO15693 library layer
CR95HF library layer
(embeds the commands defined in CR95HF datasheet)
CR95HF library
Standard peripheral driver (MCU specific layer)
MS19959V1
The CR95HF library functions use the following ANSI C compliant types defined in the stm8l15x.h file.
Signed integer types
typedef |
signed char |
int8_t; |
typedef |
signed short |
int16_t; |
typedef |
signed long |
int32_t; |
typedef |
int32_t |
s32; |
typedef |
int16_t |
s16; |
typedef |
int8_t |
s8; |
Unsigned integer types
typedef |
unsigned char |
uint8_t; |
typedef |
unsigned short |
uint16_t; |
typedef |
unsigned long |
uint32_t; |
typedef |
uint32_t |
u32; |
typedef |
uint16_t |
u16; |
typedef |
uint8_t |
u8; |
typedef |
unsigned char |
uint8_t; |
typedef |
signed char |
int8_t; |
typedef |
const uint8_t |
uc8; |
typedef |
signed short int |
int16_t; |
12/105 |
Doc ID 022255 Rev 2 |
AN3985 |
CR95HF low level layer |
|
|
This layer is composed of:
●the lib_CR95HF.c source file
●the lib_CR95HF.h include file
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.
A command from MCU to CR95HF is composed of three fields:
●command code
●length
●data
The dedicated structure is CR95HF_CommandSending.
Table 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 |
|
|
|
Field |
Length |
Dedicated structure |
|
|
|
|
Command code |
1 byte |
cmd_code |
|
|
|
|
|
Length |
|
1 byte |
data_lenght |
|
|
|
|
Data |
|
Up to 255 bytes |
data |
|
|
|
|
The structure definition of a command to CR95HF is: typedef struct
{
u8 cmd_code;
u8 data_length;
u8 data[MAX_DATASENT_LENGTH]; }CR95HF_CommandSending;
Doc ID 022255 Rev 2 |
13/105 |
CR95HF low level layer |
AN3985 |
|
|
A response from CR95HF to MCU is composed of three fields:
●response code
●length
●data
The dedicated structure is CR95HF_ResponseReceiving.
Table 3 lists the fields of a generic response from CR95HF, the number of bytes and the name of the dedicated structure member.
Table 3. |
Response field formats |
|
|
|
|
Field |
|
Length |
Dedicated structure |
|
|
|
|
|
RF protocol |
|
|
1 byte |
resp_code |
|
|
|
|
|
Length |
|
|
1 byte |
data_lenght |
|
|
|
|
|
Data |
|
|
Up to 255 bytes |
data |
|
|
|
|
|
The structure definition of a response from CR95HF is:
typedef struct
{
u8 resp_code;
u8 data_length;
u8 data[MAX_DATARECEIVED_LENGTH]; }CR95HF_CommandSending;
The CR95HF can use different RF protocols:
●ISO/IEC 14443 type A or type B
●ISO/IEC 15693
●ISO/IEC 18092
Each protocol has its own parameters.
The Protocol_Config structure displays the RF protocol parameters.
Table 4 lists the protocol parameters.
Table 4. |
Protocol parameter formats |
|
|
|
Field |
Length |
Dedicated structure |
|
|
|
|
Response code |
1 byte |
protocol_in_use |
|
|
|
|
|
Length |
|
1 byte |
parameters_lenght |
|
|
|
|
Data |
|
Up to 3 bytes |
parameters |
|
|
|
|
The structure definition of a protocol selection structure is:
typedef struct
{
14/105 |
Doc ID 022255 Rev 2 |
AN3985 |
CR95HF low level layer |
|
|
u8 protocol_in_use;
u8 parameters_lenght;
u8 paramaters[MAX_PARAMAETERS_LENGTH]; }Protocol_Config;
Table 5 lists the available values for protocol_in_use.
|
Table 5. |
Protocol values |
|
|
|
|
|
|
|
RF protocol |
|
Values |
|
|
|
|
|
|
|
|
|
|
|
|
ISO/IEC 15693 |
|
1 |
|
|
||
|
|
|
|
|
|
|
|
|
ISO/IEC 14443 type A |
|
2 |
|
|
||
|
|
|
|
|
|
|
|
|
ISO/IEC 14443 type B |
|
3 |
|
|
||
|
|
|
|
|
|
|
|
|
ISO/IEC 18092 |
|
4 |
|
|
||
|
|
|
|
|
|
||
Note: |
These values are defined in CR95HF_command.h. |
|
|||||
4.2.4 |
Idle structure |
|
|
|
|
||
|
The idle structure contains the last parameters of the idle command sent to CR95HF. |
||||||
|
Table 6 lists the parameters contained in an idle structure. |
|
|||||
|
Table 6. |
Idle structure parameters |
|
||||
|
|
|
|
|
|
||
|
|
Parameter |
|
Length |
Dedicated structure |
||
|
|
|
|
|
|||
|
Wake-up flags |
|
1 byte |
wuFlags |
|||
|
|
|
|
|
|||
|
Low threshold for tag detector mode |
|
1 byte |
dacDataL |
|||
|
|
|
|
|
|||
|
High threshold for tag detector mode |
|
1 byte |
dacDataH |
|||
|
|
|
|
|
|||
|
Cause of last wake-up exit |
|
1 byte |
last_reason_of_wakeup |
|||
|
|
|
|
||||
|
The structure definition of an idle structure is: |
|
|||||
|
typedef struct |
|
|
|
|
||
|
{ |
|
|
|
|
|
|
|
u8 wuFlags; |
|
|
|
|
||
|
u8 dacDataL; |
|
|
|
|
||
|
u8 dacDataH; |
|
|
|
|
||
|
u8 last_reason_of_wakeup; |
|
|
|
|
||
|
}CR95HF_Idle_Config; |
|
|
|
|
||
Note: |
This structure is defined in CR95HF_structure.h file. |
|
|||||
|
For more details about idle command, refer to CR95HF datasheet. |
Doc ID 022255 Rev 2 |
15/105 |
CR95HF low level layer |
AN3985 |
|
|
The tables below list the functions available in a CR95HF layer.
Table 7. |
CR95HF layer functions based on CR95HF commands |
|
|
Function name |
Description |
|
|
|
CR95HF_IDN |
Sends an Idn command. |
|
|
|
|
CR95HF_Echo |
Sends an Echo command. |
|
|
|
|
CR95HF_ProtocolSelect |
Sends a ProtocolSelect command. |
|
|
|
|
CR95HF_SendRecv |
Sends a SendRecv command. |
|
|
|
|
CR95HF_Idle |
Sends an Idle command. |
|
|
|
|
CR95HF_Rd_Wake_up_Reg |
Reads the wake-up Register command. |
|
|
|
|
CR95HF_Rd_Analog_Register_Config_B |
Reads the analog register configuration B command. |
|
|
|
|
CR95HF_BaudRate |
Sends a BaudRate command. |
|
|
|
|
Table 8. |
CR95HF layer additional functions |
|
|
Function name |
Description |
|
|
|
CR95HF_SendEOF |
Sends an EOF pulse. |
|
|
|
|
CR95HF_FieldOff |
Switches off the RF field. |
|
|
|
|
Table 9. |
Low Power mode functions |
|
|
|
Function name |
Description |
|
|
|
||
CR95HF_Hibernate |
Sends an hibernate command to CR95HF. |
||
|
|
||
CR95HF_Sleep |
Sends a Sleep command to CR95HF. |
||
|
|
|
|
CR95HF_IdlebyTimerfunction |
Sends a Idle command to CR95HF. The wake-up |
||
source is its internal timer. |
|||
|
|
||
|
|
||
CR95HF_TagDetecting |
Sends a Tag detecting command to CR95HF. |
||
|
|
|
Table 10. CR95HF layer IS functions
Function name |
Description |
|||
|
|
|||
CR95HF_IsReaderResultOK |
Checks if the returned code is successful. |
|||
|
|
|
|
|
|
Checks if a pulse on |
|
pad is a wake-up |
|
CR95HF_Is_IRQ_in_Interrupt_Wake_up |
IRQ_IN |
|||
_Condition |
condition. |
|||
|
|
|||
CR95HF_Is_NSS_Interrupt_Wake_up_ |
Checks if a pulse on NSS pad is a wake-up |
|||
Condition |
condition. |
|||
|
|
|||
CR95HF_Is_Tag_Detected_Wake_up_ |
Checks if a tag detector state is a wake-up |
|||
Condition |
condition. |
|||
|
|
|
|
|
CR95HF_Is_Timeout_Wake_up_ |
Checks if an internal timer is a wake-up condition. |
|||
Condition |
||||
|
|
|
||
|
|
|
|
16/105 |
Doc ID 022255 Rev 2 |
AN3985 |
CR95HF low level layer |
|
|
|
|
|
Table 11. CR95HF layer advanced functions |
|
|
|
|
|
Function name |
Description |
|
|
|
|
CR95HF_Modify_Baud_Rate |
Changes the UART baud rate of MCU and |
|
|
CR95HF. |
|
|
|
|
CR95HF_Idle_Detector_Calibration |
Carries out a calibration for tag detector mode. |
|
|
|
|
CR95HF_Wait_Wake_up_From_Idle |
Waits for CR95HF to exit the idle state and retrieve |
|
|
what caused the wake-up. |
|
|
|
|
CR95HF_Wake_up_CR95HF |
Wakes up CR95HF when exists idle mode. |
|
|
|
CR95HF_IDN function
This function sends an IDN command to the CR95HF device. It returns its version number.
Table 12. CR95HF_IDN function description
Prototype |
u8 CR95HF_IDN (CR95HF_ResponseReceiving* Response); |
|
|
|
|
Input parameter |
None |
|
|
|
|
Output parameter |
Response: 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.
Table 13. CR95HF_Echo function description
Prototype |
u8 CR95HF_Echo (void); |
|
|
|
|
Input parameter |
None |
|
|
|
|
Output parameter |
None |
|
|
|
|
Return parameter |
CR95HF_SUCCESS_CODE: The command is successful. |
|
CR95HF_ERROR_CODE: The command failed. |
||
|
||
|
|
Doc ID 022255 Rev 2 |
17/105 |
CR95HF low level layer |
AN3985 |
|
|
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
|
u8 CR95HF_ProtocolSelect (const u8 Protocol, const u8 |
|
Prototype |
ParametersLength,const u8* Parameters, |
|
|
CR95HF_Protocol_Config* Protocol_Settings); |
|
|
|
|
|
Protocol: RF protocol selected |
|
Input parameter(1) |
ParametersLength: length of any parameters attached |
|
|
Parameters: any parameters to be attached for different protocols |
|
|
|
|
Output parameter |
Protocol_Settings: structure at the end of the command containing the |
|
last protocol selected and its parameters |
||
|
||
|
|
|
|
CR95HF_SUCCESS_CODE: The command is successful. |
|
|
CR95HF_ERROR_INVALID_PROTOCOL: The protocol selected is invalid. |
|
Return parameter |
CR95HF_ERROR_INVALID_CMD_LENGTH: The command length is |
|
|
invalid. |
|
|
CR95HF_ERROR_CODE: The command failed. |
|
|
|
1.The input parameter settings depend on the selected protocol. This application note applies to ISO/IEC 15693 products.
Table 15. Input parameters settings for ISO/IEC 15693 protocol
Parameter name |
Byte |
Bit |
Value |
Example |
|
|
|
|
|
Command code |
0 |
|
0x02 |
02020126 |
|
|
|
|
|
Length |
1 |
|
0x02 |
|
|
|
|
|
|
Protocol |
2 |
|
0x01: ISO/IEC 15693 protocol |
|
|
|
|
|
|
|
|
7:6 |
RFU |
|
|
|
|
|
|
|
|
|
0b00: 26 kbps |
|
|
|
|
|
|
|
|
5:4 |
0b01: 52 kbps |
|
|
|
|
|
|
|
|
0b10: 6 kbps |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0b11: RFU |
|
|
|
|
|
|
|
|
3 |
0b0: ensure a 312 µs delay |
|
Parameter |
3 |
|
|
|
0b1: wait for SOF |
|
|||
|
|
|||
|
|
|
|
|
|
|
2 |
0b0: 100% modulation |
|
|
|
|
|
|
|
|
0b1: 10% modulation |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
0b0: single subcarrier |
|
|
|
|
|
|
|
|
0b1: single subcarrier |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
0b0: don’t append CRC |
|
|
|
|
|
|
|
|
0b1: append CRC (1) |
|
|
|
|
|
|
1. It is recommended to set the append CRC bit (see Chapter 5.3.4: CRC16 management)
For more detail concerning this parameter, please refer to the CR95HF datasheet.
18/105 |
Doc ID 022255 Rev 2 |
AN3985 |
CR95HF 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 |
u8 CR95HF_SendRecv(CR95HF_ResponseReceiving* |
|
Response,const CR95HF_CommandSending* Command); |
||
|
||
|
|
|
Input parameter |
Command: the command structure to send to a contactless tag |
|
|
|
|
Output parameter |
Response: pointer on the response structure |
|
|
|
|
|
CR95HF_SUCCESS_CODE: The command is successful. |
|
Return parameter |
CR95HF_ERROR_CODE: The command failed. Response contains |
|
|
the right error code. |
|
|
|
The Parameters of input parameter depend on the selected protocol. Table 15 gives ISO/IEC 15693 protocol parameters.
In case of a correct response, the SendRecv response sent to MCU is as follows:
Table 17. SendRecv correct response
Parameter name |
Byte |
Bit |
Value |
Example |
|
|
|
|
|
|
|
Result Code |
0 |
7:0 |
0x80 |
0x800D0000FA20563C172202E |
|
|
|
|
|
0746800 |
|
Length |
1 |
7:0 |
0xXX |
||
with: |
|||||
|
|
|
|
||
Data |
2:X |
7:0 |
0xXX |
||
80: success code |
|||||
|
|
|
|
||
CRC |
X+2:X+3 |
7:0 |
0xXX |
0D: number of bytes |
|
|
|
|
|
0000FA20563C172202E0: |
|
|
|
7:2 |
RFU |
||
|
|
contactless tag data |
|||
|
|
|
|
||
Control byte |
X+4 |
1 |
CRC error if set |
||
7468: CRC |
|||||
|
|
|
|
||
|
|
0 |
Collision detected if set |
00: control byte |
|
|
|
|
|
|
In case of an error response, the SendRecv response sent to MCU is as follows:
Table 18. SendRecv error response
Parameter name |
Byte |
Bit |
Value |
Example |
|
|
|
|
|
Result Code |
0 |
7:0 |
0x8X |
0x 87 00: no tag in |
|
|
|
|
|
Length |
1 |
7:0 |
0x00 |
the field |
|
||||
|
|
|
|
|
For more details, please refer to the CR95HF datasheet.
Doc ID 022255 Rev 2 |
19/105 |
CR95HF low level layer |
AN3985 |
|
|
CR95HF_Idle function
This function sends an Idle command to the CR95HF to switch the CR95HF device into low consumption mode.
Table 19. CR95HF_Idle function description
|
|
u8 CR95HF_Idle (const |
u8 WakeUpFlags,const u8 |
||
|
|
EnterCtrlL,const |
u8 EnterCtrlH, |
const u8 |
|
|
|
WUCtrlL,const u8 WUCtrlH,const |
u8 |
||
|
Prototype |
LeaveCtrlL,const |
u8 |
LeaveCtrlH ,const u8 |
|
|
WUPeriod,const |
u8 OscStart,const |
u8 |
||
|
|
||||
|
|
DacStart,const |
u8 DacDataL,const |
u8 |
|
|
|
DacDataH,const |
u8 SwingsCnt,const u8 MaxSleep, |
||
|
|
CR95HF_Idle_Config* Idle_Config); |
|
||
|
|
|
|
||
|
|
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 |
|||
|
Input parameter |
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 parameter |
Idle_Config: pointer on the Idle structure |
|
||
|
|
|
|||
|
Return parameter |
CR95HF_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
Prototype |
u8 CR95HF_Rd_Wake_up_Reg(CR95HF_ResponseReceiving* |
|
Response,CR95HF_Idle_Config* Idle_Config); |
||
|
||
|
|
|
Input parameter |
None |
|
|
|
|
Output parameter |
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, |
|
Return parameter |
invalid length. |
|
|
CR95HF_ERROR_CODE: Command failed, response contains the |
|
|
error code. |
|
|
|
20/105 |
Doc ID 022255 Rev 2 |
AN3985 CR95HF 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 |
|
|
|
|
|
Prototype |
u8 CR95HF_Rd_Wake_up_Reg(CR95HF_ResponseReceiving* |
|
Response,CR95HF_Idle_Config* Idle_Config); |
|
|
|
|
|
|
|
|
Input parameter |
None |
|
|
|
|
Output parameter |
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, |
|
Return parameter |
invalid length |
|
|
CR95HF_ERROR_CODE: Unsuccessful command, Response |
|
|
contains the error code. |
|
|
|
CR95HF_Baud_Rate function
This function sends a BaudRate command to the CR95HF. It allows to configure the UART baudrate.
Table 22. CR95HF_Baud_Rate function description
Prototype |
u8 CR95HF_Baud_Rate(u8 New_Baud_Rate); |
|
|
Input parameter |
New_Baud_Rate: new baud rate = 13.56/(2*BaudRate+2) Mbps |
|
|
Output parameter |
pResponse: 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 2 |
21/105 |
CR95HF low level layer |
AN3985 |
|
|
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.
Table 23. CR95HF_SendEOF function description
Prototype |
u8 CR95HF_SendEOF(CR95HF_ResponseReceiving* Response); |
|
|
|
|
Input parameter |
None |
|
|
|
|
Output parameter |
Response: pointer on the structure which will contain the Tag answer |
|
|
|
|
Return parameter |
CR95HF_SUCCESS_CODE: The command is successful. |
|
CR95HF_ERROR_CODE: The command failed. |
||
|
||
|
|
CR95HF_FieldOff function
This function switches off the RF Field using the protocol select command.
Table 24. CR95HF_FieldOff function description
Prototype
u8 CR95HF_FieldOff(CR95HF_Protocol_Config*
Protocol_Settings);
Input parameter Protocol_Settings: structure to update
Output parameter None
CR95HF_SUCCESS_CODE: The field was successfully turned off
CR95HF_ERROR_INVALID_PROTOCOL: The selected protocol is wrong.
Return parameter
CR95HF_ERROR_INVALID_CMD_LENGTH: The command length is invalid.
CR95HF_ERROR_CODE: The command failed
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 IRQ_IN pin can wake-up the CR95HF.
Table 25. CR95HF_Hibernate function description
Prototype |
u8 CR95HF_Hibernate (CR95HF_Idle_Config* Idle_Config); |
|
|
|
|
Input parameter |
None |
|
|
|
|
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. |
|
|
|
22/105 |
Doc ID 022255 Rev 2 |
AN3985 |
CR95HF low level layer |
|
|
CR95HF_Sleep function
This function sends a Sleep command to CR95HF and turns the sleep state on.
Table 26. CR95HF_Sleep function description
Prototype |
u8 CR95HF_Sleep (CR95HF_Idle_Config* Idle_Config); |
|
|
|
|
Input parameter |
WakeUpSource: the source of wake-up for CR95HF(1) |
|
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 wakeup 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.
Table 27. CR95HF_TagDetecting function description
u8 CR95HF_TagDetecting (const u8 WakeUpSource, const u8 Prototype WUperiod,const u8 DACdataL, const u8 DACdataH,
CR95HF_Idle_Config* Idle_Config);
WakeUpSource: other source of wake-up for CR95HF than tag detecting (1)
LFOfreq: LFO frequency (2bits) (00 : 32 kHz 01 : 16 kHz 10 : 8 kHz 11 : 4 kHz)
Input parameter WUperiod: tinactive = time between two bursts = ( Wuperiod +1 )* 256 / LFOfreq DACdataL: low threshold of tag detecting
DACdataH: high threshold of tag detecting
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_SPINSS value. For a wake-up by a pulse on IRQ_IN pad, use CR95HF_IDLE_WAKEUP_IRQ_in value.
Doc ID 022255 Rev 2 |
23/105 |
CR95HF low level layer |
AN3985 |
|
|
CR95HF_IdlebyTimer function
This function sends an Idle command to CR95HF. The wake-up source is its internal timer.
Table 28. CR95HF_IdlebyTimer function description
u8 CR95HF_IdlebyTimer (const u8 WakeUpSource,const u8 Prototype LFOfreq, const u8 WUperiod,const u8 MaxSleep,
CR95HF_Idle_Config* Idle_Config);
WakeUpSource: other source of wake-up for CR95HF than tag detecting (1)
LFOfreq: LFO frequency (2bits) (00: 32 kHz, 01: 16 kHz, 10: 8 kHz, 11: 4 kHz)
Input parameter
WUperiod: timeout = ( Wuperiod +1 )* MaxSleep * 256 / LFOfreq
MaxSleep: timeout = ( Wuperiod +1 )* MaxSleep * 256 / LFOfreq
Output parameter
Idle_Config: pointer on the structure contains the data about some idle parameters to update
Return parameter CR95HF_SUCCESS_CODE: The command is successful.
1.For example, for a wake-up by a pulse on SPI_NSS pad, use CR95HF_IDLE_WAKEUP_SPINSS value. For a wake-up by a pulse on IRQ_IN pad, use CR95HF_IDLE_WAKEUP_IRQ_in value.
These functions check a parameter and return either TRUE_CODE or FALSE_CODE.
CR95HF_IsReaderResultOK function
This function checks if the CR95HF has answered a successful code.
_
Table 29. CR95HF_IsReaderResultOK function description
Prototype
u8 CR95HF_IsReaderResultOK(CR95HF_ResponseReceiving*
Response,const u8 Code_OK);
Input parameter CR95HF_ResponseReceiving* Response,
Output parameter None
TRUE_CODE: CR95HF returned a successful code.
Return parameter
FALSE_CODE: CR95HF did not return a successful code.
Is_IRQ_in_Interupt_Wake_up_Condition function
This function returns whether an interrupt on IRQ_IN pin is a wake-up condition or not.
Table 30. Is_IRQ_in_Interupt_Wake_up_Condition function description
Prototype
u8 CR95HF_Is_IRQ_in_Interrupt_Wake_up_Condition(u8
WUFlags);
Input parameter WUFlags: the byte containing the expected data
Output parameter None
TRUE_CODE: An interrupt on IRQ_IN pin is a wake-up condition.
Return parameter
FALSE_CODE: An interrupt on IRQ_IN pin is not a wake-up condition.
24/105 |
Doc ID 022255 Rev 2 |
AN3985 |
CR95HF 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
Prototype |
u8 CR95HF_Is_NSS_Interrupt_Wake_up_Condition(u8 WUFlags); |
|||||
|
|
|||||
Input parameter |
WUFlags: the byte containing the expected data |
|||||
|
|
|||||
Output parameter |
None |
|||||
|
|
|
|
|
||
|
TRUE_CODE: An interrupt on |
|
|
is a wake-up condition. |
||
Return parameter |
IRQ_IN |
|||||
|
|
|
|
|
||
FALSE_CODE: An interrupt on IRQ_IN is not 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
Prototype |
u8 CR95HF_Is_Tag_Detected_Wake_up_Condition_(u8 WUFlags); |
|
|
|
|
Input parameter |
WUFlags: 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
Prototype |
u8 CR95HF_Is_Timeout_Wake_up_Condition(u8 WUFlags); |
|||||
|
|
|||||
Input parameter |
WUFlags: the byte containing the expected data |
|||||
|
|
|||||
Output parameter |
None |
|||||
|
|
|
|
|
||
|
TRUE_CODE: An interrupt on |
|
|
is a wake-up condition. |
||
Return parameter |
IRQ_IN |
|||||
|
|
|
|
|
||
FALSE_CODE: An interrupt on IRQ_IN is not a wake-up condition. |
||||||
|
||||||
|
|
|
|
|
|
Doc ID 022255 Rev 2 |
25/105 |
CR95HF low level layer |
AN3985 |
|
|
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
Prototype u8 CR95HF_Modify_Baud_Rate(const u8 New_Baud_Rate);
Input parameter u8 New_Baud_Rate
Output parameter None
CR95HF_SUCCESS_CODE: The command is successful.
CR95HF_BAUd_RATE_FAILED_PREVIOUS_VALUE_ON: The command failed but the transmission with the previous baud rate is kept.
Return parameter CR95HF_BAUD_RATE_FAILED_DEFAULT_VALUE_ON: The command failed and did not manage to keep the previous baud rate. Default baud rate is on.
CR95HF_ERROR_CODE: The command failed. UART communication may be lost.
CR95HF_Idle_Detector_Calibration function
The purpose of this function is to perform the detector calibration according to the AN3433 Application Note.
Table 35. CR95HF_Idle_Detector_Calibration function description
u8 CR95HF_Idle_Detector_Calibration (
Prototype CR95HF_Protocol_Config* Protocol_Settings ,
CR95HF_Idle_Config* Idle_Config);
Input parameter
Protocol_Settings: pointer on the structure to update the protocol select. (Turn
RF field off)
Output parameter
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.
Return parameter
CR95HF_ERROR_CODE: The command failed.
26/105 |
Doc ID 022255 Rev 2 |
AN3985 |
CR95HF 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
u8 CR95HF_Wait_Wake_up_from_Idle(CR95HF_ResponseReceiving*
Prototype CR95HF_Response_Idle,CR95HF_Idle_Config* Idle_Config, u8
Number_of_DELAY_BEFORE_TIMEOUT_250MS);
Idle_Config: pointer on the structure to update with the new last reason of wake-up Input parameter Number_of_DELAY_BEFORE_TIMEOUT_250MS: number of periods of
250ms duration to wait before aborting the procedure
Output parameter
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 Return parameter 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
Prototype |
u8 CR95HF_Wake_up_CR95HF(CR95HF_Idle_Config* Idle_Config); |
|
|
Input parameter |
Idle_Config: contains the wake-up condition |
|
|
Output parameter |
None |
|
|
|
CR95HF_SUCCESS_CODE: the CR95HF woke up, communication is possible. |
Return parameter |
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 2 |
27/105 |
CR95HF low level layer |
AN3985 |
|
|
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
Start
Echo |
|
Echo |
No |
response? |
|
Yes |
|
Select |
|
protocol |
|
Selected? |
Error code |
|
|
Yes |
|
SendRecv |
|
Another |
Yes |
protocol? |
|
No |
AI18875 |
|
28/105 |
Doc ID 022255 Rev 2 |
AN3985 |
ISO/IEC 15693 layer |
|
|
This layer is composed of:
●the source file: iso15693_command.c
●the included file: iso15693_command.h
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.
This layer uses a structure to store the information of an ISO/IEC contactless tag.
The ISO15693_tag structure contains the different fields associated to an ISO/IEC15693 contactless tag.
Table 38. ISO15693_tag structure description
Name |
Number of bytes |
Comment |
|
|
|
|
|
command_ok |
1 |
The command and the response |
|
are ok, the structure is ok. |
|||
|
|
||
|
|
|
|
error_code |
1 |
Error code of a contactless tag or |
|
CRC error |
|||
|
|
||
|
|
|
|
response_flags |
1 |
Response flag provided by the tag |
|
|
|
|
|
dataField |
ISO15693_DATA_RECEIVED_MAX |
Whole data transmitted by the tag |
|
_SIZE |
and CR95HF control byte |
||
|
|||
|
|
|
|
receivedDataLength |
1 |
Length of data transmitted by the |
|
Tag |
|||
|
|
||
|
|
|
|
UID_Tag |
ISO15693_UID_SIZE |
UID of the contactless tag |
|
|
|
|
|
AFI_Tag |
1 |
AFI of the contactless tag |
|
|
|
|
|
DSFID_Tag |
1 |
DSFID of the contactless tag |
|
|
|
|
|
|
|
ICRef of the Tag (only for those |
|
ICRef |
1 |
manufactured by |
|
|
|
STMicroelectronics). |
|
|
|
|
|
memSize |
ISO15693_MEMSIZE_MAX_WORD_ |
Memfield of getsystem info |
|
BYTE_SIZE |
command |
||
|
|||
|
|
|
Doc ID 022255 Rev 2 |
29/105 |
ISO/IEC 15693 layer |
AN3985 |
|
|
This structure is defined in ISO15693_structure.h.
typedef struct
{
u8 command_ok;
u8 error_code;
u8 response_flags;
u8 dataField[ISO15693_DATA_RECEIVED_MAX_SIZE]; u8 receivedDataLength;
u8 UID_Tag[ISO15693_UID_SIZE];
u8 AFI_Tag;
u8 DSFID_Tag;
u8 ICRef;
u8 memSize[ISO15693_MEMSIZE_MAX_WORD_BYTE_SIZE]; }ISO15693_Tag;
The commands defined by ISO/IEC 15693 specification have the following structure:
SOF |
Request flag |
Command code |
Data |
CRC |
EOF |
|
|
|
|
|
|
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.1SOF and EOF
The SOF and EOF are managed by CR95HF device.
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/105 |
Doc ID 022255 Rev 2 |