ST AN3954 Application Note

ST AN3954 Application Note

Developing your own visual basic or c/c++ application on a demonstration board

Advertisement

Quick Links

AN3954
Application note
Developing your own Visual Basic or C/C++ application
on a CR95HF demonstration board
Introduction
This application note explains how to develop an application using either Visual Basic or
C/C++ language to drive a CR95HF demonstration board from a host computer.
CR95HF demonstration board is a kit that allows the user to evaluate the performance of
STMicroelectronics CR95HF, a 13.56 MHz multiprotocol contactless transceiver. It includes
a ready-to-use board to interface with the CR95HF host PC demonstration software through
an USB interface. The CR95HF demonstration board is included in the M24LR-
DISCOVERY kit (see
Figure
1).
The board is powered through the USB port, and no external power supply is required. It is
made up of a CR95HF, a 48 mm x 34 mm, 13.56 MHz inductive etched antenna and its
associated tuning components. The CR95HF communicates with the STM32F103CB 32-bit
core microcontroller via the SPI bus.
A dynamic link library (DLL) file is used by the host computer to manage several functions
and to communicate with both the STM32 MCU and the CR95HF
Source code examples described in this application note and additional demonstrations can
be found in the package STSW-95HF002, which can be downloaded from www.st.com.
Some basic examples are available in C/C++, additional examples are available in a Visual
Basic 6 project, among them NDEF message management on Type 4A and Type 5,
ST25DV user interface and FTM demonstrations. DLL file is also available in this package.

Figure 1. CR95HF demonstration board embedded in the M24LR-Discovery kit

For more information, refer to the following documents, available on www.st.com:
• M24LR-DISCOVERY databrief
• CR95HF datasheet
• User manual UM1084 "CR95HF development software"
• STSW-95HF002 source code example
January 2017
Doc ID022016 Rev 4
1/47
www.st.com
1

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the AN3954 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for ST AN3954

  • Page 1: Figure 1. Cr95Hf Demonstration Board Embedded In The M24Lr-Discovery Kit

    STM32 MCU and the CR95HF Source code examples described in this application note and additional demonstrations can be found in the package STSW-95HF002, which can be downloaded from www.st.com. Some basic examples are available in C/C++, additional examples are available in a Visual Basic 6 project, among them NDEF message management on Type 4A and Type 5, ST25DV user interface and FTM demonstrations.
  • Page 2: Table Of Contents

    Contents AN3954 Contents Getting started ..........5 Connecting the board to the computer .
  • Page 3 AN3954 List of tables List of tables Table 1. List of error codes ............45 Table 2.
  • Page 4 List of figures AN3954 List of figures Figure 1. CR95HF demonstration board embedded in the M24LR-Discovery kit ....1 Figure 2. Typical application block diagram ..........5 Figure 3.
  • Page 5: Getting Started

    AN3954 Getting started Getting started This application note and the source code example have been written to help users to easily develop their applications. This document note contains function descriptions and some use cases. To improve the use of CR95HF demonstration board and the communication with tags, it is...
  • Page 6: Figure 3. Function Cr95Hfdll_Usbconnect

    Getting started AN3954 communicate with it. The computer first checks if a CR95HF demonstration board is connected to the USB port. If so, it assigns a USB handle to the board (see Figure CR95HFDLL_USBhandlecheck function can be used to verify if the CR95HF demonstration board is connected to the USB port of the computer.
  • Page 7: Figure 5. Driving The Cr95Hf From The Pc

    AN3954 Getting started Other functions can be used to send instructions to the CR95HF IC (see Figure • CR95HFDll_Idn: gets the IDN of the CR95HF IC. • CR95HFDll_Select: configures the required RF protocol for the CR95HF IC (IS0 15693, ISO 14443B …) and starts the RF field on the antenna.
  • Page 8: Description Of Functions

    Description of functions AN3954 Description of functions This section describes the various functions required to evaluate the CR95HF demonstration board. Functions to check DLL installation and USB connection 2.1.1 CR95HFDll_GetDLLrev This function detects if the CR95HF.dll file has been installed in the system folder of the host PC system, reads its header and sends back its revision number.
  • Page 9 AN3954 Description of functions C/C++ language Declaration: __declspec(dllimport) int __stdcall CR95HFDll_GetDLLrev(char* stringreply); Prototype: int iresult; char strAnswer[50]=""; iresult = CR95HFDll_GetDLLrev(strAnswer); Input parameter: None Output parameter: strAnswer: Revision of the DLL installed on your PC system. Answer example: "0.4" Returned value:...
  • Page 10: Cr95Hfdll_Usbconnect

    Description of functions AN3954 2.1.2 CR95HFDLL_USBconnect This function can be used to connect the CR95HF demonstration board to the computer USB port. The computer then assigns a USB handle to the board. Visual Basic language Declaration: Public Declare Function CR95HFDLL_USBconnect Lib"CR95HF.dll"...
  • Page 11: Cr95Hfdll_Usbhandlecheck

    AN3954 Description of functions iresult= CR95HFDLL_USBconnect (); printf("\nCR95HFDll_USBconnect function:\n"); printf("\n --> request : CR95HFDll_USBconnect()"); printf("\n <-- answer : "); if (iresult == 0) printf("CR95HF demonstration board is connected and ready to be used\n\n\r"); else printf("Error : CR95HF demonstration board not ready to be used\n\n\r");...
  • Page 12: Functions To Communicate With The Stm32 Mcu

    Description of functions AN3954 C/C++ language Declaration: __declspec(dllexport) int __stdcall CR95HFDLL_USBhandcheck(void); Prototype: int iresult; iresult= CR95HFDLL_USBhandcheck(); Input parameter: None Output parameter: None Returned value: iresult: 0: the USB handle is valid 5: the USB handle is invalid and the CR95HF demonstration...
  • Page 13 AN3954 Description of functions Visual Basic language Declaration: Public Declare Function CR95HFDll_Echo Lib "CR95HF.dll" (ByVal mystring As String) As Long Prototype: Dim lngStatus as long Dim strAnswer As String * 256 lngStatus = CR95HFDll_Echo(strAnswer) Input parameter: None Output parameter: strAnswer: The CR95HF IC answer to the Echo request is “5500” if there is no error.
  • Page 14: Cr95Hfdll_Getmcurev

    Description of functions AN3954 printf("\n\n\n\n"); iresult= CR95HFDll_Echo (strAnswer); printf("\nEcho using CR95HFDll_Echo function:\n"); printf("\n --> request : CR95HFDll_Echo(strAnswer)"); printf("\n <-- answer : "); if (iresult == 0) printf("%s = Echo command answer\n\n\r", strAnswer); else printf("%s = No answer from MCU\n\n\r", strAnswer);...
  • Page 15 AN3954 Description of functions Else txtMCUrev.Text = "Error = no communication with STM32 MCU" End If End Sub C/C++ language Declaration: __declspec(dllexport) int __stdcall CR95HFDLL_getMCUrev(char* stringreply); Prototype int iresult; char strAnswer[50]=""; iresult = CR95HFDLL_getMCUrev(strAnswer); Input parameter: None Output parameter: strAnswer: Firmware revision of the STM32 MCU on CR95HF demonstration board.
  • Page 16: Cr95Hfdll_Gethardwareversion

    Description of functions AN3954 2.2.3 CR95HFDLL_getHardwareVersion This function sends a USB request to the STM32 MCU on the CR95HF demonstration board that sends back the hardware revision of the board. Note: This function is available since DLL revision 0.9 and higher.
  • Page 17 AN3954 Description of functions Source code example Private Sub cmdGetHardwareRev_Click() Dim strAnswer As String * 256 Dim lngStatus As Long Dim i As Integer txtHardwareRevAscii.Text = "" lngStatus = CR95HFDLL_getHardwareVersion(strAnswer) If (lngStatus = 0) Then If (Mid(strAnswer, 1, 2) = "00") Then txtHardwareRev.Text = strAnswer...
  • Page 18: Cr95Hfdll_Getinterfacepinstate

    Description of functions AN3954 Source code example int Get_Hardware_rev (void) char strAnswer[50]=""; int iresult; char entry3; printf("\n\n\n\n"); iresult = CR95HFDLL_getHardwareVersion(strAnswer); printf("\nGet Hardware revision using CR95HFDLL_getHardwareVersion function:\n"); printf("\n --> request : CR95HFDLL_getHardwarerev(strAnswer)"); printf("\n <-- answer : "); if (iresult == 0) printf("%s = Hardware revision\n\n\r", strAnswer);...
  • Page 19 AN3954 Description of functions 01: Size of answer (in bytes) 0X: Communication mode With X: 0: Communication in UART mode 1: Communication in SPI Mode Returned value: lngStatus: 0: No error 5: CR95HF demonstration board not connected Source code example...
  • Page 20: Functions To Communicate With The Cr95Hf Ic

    Description of functions AN3954 With X: 0: Communication in UART mode 1: Communication in SPI Mode Returned value: iresult: 0: No error 5: CR95HF demonstration board not connected Source code example int Get_Interface_Pin_State (void) int iresult; char strAnswer[50]=""; char entry3;...
  • Page 21 AN3954 Description of functions Note: The IDN command requests brief information about the CR95HF and its firmware version. For more information, refer to the CR95HF transceiver datasheet. Visual Basic language Declaration: Public Declare Function CR95HFDll_Idn Lib "CR95HF.dll" (ByVal mystring As String) As Long...
  • Page 22: Cr95Hfdll_Select

    Description of functions AN3954 Where: 00: Status byte (see annexe 2 for error codes) 0F: Size of answer (in bytes) 4E4643204653324A41535430: ASCII transcription of the CR95HF IDN (in this example, IDN = “NFC FS2JAST0”) 00: protocol status A998: CRC value...
  • Page 23 AN3954 Description of functions Visual Basic language Declaration: Public Declare Function CR95HFDll_Select Lib "CR95HF.dll" (ByVal mycmdstring As String, ByVal mystring As String) As Long Prototype: Dim lngStatus As Long Dim strConfiguration As String Dim strSelectMsg As String * 256 lngStatus = CR95HFDll_Select(strConfiguration,...
  • Page 24 Description of functions AN3954 'Private Sub cmdSelect_ISO15693_protocol_Click() Dim strAnswer As String * 256 Dim lngStatus As Long lngStatus = CR95HFDll_Select("010D", strAnswer) If (lngStatus = 0) Then txtISO15693_SelectAnswer.Text = strAnswer Else txtISO15693_SelectAnswer.Text = " Select protocol ISO15693 not executed" End If...
  • Page 25 AN3954 Description of functions - by optimizing the synchro between digital & analog inputs (sends CR95HFDLL_STCMD with "01 09043A005804") - by modifying modulation & gain (send CR95HFDLL_STCMD with "01 0904680101D1") ISO14443B = "03010180": Where: “03” is the ISO 14443B configuration “010180”...
  • Page 26: Cr95Hfdll_Stcmd

    Description of functions AN3954 printf("\n\n\n\n"); printf("\npress any key to continue"); printf("\n"); scanf("%s", &entry3); return iresult; int Select_ISO14443B (void) char strRequest[50]=""; char strAnswer[50]=""; int iresult; char entry3; printf("\n\n\n\n"); strcpy(strRequest,"03010180"); iresult = CR95HFDll_Select(strRequest ,strAnswer); printf("\nISO14443B protocol select using CR95HFDll_Select function:\n"); printf("\n --> request : CR95HFDll_Select(%s, strAnswer)",strRequest);...
  • Page 27 “08” is the RdReg command “03” is the request length “62” is the wakeup register value “01” is the register size “00” ST reserved Example 2: Select ISO 15693 protocol: “010202010D” Where: “01” is the transparent command header byte “0202010D” is the Protocol Select ISO 15693 frame “02”...
  • Page 28 Description of functions AN3954 Where: “00” is the status byte (see Appendix A for error codes) “00” is the size of the answer Returned value: lngStatus: 0: No error 5: CR95HF demonstration board not connected 2: Empty argument error Source code example...
  • Page 29 “08” is the RdReg command “03” is the request length “62” is the wakeup register value “01” is the register size “00” ST reserved Example 2: Select ISO 15693 protocol: “010202010D” Where: “01” is the transparent command header byte “0202010D” is the Protocol Select ISO 15693 frame “02”...
  • Page 30 Description of functions AN3954 Example 3: Answer to Idle command = “0000” Where: “00” is the status byte (see Appendix A for error codes) “00” is the size of the answer Returned value: iresult: 0: No error 5: CR95HF demonstration board not connected...
  • Page 31: Cr95Hfdll_Fieldoff

    AN3954 Description of functions printf("\nISO15693 protocol select using CR95HFDll_STCmd function:\n"); printf("\n --> request : CR95HFDll_STCmd(%s, strAnswer)",strRequest); printf("\n <-- answer : "); if (iresult == 0) printf("%s = ISO15693 protocol selected successfully\n\n\r", strAnswer); else printf("%s = Protocol not selected\n\n\r", strAnswer); printf("\n\n\n\n");...
  • Page 32 Description of functions AN3954 Note: To perform this RF Field Off command, the STM32 MCU sends a Protocol Select command with parameters ‘0000’. For more information, refer to the CR95HF transceiver datasheet. Visual Basic language Declaration: Public Declare Function CR95HFDll_FieldOff Lib "CR95HF.dll"...
  • Page 33: Cr95Hfdll_Resetspi

    AN3954 Description of functions Returned value: iresult: 0: No error 5: CR95HF demonstration board not connected Source code example int FieldOff (void) int iresult; char strAnswer[50]=""; char entry3; printf("\n\n\n\n"); iresult= CR95HFDll_FieldOff (strAnswer); printf("\nField Off using CR95HFDll_FieldOff function:\n"); printf("\n --> request : CR95HFDll_FieldOff(strAnswer)");...
  • Page 34 Description of functions AN3954 Returned value: lngStatus: 0: No error 5: CR95HF demonstration board not connected Source code example Private Sub cmdResetSPI_Click() Dim strAnswer As String * 256 Dim lngStatus As Long lngStatus = CR95HFDll_ResetSPI(strAnswer) If (lngStatus = 0) Then txtResetSPIAnswer.Text = strAnswer...
  • Page 35: Cr95Hfdll_Sendirqpulse

    AN3954 Description of functions printf("%s = Reset SPI successfully\n\n\r", strAnswer); else printf("%s = No answer from CR95HF demonstration board\n\n\r", strAnswer); printf("\n\n\n\n"); printf("\npress any key to continue"); printf("\n"); scanf("%s", &entry3); return iresult; 2.3.6 CR95HFDll_SendIRQPulse This function must be used when the CR95HF demonstration board is configured in SPI mode (communication between the STM32 MCU and the CR95HF IC).
  • Page 36: Cr95Hfdll_Polling_Reading

    Description of functions AN3954 C/C++ language Declaration: __declspec(dllexport) int __stdcall CR95HFDll_SendIRQPulse(char* stringreply); Prototype: int iresult; char strAnswer[50]=""; iresult = CR95HFDll_SendIRQPulse(strAnswer); Input parameter: None Output parameter: strAnswer: The CR95HF demonstration board sends back an answer if the IRQ Pulse is correctly sent.
  • Page 37 AN3954 Description of functions This function can be used after an IDLE command to make sure that the answer buffer has been emptied and avoid receiving an erroneous answer on the next request. Visual Basic language Declaration: Public Declare Function CR95HFDll_Polling_Reading Lib "CR95HF.dll"...
  • Page 38: Cr95Hfdll_Sendnsspulse

    Description of functions AN3954 function:\n"); printf("\n --> request : CR95HFDll_Polling_Reading(strAnswer)"); printf("\n <-- answer : "); if (iresult == 0) printf("%s = Set Polling Reading successfully\n\n\r", strAnswer); else printf("%s = No answer from CR95HF demonstration board\n\n\r", strAnswer); printf("\n\n\n\n"); printf("\npress any key to continue");...
  • Page 39 AN3954 Description of functions C/C++ language Declaration: __declspec(dllexport) int __stdcall CR95HFDll_SendNSSPulse(char* StringReply); Prototype: int iresult; char strAnswer[50]=""; iresult = CR95HFDll_SendNSSPulse(strAnswer); Input parameter: None Output parameter: strAnswer: The CR95HFdemonstration board sends back an answer if the NSS pulse correctly sent. Example of answer: “0000”...
  • Page 40: Functions To Communicate With An Rf Tag

    Description of functions AN3954 Functions to communicate with an RF tag 2.4.1 CR95HFDll_SendReceive This function sends a USB request to the STM32 MCU that executes a SendRecv command with data to the CR95HF IC. The STM32 MCU sends back the answer of the CR95HF, if possible, or returns an error code ‘1’...
  • Page 41 AN3954 Description of functions “1259” is the original received CRC value “00” is the protocol error status Returned value: lngStatus: 0: No error 5: CR95HF demonstration board not connected 4: Communication error Source code example Private Sub cmdSendReceive_ISO15693_Inventory_Click() Dim strTagResponse...
  • Page 42 Description of functions AN3954 ISO 14443B Initiate example: "0600" Where: “0600” is the ISO 14443B Initiate command. Output parameter: strTagResponse: The Tag answer if the CR95HF has received an answer from the Tag in the field; otherwise, an error code (see...
  • Page 43: Sendreceive Request And Response Maximum Data Size

    AN3954 Description of functions printf("\n\n\n\n"); printf("\npress any key to continue"); printf("\n"); scanf("%s", &entry3); return iresult; int Send_ISO14443B_Initiate (void) char strRequest[50]=""; char strTagAnswer[50]=""; int iresult; char entry3; printf("\n\n\n\n"); strcpy(strRequest,"0600"); iresult=CR95HFDll_SendReceive(strRequest,strTagAnswer); printf("\nISO14443B Initiate using CR95HFDll_SendReceive function:\n"); printf("\n --> request : CR95HFDll_SendReceive(%s, strTagAnswer)",strRequest);...
  • Page 44 Description of functions AN3954 Each request frame coming from the PC software is cut in several 64 bytes parts by the CR95HFDll then sent to the CR95HF demonstration board through the HID USB. The STM32 microcontroller then restores the initial frame and send the request to the CR95HF.
  • Page 45: Appendix A Error Codes

    AN3954 Error codes Appendix A Error codes Table 1. List of error codes Error code Description 0000 Answer OK 8000 Answer OK 8200 Invalid command length 8300 Invalid protocol 8600 Communication error 8700 Frame wait time out OR no tag...
  • Page 46: Revision History

    Revision history AN3954 Revision history Table 2. Document revision history Date Revision Changes 25-Jul-2011 Initial release. Added functions available in new DLL release revision 0.5: Section 2.1.2: CR95HFDLL_USBconnect, Section 2.1.3: CR95HFDLL_USBhandlecheck, Section 2.3.7: CR95HFDll_Polling_Reading, and Section 2.3.8: CR95HFDll_SendNSSPulse. Updated returned value in C/C++ for Section 2.1.1:...
  • Page 47 ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order acknowledgement.

This manual is also suitable for:

Cr95hf

Table of Contents