ST AN3227 APPLICATION NOTE

AN3227
Application note
Developing an application with the
STARTKIT-M24LR-A
Introduction
This application note explains how to develop a Visual Basic or C/C++ application code to drive STMicroelectronics STARTKIT-M24LR-A starter kit from a host computer. The STARTKIT-M24LR-A is a ISO 15693 reader designed to operate with the M24LRXX dual interface EEPROM. It is connected to the host USB port and can be used either as a I reader connected to the transponders through an I using the integrated RF antenna.

Figure 1. STARTKIT-M24LR-A

2
C bus cable or as an RF reader when
2
C
Reference documents
M24LRXX datasheet
“M24LRXX tool kit user guide” (UM0853)
“Configuring your ISO 15693 reader to support the M24LRXX” application note
(AN3163)
September 2011 Doc ID 17575 Rev 2 1/38
www.st.com
Contents AN3227
Contents
1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1 M24LRXX dual interface EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 STARTKIT-M24LR-A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 Installation requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1 HIDdll.dll installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Visual Basic project requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3 C/C++ project requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 STARTKIT-M24LR-A detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1 Reader detection functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.1 API_USBGetConnectedDeviceNum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.2 API_USBOpenWithNum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.1.3 API_USBCloseComm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2 Visual Basic source code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3 C/C++ source code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 USB API_USBALL function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.1 API_USBALL generic description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.1.1 Visual Basic API_USBALL prototype . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.1.2 C/C++ source API_USBALL prototype . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2 RF ISO 15693 High-level Inventory command . . . . . . . . . . . . . . . . . . . . . 15
4.2.1 Visual Basic source code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.2.2 C/C++ source code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.3 RF ISO 15693 Transparent commands . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.3.1 Read single block command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.3.2 Write single block command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.4 I2C commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.4.1 I2C start command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.4.2 I
4.4.3 I
4.4.4 I
4.4.5 I
2
C send byte command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2
C read byte command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2
C send ACK command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2
C send NoAck command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2/38 Doc ID 17575 Rev 2
AN3227 Contents
4.4.6 I2C read Ack command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.4.7 I
4.4.8 I
4.4.9 I
4.4.10 I
4.4.11 I
2
C stop command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2
C read X bytes command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2
C send X bytes command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2
C read data command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2
C Write data command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.5 STARTKIT-M24LR-A commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.5.1 LED command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.5.2 Buzzer command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.5.3 Get version command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Appendix A Useful source code zip files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Appendix B List of error codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Doc ID 17575 Rev 2 3/38
List of tables AN3227
List of tables
Table 1. API_USBGetConnectedDeviceNum Visual Basic function. . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 2. API_USBGetConnectedDeviceNum C/C++ function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 3. API_USBOpenWithNum Visual Basic function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Table 4. API_USBOpenWithNum C/C++ function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Table 5. API_USBCloseComm Visual Basic function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Table 6. API_USBCloseComm C/C++ function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Table 7. API_USBAll Visual Basic function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Table 8. API_USBAll C/C++ function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Table 9. RF ISO15693 high-level Inventory command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Table 10. Read single block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Table 11. Write single block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 12. I Table 13. I Table 14. I Table 15. I Table 16. I Table 17. I Table 18. I Table 19. I Table 20. I Table 21. I Table 22. I
Table 23. LED command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Table 24. Buzzer command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Table 25. Get version command. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Table 26. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2
C start. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2
C send byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2
C read byte. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2
C send Ack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2
C send NoAck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2
C read Ack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2
C stop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2
C read X bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2
C send X bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2
C read data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2
C write data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4/38 Doc ID 17575 Rev 2
AN3227 List of figures
List of figures
Figure 1. STARTKIT-M24LR-A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Figure 2. STARTKIT-M24LR-A application schematics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Doc ID 17575 Rev 2 5/38
Description AN3227
Dual Interface EEPROM
M24LR64-R
M24LR64-R I²C connector board
I²C bus
USB
cable
STARTKIT-M24LR-A
(RF and I²C reader)
Computer sends RF or I²C requests
through the USB port
RF antenna
M24LR64-R on board
RF antenna
AI18038

1 Description

1.1 M24LRXX dual interface EEPROM

The M24LRXX is a dual interface EEPROM which can be accessed either through an I2C serial bus or a contactless interface using the ISO 15693 RFID protocol.
To easily control the M24LRXX RF and I the STARTKIT-M24LR-A.
Refer to the product datasheet and to application note AN3163 “Configuring your ISO 15693 reader to support the M24LRXX” for more in-depth information on the M24LRXX and for explanations on the RF and I http://www.st.com.
Application note AN3227 helps software engineers using and including the software delivered with the STARTKIT-M24LR-A in their own application. Some examples are offered showing how to send an RF request in Visual Basic and C/C++. These examples also show how to manage the I
2
C protocol.

1.2 STARTKIT-M24LR-A

2
C communication protocols. Both documents are available on
2
C channels, ST offers several tools among which is
The STARTKIT-M24LR-A reader is connected to the host-computer USB port. It manages RF ISO 15693 commands (High-level Inventory and Transparent commands) and I
2
C
commands between the reader and M24LRXX-based transponders (see Figure 2:
STARTKIT-M24LR-A application schematics).

Figure 2. STARTKIT-M24LR-A application schematics

6/38 Doc ID 17575 Rev 2
AN3227 Description
RF ISO 15693 commands
RF ISO 15693 commands are sent by the host computer to the transponders via the reader RF interface. Two types of commands are available:
High-level Inventory command (see Section 4.2: RF ISO 15693 High-level
Inventory command)
The host sends an already formatted Inventory request to the transponders via the reader RF interface. This command launches an anticollision sequence to identify all the transponders present in the RF field and sends back the UID information to the host. Due to reader limitations, a maximum of two transponders can be detected by an Inventory request.
Transparent commands (see Section 4.3: RF ISO 15693 Transparent commands).
The host can also send RF Transparent commands to transponders via the reader RF interface. The Transparent commands send single or multiple frames compliant with the ISO 15693 protocol. Refer to the M24LRXX datasheet for a detailed description of the available Dual interface EEPROM command.
The transponders answers are sent back to the computer.
2
I
C commands (see Section 4.4: I2C commands).
2
I
C commands are sent by the host computer to the M24LRXX via the reader I2C bus.
The following sections explain how to detect the STARTKIT-M24LR-A reader and open the communication prior to sending RF or I then describe in details how to send RF commands to transponders and manage I
2
C commands to the M24LRXX transponders. They
2
C
communication.
Doc ID 17575 Rev 2 7/38
Installation requirements AN3227

2 Installation requirements

Communication with the STARTKIT-M24LR-A is based on the HID USB class. To be able to communicate with the reader, the HIDdll.dll file must be installed in your computer. This is mandatory for sending any RF or I
Depending on whether you use Visual Basic or C/C++, other .bas or .h files must be used for correct function declaration. These installations are outlined below.

2.1 HIDdll.dll installation

The HIDdll.dll contains all the functions allowing to drive the STARTKIT-M24LR-A.
Copy the HIDdll.dll which is delivery with the AN3227.zip available at http://www.st.com/dualeeprom to the Windows system folder of your computer (C:/Windows/System32). If you have installed the M24LRxx_Application_Software, then the HIDdll.dll file is already present in your Windows system folder.

2.2 Visual Basic project requirements

2
C request using the STARTKIT-M24LR-A.
To create a Visual Basic project, the HIDdll.bas header file must be inserted in your source code. It references all the STARTKIT-M24LR-A functions declared in the HIDdll.dll.
Insert the HIDdll.bas into your Visual Basic project. HIDdll.bas makes the link between HIDdll.dll and the source code. HIDdll.bas contains all the functions declarations and descriptions for whichever communication mode you choose: RF ISO 15693 or I
HIDdll.bas can be found in the AN3227.zip available at http://www.st.com/dualeeprom.
Below is an example of the command needing to be declared in your Visual Basic header file, when operating in RF ISO15693 mode or I
Public Declare Function API_USBAll Lib "HIDdll.DLL" (ByVal commHandle As Long, ByVal cmdSize As Long, ByRef cmd As Byte, ByRef returnlen As Byte, ByRef pBuffer As Byte) As Long

2.3 C/C++ project requirements

To create a C/C++ project, the HIDdll.h header file and the HIDdll.lib library, are required. HIDdll.h and HIDdll.lib files allow linking your source code to the HIDdll.dll file. HIDdll.h can
be found in the source code example AN3227.zip available at http://www.st.com/dualeeprom.
In the source code, declare the header files as follows:
#include "HIDdll.h"
2
C mode:
2
C mode.
Below is an example of the command needing to be declared in your C/C++ header file, when operating in RF ISO15693 mode or I
'extern "C" __declspec(dllexport) int __stdcall API_USBAll(HANDLE commHandle,int cmdSize, unsigned char *cmd, unsigned char *returnlen,unsigned char *pbuffer);
8/38 Doc ID 17575 Rev 2
2
C mode:
AN3227 STARTKIT-M24LR-A detection

3 STARTKIT-M24LR-A detection

To send an I2C or an RF command to the STARTKIT-M24LR-A reader, the computer must first detect the reader. Once it is detected, a handle is randomly assigned to the reader.
This section presents all the available functions for performing reader detection. Visual Basic and C/C++ source code examples are also provided.

3.1 Reader detection functions

The following functions are included in the HIDdll.dll file and must be called to be able to use the reader:
API_USBGetConnectedDeviceNum
This function detects any connected STARTKIT-M24LR-A reader, and sends back the number of readers connected to the USB ports of your computer.
API_USBOpenWithNum
This function returns the handle of the STARTKIT-M24LR-A identified by the index number. This reader must have been previously detected by the API_USBGetConnectedDeviceNum function.
API_USBCloseComm
This function closes USB communication for the STARTKIT-M24LR-A identified by its handle.

3.1.1 API_USBGetConnectedDeviceNum

API_USBGetConnectedDeviceNum Visual Basic prototype
Ta bl e 7 illustrates the API_USBGetConnectedDeviceNum Visual Basic function.
Table 1. API_USBGetConnectedDeviceNum Visual Basic function
Function description
Prototype
Parameters None
Returned value Number of connected USB devices minus 1
API_USBGetConnectedDeviceNum C/C++ prototype
Ta bl e 2 illustrates the API_USBGetConnectedDeviceNum C/C++ function.
Table 2. API_USBGetConnectedDeviceNum C/C++ function
Prototype
Parameters None
Public Declare Function API_USBGetConnectedDeviceNum Lib "HIDdll.DLL" () As Long
Function description
extern "C" __declspec(dllexport) int __stdcall API_USBGetConnectedDeviceNum(void);
Returned value Number of connected USB devices minus 1
Doc ID 17575 Rev 2 9/38
STARTKIT-M24LR-A detection AN3227

3.1.2 API_USBOpenWithNum

API_USBOpenWithNum Visual Basic prototype
Ta bl e 3 illustrates the API_USBOpenWithNum Visual Basic function.
Table 3. API_USBOpenWithNum Visual Basic function
Function description
Public Declare Function API_USBOpenWithNum Lib
Prototype
"HIDdll.DLL" (ByRef hcomm As Long, ByVal deviceIndex As Long, ByVal numInputBuffers As Byte) As Long
hcomm: STARTKIT-M24LR-A
Parameters
deviceIndex: device index (0x00 for one connected device) numinputBuffers: 0x40
Returned value Error code
API_USBOpenWithNum C/C++ prototype
Ta bl e 4 illustrates the API_USBOpenWithNum C/C++ function.
Table 4. API_USBOpenWithNum C/C++ function
extern "C" __declspec(dllexport) int __stdcall
Prototype
Parameters
Returned value Error code
API_USBOpenWithNum(HANDLE * hcomm,int deviceIndex,WORD numInputBuffers);
hcomm: STARTKIT-M24LR-A deviceIndex: device index (0x00 for one connected device) numinputBuffers: 0x40

3.1.3 API_USBCloseComm

API_USBCloseComm Visual Basic prototype
handle returned by the function
Function description
handle returned by the function
Ta bl e 5 illustrates the API_USBCloseComm Visual Basic function.
Table 5. API_USBCloseComm Visual Basic function
Function description
Prototype
Parameters commHandle: handle of the device to be closed
Returned value Error code
10/38 Doc ID 17575 Rev 2
Public Declare Function API_USBCloseComm Lib "HIDdll.DLL" (ByVal commHandle As Long) As Boolean
AN3227 STARTKIT-M24LR-A detection
API_USBCloseComm C/C++ prototype
Ta bl e 5 illustrates the API_USBCloseComm C/C++ function.
Table 6. API_USBCloseComm C/C++ function
Function description
Prototype
Parameters commHandle: handle of the device to be closed
Returned value Error code
extern "C" __declspec(dllexport) BOOL __stdcall API_USBCloseComm(HANDLE commHandle);

3.2 Visual Basic source code example

Below is an example of reader detection Visual Basic code:
Public Function Detect_STARTKIT_M24LR_A() As Boolean Dim lngNbStartKit As Long Dim lngStatus As Long Dim i As Long Dim deviceIndex As Integer Dim numInputBuffersInt As Integer Dim strDataMsg As String ‘STARTKIT-M24LR-A Dim lngReqDataLen As Long Dim abytReqData (0 To 63) As Byte Dim abytAnswerDataLen (0 To 63) As Byte Dim abytAnswerData (0 To 63) As Byte Dim strRequestData As String Dim strAnswerData As String 'RETURN THE NUMBER OF STARTKIT-M24LR-A DEVICES CONNECTED lngNbStartKit = API_USBGetConnectedDeviceNum() 'ONE STARTKIT-M24LR-A CONNECTED If (lngNbStartKit > 0) Then deviceIndex = 0 numInputBuffersInt = 64 '------> OPEN CONNECTION WITH STARTKIT-M24LR-A ‘------> GET USB HANDLE (hcomm_public) lngStatus = API_USBOpenWithNum(hcomm_public, _ deviceIndex, _ numInputBuffersInt) '------> GET FIRMWARE VERSION OF STARTKIT-M24LR-A strReqData = "86" lngReqDataLen = Len(strReqData) / 2 'lenght of request 'format request as Array of bytes for API_USBALL use For i = 0 To lngReqDataLen - 1 abytReqData (i) = CByte("&h" & Mid(strReqData, _ (i * 2) + 1, 2)) Next i lngStatus = API_USBAll(hcomm_public, _ lngReqDataLen,
Doc ID 17575 Rev 2 11/38
STARTKIT-M24LR-A detection AN3227
abytReqData(0), _ abytAnswerDataLen(0), abytAnswerData(0)) 'Analyse STARTKIT-M24LR-A answer For i = 1 To abytSTARTKITanswerSize(0) strAnswerData = strAnswerData & _ Chr(abytSTARTKITanswer(i - 1)) Next i 'DISPLAY STARTKIT-M24LR-A ANSWER = GET INFO txtDetectResult.Text = strAnswerData Else 'No STARTKIT-M24LR-A CONNECTED End If End Function
‘STARTKIT-M24LR-A KIT CLOSE USB COMMUNICATION Private Sub Form_terminate() Dim booAnswer As Boolean Dim lngCloseComm As Long booAnswer = API_USBCloseComm(hcomm_public) End Sub

3.3 C/C++ source code example

Below is an example of reader detection C/C++ code:
int detect_STARTKIT_M24LR_A () { int iNbStartKit; int deviceIndex; unsigned short numInputBuffersInt; int istatus; int entry3;
/* RETURN THE NUMBER OF STARTKIT-M24LR-A DEVICES CONNECTED */ iNbStartKit = API_USBGetConnectedDeviceNum();
/* ONE STARTKIT-M24LR-A CONNECTED */ if (iNbStartKit > 0) { deviceIndex = 0; numInputBuffersInt = 64; /* ------> OPEN CONNECTION AND GET USB HANDLE */ istatus = API_USBOpenWithNum(&hcomm_public, deviceIndex, numInputBuffersInt);
if (istatus == 0) {
/* USB connection OK */ /* hcomm_public is handle for STARTKIT-M24LR-A functions */ return 1;
12/38 Doc ID 17575 Rev 2
Loading...
+ 26 hidden pages