This application note explains how to develop an application using either Visual Basic or
C/C++ language to drive the DEMO-CR95HF-A demonstration board from a host computer.
The DEMO-CR95HF-A is a demonstration kit which allows to evaluate the performance of
STMicroelectronics CR95HF 13.56 MHz multiprotocol contactless transceiver. It includes a
ready-to-use board to interface with the CR95HF host PC demonstration software through a
USB interface.
The DEMO-CR95HF-A board is powered through the USB port and no external power
supply is required. It is made up of a CR95HF contactless transceiver, a 48 x 34 mm 13.56
MHz inductive etched antenna and its associated tuning components. The CR95HF
communicates with the STM32F103CB 32-bit core MCU via the SPI bus.
A dynamic link library (DLL) file is used by the host computer to manage several functions
and communicate with the STM32 MCU and the CR95HF IC. It is included in the
demo-cr95hf-a_dev_appli.zip version 2 (Visual Basic 6 and C/C++ source code examples)
which can be downloaded from http://www.st.com.
AN3954
Application note
Developing your own Visual Basic or C/C++ application
on a DEMO-CR95HF-A demonstration board
An executable with a simple user interface is also available for both Visual Basic and C/C++
projects.
Figure 1.DEMO-CR95HF-A evaluation board
For more information, refer to the following documents available on www.st.com:
■ CR95HF: 13.56-MHz multi-protocol contactless transceiver IC with SPI and UART serial
access datasheet
■ DEMO-CR95HF-A: Demonstration kit for the CR95HF 13.56 MHz transceiver IC data
The DEMO-CR95HF-A is connected to the host computer through its USB port. No
particular USB driver is needed. The HID USB driver (already included in all Windows
operating systems) is used for communication.
Through the USB port of your computer, you can drive the board, communicate with the
STM32 MCU, manage the CR95HF IC and send requests to a RF tag.
Figure 2.Typical application block diagram
1.2 Using the DLL system file
A DLL file (CR95HF.dll) is provided in order to drive the DEMO-CR95HF-A board from your
computer.
Copy this file to the system folder of your computer (C:/Windows/system32/).
This DLL contains several functions to enable communication with the board.
Using this DLL, the host computer is able to manage several functions and communicate
with the STM32 MCU and the CR95HF IC.
1.2.1 Overview of DLL functions
The CR95HFDll_GetDLLrev function reads the revision number of the DLL file. If the DLL
file is not correctly installed in the system folder of the host computer, this function returns
an error message (see Figure 3).
The CR95HFDLL_USBconnect function is required to connect the DEMO-CR95HF-A board
to the host computer and communicate with it. It is available from DLL revision 0.5 and
upper. The computer first checks if a DEMO-CR95HF-A is connected to the USB port. If so,
it assigns a USB handle to the board (see Figure 3).
The CR95HFDLL_USBhandlecheck function can be used to verify if the DEMO-CR95HF-A
is connected to the USB port of your computer. It is available from DLL revision 0.6 and
upper. This function sends a request to the DEMO-CR95HF-A and waits for an
acknowledge. An error code is sent if the communication with the board has been lost. In
Doc ID 022016 Rev 23/42
Getting startedAN3954
-36
)3/2&
-#5
#2(&
#ONTACTLESS
TAG
#2(&
LIBRARY
2&
$%-/#2(&!
53"
(/34
#/-054%2
53"
REVISION
#2$LLDLL
-36
)3/2&
-#5
#2(&
#ONTACTLESS
TAG
#2(&
LIBRARY
2&
$%-/#2(&!
53"
(/34
#/-054%2
53"
#2$LLDLL
this case, the CR95HFDLL_USBconnect can be used to reconnect the DEMO-CR95HF-A
to the host computer.
Figure 3.Typical application block diagram
A set of functions are available to drive the STM32 MCU (see Figure 4):
●CR95HFDll_Echo: verifies that the DEMO-CR95HF-A board is connected to the USB
port of the computer.
●CR95HFDLL_getMCUrev: reads the firmware revision of the STM32 MCU.
●CR95HFDLL_getInterfacePinState: verifies the communication path between the
STM32 MCU and the CR95HF IC (either SPI or UART).
Figure 4.Typical application block diagram
Other functions can be used to send instructions to the CR95HF IC (see Figure 5):
●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.
●CR95HFDll_STCmd: sends commands to the CR95HF IC (refer to datasheet for a list
of possible commands).
●CR95HFDll_FieldOff: stops the RF field of the CR95HF IC.
●CR95HFDll_ResetSPI: resets the SPI interface of the CR95HF IC.
●CR95HFDll_SendIRQPulse: sends an interruption pulse on the IRQ pin of the CR95HF
IC to wake it up. This interrupt function can be used when the communication between
the STM32 MCU and the DEMO-CR95HF-A is performed in SPI mode.
●CR95HFDll_SendNSSPulse: sends an interrupt pulse to the NSS pin of the CR95HF
IC to wake it up. This interrupt function can be used when the communication between
the STM32 MCU and the DEMO-CR95HF-A is performed in UART mode.
●CR95HFDll_Polling_Reading: launches a polling sequence and reads the CR95HF
answer buffer to retrieve the answer when it is not available in the FIFO answer buffer
(e.g. after an IDLE command)
4/42Doc ID 022016 Rev 2
AN3954Getting started
-36
)3/2&
-#5
#2(&
#ONTACTLESS
TAG
#2(&
LIBRARY
2&
$%-/#2(&!
53"
(/34
#/-054%2
53"
#2$LLDLL
Figure 5.Typical application block diagram
Finally, the CR95HFDll_SendReceive function sends an RF frame to any tag present in the
RF field and receives its answer according to the RF protocol previously defined using the
Select command (see Figure 6).
Figure 6.Typical application block diagram
(/34
#/-054%2
#2$LLDLL
53"
53"
#2(&
LIBRARY
-#5
$%-/#2(&!
#2(&
)3/2&
2&
#ONTACTLESS
TAG
-36
Doc ID 022016 Rev 25/42
Function descriptionsAN3954
2 Function descriptions
This section describes the various functions required to evaluate the DEMO-CR95HF-A
demonstration board.
2.1 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.
This is used by software to ensure that the DLL is correctly installed and that it is up to date.
If no DLL file is found, it returns an error message.
Visual Basic language
Declaration: Public Declare Function CR95HFDll_GetDLLrev Lib
"CR95HF.dll" (ByVal mystring As String) As Long
Prototype: Dim lngStatus As Long
Dim strAnswer As String * 256
lngStatus = CR95HFDll_GetDLLrev(strAnswer)
Input parameter:None
Output parameter:strAnswer: Revision of the DLL installed on your PC system.
Answer example: "0.4"
Returned value: lngStatus: 0
Source code example
Private Sub cmdGetDllRev_Click()
Dim strAnswer As String * 256
Dim lngStatus As Long
lngStatus = CR95HFDll_GetDLLrev(strAnswer)
If (lngStatus = 0) Then
txtDllRev.Text = strAnswer
Else
txtDllRev.Text = "Error = no Dll found"
End If
End Sub
printf("DEMO-CR95HF-A is connected and ready to be used\n\n\r");
else
printf("Error : DEMO-CR95HF-A not ready to be used\n\n\r");
printf("\n\n\n\n");
printf("\npress any key to continue");
printf("\n");
scanf("%s", &entry3);
return iresult;
}
2.1.3 CR95HFDLL_USBhandlecheck
This function can be used to verify if the DEMO-CR95HF-A is correctly connected to the
USB port of the computer and if the USB Handle attribué by the CR95HFDLL_USBconnect
is always valid.
Visual Basic language
Declaration:Public Declare Function CR95HFDLL_USBhandlecheck Lib
"CR95HF.dll" () As Long
Prototype:Dim lngStatus as long
lngStatus = CR95HFDLL_USBhandlecheck()
Input parameter: None
Output parameter:None
Returned value:lngStatus:
0: the USB handle is valid
1: the USB handle is invalid and the DEMO-CR95HF-A board
not connected
Source code example
Private Sub cmdUSBhandlecheck_Click()
Dim lngStatus As Long
txtUSBhandlecheckAnswer.Text = ""
lngStatus = CR95HFDLL_USBhandlecheck()
If (lngStatus = 0) Then
txtUSBhandlecheckAnswer.Text = "DEMO-CR95HF-A connected"
ElseIf (lngStatus = 5) Then
txtUSBhandlecheckAnswer.Text = "DEMO-CR95HF-A not connected (use
CR95HFDLL_USBconnect to connect it)"
End If
End Sub
Doc ID 022016 Rev 29/42
Function descriptionsAN3954
C/C++ language
Declaration: __declspec(dllexport) int __stdcall
CR95HFDLL_USBhandcheck(void);
Prototype:int iresult;
iresult= CR95HFDLL_USBhandcheck();
Input parameter:None
Output parameter:None
Return value:iresult:
0: the USB handle is valid
1: the USB handle is invalid and the DEMO-CR95HF-A board
not connected
Source code example
int DEMO_CR95HF_A_USBhandlecheck (void)
{
int iresult;
char entry3;
printf("\n\n\n\n");
iresult= CR95HFDLL_USBhandlecheck ();
printf("\nCR95HFDll_USBhandlecheck function:\n");
printf("\n --> request : CR95HFDll_USBhandlecheck()");
printf("\n <-- answer : ");
if (iresult == 0)
printf("DEMO-CR95HF-A is well connected\n\n\r");
else
printf("Error : DEMO-CR95HF-A not connected (use
CR95HFDLL_USBConnect)\n\n\r");
printf("\n\n\n\n");
printf("\npress any key to continue");
printf("\n");
scanf("%s", &entry3);
return iresult;
}
10/42Doc ID 022016 Rev 2
AN3954Function descriptions
2.2 Functions to communicate with the STM32 MCU
2.2.1 CR95HFDll_Echo
This function sends a USB request to the STM32 MCU that executes an Echo request on
the CR95HF. The STM32 MCU sends back the answer of the CR95HF, if possible, or
returns an error code ‘1’ if there is no answer.
Note:The Echo request uses the EchoCode command to perform a serial interface echo. For
more information, refer to the CR95HF transceiver datasheet.
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.
Answer example: “5500”
Returned value:lngStatus:
0: No error
5: DEMO-CR95HF-A board not connected
Source code example
Private Sub cmdEcho_Click()
Dim strAnswer As String * 256
Dim lngStatus As Long
lngStatus = CR95HFDll_Echo(strAnswer)
If (lngStatus = 0) Then
txtEchoAnswer.Text = strAnswer
Else
txtEchoAnswer.Text = "No communication with DEMO-CR95HF-A board"
End If
End Sub
Doc ID 022016 Rev 211/42
Function descriptionsAN3954
C/C++ language
Declaration:__declspec(dllimport) int __stdcall CR95HFDll_Echo(char