ST AN3954 Installation and operating instructions

January 2017 Doc ID022016 Rev 4 1/47
1
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
www.st.com

Contents AN3954
2/47 Doc ID022016 Rev 4
Contents
1 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1 Connecting the board to the computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Using the DLL system file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.1 Overview of DLL functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Description of functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1 Functions to check DLL installation and USB connection . . . . . . . . . . . . . 8
2.1.1 CR95HFDll_GetDLLrev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1.2 CR95HFDLL_USBconnect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.1.3 CR95HFDLL_USBhandlecheck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Functions to communicate with the STM32 MCU . . . . . . . . . . . . . . . . . . 12
2.2.1 CR95HFDll_Echo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.2 CR95HFDLL_getMCUrev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2.3 CR95HFDLL_getHardwareVersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2.4 CR95HFDLL_getInterfacePinState . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.3 Functions to communicate with the CR95HF IC . . . . . . . . . . . . . . . . . . . 20
2.3.1 CR95HFDll_Idn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.3.2 CR95HFDll_Select . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.3.3 CR95HFDll_STCmd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.3.4 CR95HFDll_FieldOff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.3.5 CR95HFDll_ResetSPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.3.6 CR95HFDll_SendIRQPulse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.3.7 CR95HFDll_Polling_Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.3.8 CR95HFDll_SendNSSPulse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.4 Functions to communicate with an RF tag . . . . . . . . . . . . . . . . . . . . . . . . 40
2.4.1 CR95HFDll_SendReceive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.4.2 SendReceive Request and Response maximum data size . . . . . . . . . . 43
Appendix A Error codes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

Doc ID022016 Rev 4 3/47
AN3954 List of tables
3
List of tables
Table 1. List of error codes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Table 2. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

List of figures AN3954
4/47 Doc ID022016 Rev 4
List of figures
Figure 1. CR95HF demonstration board embedded in the M24LR-Discovery kit . . . . . . . . . . . . . . . . 1
Figure 2. Typical application block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 3. Function CR95HFDLL_USBconnect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 4. Driving the MCU on the CR95HF demonstration board from the PC . . . . . . . . . . . . . . . . . . 6
Figure 5. Driving the CR95HF from the PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 6. Sending frames directly to the tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Doc ID022016 Rev 4 5/47
AN3954 Getting started
46
1 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
recommended to download and use the CR95HF development software (STSW-95HF001)
available on www.st.com. This software (and not this application note) can be used as a
reference to improve and test the CR95HF demonstration board functions and the
communication with tags, in various RF protocols.
1.1 Connecting the board to the computer
As shown in Figure 2, the CR95HF demonstration board is connected to the host computer
through its USB port, no particular driver is needed. The HID USB driver (already included in
all Windows operating systems) is used for communication.
Through the USB port of the computer, the user can drive the board, communicate with the
STM32 MCU, manage the CR95HF IC and send requests to an RF tag.
Figure 2. Typical application block diagram
1.2 Using the DLL system file
A DLL file (CR95HF.dll) is provided to drive the CR95HF demonstration 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 (available from DLL revision 0.5 and higher) is
required to connect the CR95HF demonstration board to the host computer and
069
&RQWDFWOHVVWDJ
5)
5),'SURWRFRO
&5+)GHPRQVWUDWLRQERDUG
86%
+RVW
FRPSXWHU
&5'OOGOO 6700&8
&5+)
86%
&5+)OLEUDU\
5)

Getting started AN3954
6/47 Doc ID022016 Rev 4
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 3).
The CR95HFDLL_USBhandlecheck function can be used to verify if the CR95HF
demonstration board is connected to the USB port of the computer. It is available from DLL
revision 0.6 and higher. This function sends a request to the CR95HF demonstration board
and waits for an acknowledge. An error code is sent if the communication with the board has
been lost. In this case, the CR95HFDLL_USBconnect can be used to reconnect the board
to the host computer.
Figure 3. Function CR95HFDLL_USBconnect
A set of functions are available to drive the STM32 MCU (see Figure 4):
•CR95HFDll_Echo: verifies that the CR95HF demonstration board is connected to the
USB port of the computer.
•CR95HFDLL_getMCUrev: reads the firmware revision of the STM32 MCU.
•CR95HFDLL_getHardwareVersion: reads the hardware version of the boards
(available on latest MCU revision boards / introduced from dll revision 0.9).
•CR95HFDLL_getInterfacePinState: verifies the communication path between the
STM32 MCU and the CR95HF IC (either SPI or UART).
Figure 4. Driving the MCU on the CR95HF demonstration board from the PC
069
&RQWDFWOHVVWDJ
5)
5),'SURWRFRO
&5+)GHPRQVWUDWLRQERDUG
86%
+RVW
FRPSXWHU
&5'OOGOO 6700&8
&5+)
86%
&5+)OLEUDU\
5)
5HYLVLRQ
069
&RQWDFWOHVVWDJ
5)
5),'SURWRFRO
&5+)GHPRQVWUDWLRQERDUG
86%
+RVW
FRPSXWHU
&5'OOGOO 6700&8
&5+)
86%
&5+)OLEUDU\
5)

Doc ID022016 Rev 4 7/47
AN3954 Getting started
46
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 CR95HF demonstration board 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 CR95HF demonstration board 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)
Figure 5. Driving the CR95HF from the PC
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. Sending frames directly to the tag
069
&RQWDFWOHVVWDJ
5)
5),'SURWRFRO
&5+)GHPRQVWUDWLRQERDUG
86%
+RVW
FRPSXWHU
&5'OOGOO 6700&8
&5+)
86%
&5+)OLEUDU\
5)
069
&RQWDFWOHVVWDJ
5)
5),'SURWRFRO
&5+)GHPRQVWUDWLRQERDUG
86%
+RVW
FRPSXWHU
&5'OOGOO 6700&8
&5+)
86%
&5+)OLEUDU\
5)

Description of functions AN3954
8/47 Doc ID022016 Rev 4
2 Description of functions
This section describes the various functions required to evaluate the CR95HF
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

Doc ID022016 Rev 4 9/47
AN3954 Description of functions
46
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: lresult: 0
Source code example
int Get_Dll_rev (void)
{char strAnswer[50]="";
int iresult;
char entry3;
printf("\n\n\n\n");
iresult = CR95HFDll_GetDLLrev(strAnswer);
printf("\nGet Dll revision using CR95HFDll_GetDLLrev
function:\n");
printf("\n --> request : CR95HFDll_GetDLLrev(strAnswer)");
printf("\n <-- answer : ");
if (iresult == 0)
printf("%s = DLL version\n\n\r", strAnswer);
else printf("%s = Error : no communication with MCU\n\n\r",
strAnswer);
printf("\n\n\n\n");
printf("\npress any key to continue");
printf("\n");
scanf("%s", &entry3);
return iresult;
}

Description of functions AN3954
10/47 Doc ID022016 Rev 4
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" () As Long
Prototype:Dim lngStatus As Long
lngStatus = CR95HFDLL_USBconnect()
Input parameter: None
Output parameter: None
Returned value: lngStatus:
0: the CR95HF demonstration board is connected
and ready to be used
1: the CR95HF demonstration board is not connected
Source code example
Private Sub cmdUSBconnect_Click()
Dim lngStatus As Long
lngStatus = CR95HFDLL_USBconnect()
If (lngStatus = 0) Then
txtUSBconnectAnswer.Text="CR95HF demonstration board connected
and ready to be used"
Else txtUSBconnectAnswer.Text = "CR95HF demonstration board not
connected"
End If
End Sub
C/C++ language
Declaration: __declspec(dllexport) int __stdcall
CR95HFDLL_USBconnect(void);
Prototype:int iresult;
iresult= CR95HFDLL_USBconnect ();
Input parameter: None
Output parameter: None
Returned value: iresult:
0: the CR95HF demonstration board is connected and
ready to be used
1: the CR95HF demonstration board is not connected
Source code example
int DEMO_CR95HF_A_USBconnect (void)
{int iresult;
char entry3;
printf("\n\n\n\n");

Doc ID022016 Rev 4 11/47
AN3954 Description of functions
46
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");
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 CR95HF demonstration board is correctly
connected to the USB port of the computer and if the USB Handle assigned 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
5: the USB handle is invalid and the CR95HF demonstration
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 = "CR95HF demonstration board
connected"
ElseIf (lngStatus = 5) Then
txtUSBhandlecheckAnswer.Text = "CR95HF demonstration board not
connected (use CR95HFDLL_USBconnect to connect it)"
End If
End Sub

Description of functions AN3954
12/47 Doc ID022016 Rev 4
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
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 : CR95HF demonstration board 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;
}
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.

Doc ID022016 Rev 4 13/47
AN3954 Description of functions
46
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: CR95HF demonstration 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 CR95HF demonstration
board"
End If
End Sub
C/C++ language
Declaration: __declspec(dllimport) int __stdcall CR95HFDll_Echo(char
*Stringreply);
Prototype:int iresult;
char strAnswer[50]="";
iresult= 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:iresult:
0: No error
5: CR95HF demonstration board not connected
Source code example
int Echo (void)
{
char strAnswer[50]="";
int iresult;
char entry3;

Description of functions AN3954
14/47 Doc ID022016 Rev 4
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);
printf("\n\n\n\n");
printf("\npress any key to continue");
printf("\n");
scanf("%s", &entry3);
return iresult;
}
2.2.2 CR95HFDLL_getMCUrev
This function sends a USB request to the STM32 MCU on the CR95HF demonstration
board that sends back the revision number of its firmware.
Visual Basic language
Declaration:Public Declare Function CR95HFDLL_getMCUrev Lib
"CR95HF.dll" (ByVal mystring As String) As Long
Prototype:status = CR95HFDLL_getMCUrev(strAnswer)
Input parameter:None
Output parameter: strAnswer: Firmware revision of the STM32 MCU on CR95HF
demonstration board.
Answer example: “0003010300”
Where:
00: Status byte (see Appendix A for error codes)
03: Size of answer (in bytes)
010300: Revision 1.3.0
Returned value: lngStatus:
0: No error
5: CR95HF demonstration board not connected
Source code example
Private Sub cmdGetMCURev_Click()
Dim strAnswer As String * 256
Dim lngStatus As Long
lngStatus = CR95HFDLL_getMCUrev(strAnswer)
If (lngStatus = 0) Then
txtMCUrev.Text = strAnswer

Doc ID022016 Rev 4 15/47
AN3954 Description of functions
46
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.
Answer example: “0003010300”
Where:
00: Status byte (see Appendix A for error codes)
03: Size of answer (in bytes)
010300: Revision 1.3.0
Returned value:iresult:
0: No error
5: CR95HF demonstration board not connected
Source code example
int Get_MCU_rev (void)
{
char strAnswer[50]="";
int iresult;
char entry3;
printf("\n\n\n\n");
iresult = CR95HFDLL_getMCUrev(strAnswer);
printf("\nGet MCU revision using CR95HFDLL_getMCUrev function:\n");
printf("\n --> request : CR95HFDLL_getMCUrev(strAnswer)");
printf("\n <-- answer : ");
if (iresult == 0)
printf("%s = MCU version\n\n\r", strAnswer);
else printf("%s = Error : no communication with MCU\n\n\r",
strAnswer);
printf("\n\n\n\n");
printf("\npress any key to continue");
printf("\n");
scanf("%s", &entry3);
return iresult;
}

Description of functions AN3954
16/47 Doc ID022016 Rev 4
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.
The hardware revision number is available since CR95HF demonstration board with MCU
revision 2.1 (produced after 2012-10).
Visual Basic language
Declaration:Public Declare Function CR95HFDLL_getHardwareVersion Lib
"CR95HF.dll" (ByVal mystring As String) As Long
Prototype lngStatus = CR95HFDLL_getHardwareVersion(strAnswer);
Input parameter:None
Output parameter: strAnswer: Hardware revision of the CR95HF demonstration board.
Answer example: "00074D423938335F41"
Where:
00: Status byte (see Appendix A for error codes)
03: Size of answer (in bytes)
4D423938335F41: Hardware revision (ASCII = MB983_A)
Answer example: "FE00"
Error return: CR95HF demonstration board doesn't contain
Hardware revision (too old)
Returned value: lngStatus:
0: No error
5: CR95HF demonstration board not connected

Doc ID022016 Rev 4 17/47
AN3954 Description of functions
46
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
For i = 0 To Mid(strAnswer, 3, 2) - 1
txtHardwareRevAscii.Text = txtHardwareRevAscii.Text &
Chr(CLng("&h" & Mid(strAnswer, (i * 2) + 5, 2)))
Next i
Else
txtHardwareRev.Text = "Hardware doesn't contain Hardware
Revision"
End If
Else
txtHardwareRev.Text = "Error = no communication with STM32 MCU"
End If
End Sub
C/C++ language
Declaration:__declspec(dllexport) int __stdcall
CR95HFDLL_getHardwareVersion(char* StringReply);
Prototype iresult = CR95HFDLL_getHardwareVersion(strAnswer);
Input parameter:None
Output parameter: strAnswer: Hardware revision of the CR95HF demonstration board
Answer example: "00074D423938335F41"
Where:
00: Status byte (see Appendix A for error codes)
03: Size of answer (in bytes)
4D423938335F41: Hardware revision (ASCII = MB983_A)
Answer example: "FE00"
Error return: CR95HF demonstration board doesn't contain
Hardware revision (too old)
Returned value: lngStatus:
0: No error
5: CR95HF demonstration board not connected

Description of functions AN3954
18/47 Doc ID022016 Rev 4
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);
else
printf("%s = Error : no communication with MCU\n\n\r", strAnswer);
printf("\n\n\n\n");
printf("\npress any key to continue");
printf("\n");
scanf("%s", &entry3);
return iresult;
}
2.2.4 CR95HFDLL_getInterfacePinState
This function verifies the communication path between the STM32 MCU and the CR95HF
IC (either SPI or UART).
The STM32 MCU checks which communication configuration is selected on the CR95HF
demonstration board. Two solder bridges are available to select the SPI or UART
configuration. By default, the board is delivered in the SPI configuration.
Visual Basic language
Declaration:Public Declare Function CR95HFDLL_getMCUrev Lib
"CR95HF.dll" (ByVal mystring As String) As Long
Prototype:status = CR95HFDLL_getMCUrev(strAnswer)
Input parameter:None
Output parameter: strAnswer: Interface Pin state.
Answer example: “00010X”
Where:
00: Status byte (see Appendix A for error codes)

Doc ID022016 Rev 4 19/47
AN3954 Description of functions
46
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
Private Sub cmdGetInterfacePinState_Click()
Dim strAnswer As String * 256
Dim lngStatus As Long
chkInterfacePinState(0).Value = vbUnchecked
chkInterfacePinState(1).Value = vbUnchecked
lngStatus = CR95HFDLL_getInterfacePinState(strAnswer)
If (lngStatus = 0) Then
txtGetInterfacePinStateAnswer.Text = strAnswer
If (Mid(strAnswer, 6, 1) = "0") Then
chkInterfacePinState(0).Value = vbChecked
chkInterfacePinState(1).Value = vbUnchecked
ElseIf (Mid(strAnswer, 6, 1) = "1") Then
chkInterfacePinState(0).Value = vbUnchecked
chkInterfacePinState(1).Value = vbChecked
Else
DoEvents
'error
End If
Else
txtGetInterfacePinStateAnswer.Text = "No answer from the DEMO-
CR95HF-A board"
End If
End Sub
C/C++ language
Declaration:__declspec(dllexport) int __stdcall
CR95HFDLL_getInterfacePinState(char* stringreply);
Prototypeint iresult;
char strAnswer[50]="";
iresult = CR95HFDLL_getInterfacePinState(strAnswer);
Input parameter:None
Output parameter: strAnswer: Interface Pin state.
Answer example: “00010X”
Where:
00: Status byte (see Appendix A for error codes)
01: Size of answer (in bytes)
0X: Communication mode

Description of functions AN3954
20/47 Doc ID022016 Rev 4
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;
printf("\n\n\n\n");
iresult = CR95HFDLL_getInterfacePinState(strAnswer);
printf("\nGet Interface Pin State CR95HFDLL_getInterfacePinState
function:\n");
printf("\n --> request :
CR95HFDLL_getInterfacePinState(strAnswer)");
printf("\n <-- answer : ");
if (iresult == 0)
{ printf("%s = Get Interface Pin State successfully\n\n\r",
strAnswer);
if (strAnswer[5] == '0')
printf("\n %c = communication in UART
mode",strAnswer[3]);
else
printf("\n %c = communication in SPI
mode",strAnswer[3]);
}
else
printf("\n %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 Functions to communicate with the CR95HF IC
2.3.1 CR95HFDll_Idn
This function sends a USB request to the STM32 MCU that requests the IDN of the
CR95HF IC. The STM32 MCU sends back the answer of the CR95HF containing the IDN
value (ASCII codes), if possible, or returns an error code ‘1’ if there is no answer.
This manual suits for next models
1
Table of contents
Other ST Motherboard manuals

ST
ST STM32H5 User manual

ST
ST EVALSP1340CPU User manual

ST
ST NUCLEO-H745ZI-Q User manual

ST
ST UM1509 User manual

ST
ST STEVAL-DIGAFEV1 User manual

ST
ST STM32373C-EVAL User manual

ST
ST X-NUCLEO-IDW01M1 User manual

ST
ST PowerSTEP01 EVLPOWERSTEP01 User manual

ST
ST STLINK-V3SET User manual

ST
ST STSW-S2LP-KNX-DK User manual