1+ /* *
2+ ******************************************************************************
3+ * @file ST25DV_HelloWorld.ino
4+ * @author STMicroelectronics
5+ * @version V1.0.0
6+ * @date 22 November 2017
7+ * @brief Arduino test application for the STMicrolectronics
8+ * ST25DV NFC device.
9+ * This application makes use of C++ classes obtained from the C
10+ * components' drivers.
11+ ******************************************************************************
12+ * @attention
13+ *
14+ * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
15+ *
16+ * Redistribution and use in source and binary forms, with or without modification,
17+ * are permitted provided that the following conditions are met:
18+ * 1. Redistributions of source code must retain the above copyright notice,
19+ * this list of conditions and the following disclaimer.
20+ * 2. Redistributions in binary form must reproduce the above copyright notice,
21+ * this list of conditions and the following disclaimer in the documentation
22+ * and/or other materials provided with the distribution.
23+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
24+ * may be used to endorse or promote products derived from this software
25+ * without specific prior written permission.
26+ *
27+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37+ *
38+ ******************************************************************************
39+ */
40+
41+ /* *
42+ ******************************************************************************
43+ * How to use this sketch
44+ *
45+ * This sketch uses the I2C interface to communicate with the NFC device.
46+ * It writes an NFC tag type URI (Uniform Resource Identifier) and reads this same tag.
47+ * Choose the uri by changing the content of uri_write.
48+ *
49+ * When the NFC module is started and ready, the message "Sytstem init done!" is
50+ * displayed on the monitor window. Next, the tag is written, read and printed on
51+ * the monitor window.
52+ *
53+ * You can also use your smartphone to read/write a tag.
54+ * On Android, download a NFC Tools. Then start the app, check if NFC is activated
55+ * on your smartphone. Put your smartphone near the tag, you can read it. You can
56+ * write a tag with this app.
57+ ******************************************************************************
58+ */
59+
60+ #include " ST25DVSensor.h"
61+
62+ #define SerialPort Serial
63+
64+ #if defined(ARDUINO_B_L4S5I_IOT01A)
65+ // Pin definitions for board B-L4S5I_IOT01A
66+ #define GPO_PIN PE4
67+ #define LPD_PIN PE2
68+ #define SDA_PIN PB11
69+ #define SCL_PIN PB10
70+
71+ #define WireNFC MyWire
72+ TwoWire MyWire (SDA_PIN, SCL_PIN);
73+
74+ #else
75+ // Please define the pin and wire instance used for your board
76+ // #define GPO_PIN PE4
77+ // #define LPD_PIN PE2
78+ // #define SDA_PIN PB11
79+ // #define SCL_PIN PB10
80+
81+ #define WireNFC Wire // Default wire instance
82+
83+ #endif
84+
85+ #if !defined(GPO_PIN) || !defined(LPD_PIN)
86+ #error define the pin and wire instance used for your board
87+ #endif
88+
89+
90+ void setup () {
91+ const char uri_write_message[] = " st.com/st25" ; // Uri message to write in the tag
92+ const char uri_write_protocol[] = URI_ID_0x01_STRING; // Uri protocol to write in the tag
93+ String uri_write = String (uri_write_protocol) + String (uri_write_message);
94+ String uri_read;
95+
96+ // Initialize serial for output.
97+ SerialPort.begin (115200 );
98+
99+ // The wire instance used can be omited in case you use default Wire instance
100+ if (st25dv.begin (GPO_PIN, LPD_PIN, &WireNFC) == 0 ) {
101+ SerialPort.println (" System Init done!" );
102+ } else {
103+ SerialPort.println (" System Init failed!" );
104+ while (1 );
105+ }
106+
107+ if (st25dv.writeURI (uri_write_protocol, uri_write_message, " " )) {
108+ SerialPort.println (" Write failed!" );
109+ while (1 );
110+ }
111+
112+ delay (100 );
113+
114+ if (st25dv.readURI (&uri_read)) {
115+ SerialPort.println (" Read failed!" );
116+ while (1 );
117+ }
118+
119+ SerialPort.println (uri_read.c_str ());
120+
121+ if (strcmp (uri_read.c_str (), uri_write.c_str ()) == 0 ) {
122+ SerialPort.println (" Successfully written and read!" );
123+ } else {
124+ SerialPort.println (" Read bad string!" );
125+ }
126+ }
127+
128+ void loop () {
129+ // empty loop
130+ }
0 commit comments