This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of X-MBED-NFC1 by
This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.
The available demos are:
- SAMPLE_WRITE_URL: write a tag with the ST home page URL
- SAMPLE_COUNT_CLICK: create a custom tag to count and report the user button clicks.
- SAMPLE_WRITE_AND_CHANGE_ALL: write a tag with all the supported records and update the tag contents when the user button is pressed.
- SAMPLE_LOCK_TAG_CONTENT: use the M24SR component API to set the NFC tag as read-only.
To enable the different demos comment/uncomment the SAMPLE_* macros provided in main.cpp .
Samples/SampleSync_writeUrl.cpp@20:ba95e0dc5975, 2017-08-21 (annotated)
- Committer:
- giovannivisentini
- Date:
- Mon Aug 21 12:12:30 2017 +0000
- Revision:
- 20:ba95e0dc5975
- Parent:
- 19:de38cedf89d6
update NDefLib and mbed libs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
giovannivisentini | 13:685d95525ec8 | 1 | /** |
giovannivisentini | 13:685d95525ec8 | 2 | ****************************************************************************** |
Davidroid | 18:d596eb3f575f | 3 | * @file SampleSync_writeUrl.cpp |
giovannivisentini | 13:685d95525ec8 | 4 | * @author ST / Central Labs |
giovannivisentini | 13:685d95525ec8 | 5 | * @date 03 Dic 2015 |
giovannivisentini | 13:685d95525ec8 | 6 | * @brief This demo write an ndef message with an url inside |
giovannivisentini | 13:685d95525ec8 | 7 | ****************************************************************************** |
giovannivisentini | 13:685d95525ec8 | 8 | * |
giovannivisentini | 13:685d95525ec8 | 9 | * COPYRIGHT(c) 2015 STMicroelectronics |
giovannivisentini | 13:685d95525ec8 | 10 | * |
giovannivisentini | 13:685d95525ec8 | 11 | * Redistribution and use in source and binary forms, with or without modification, |
giovannivisentini | 13:685d95525ec8 | 12 | * are permitted provided that the following conditions are met: |
giovannivisentini | 13:685d95525ec8 | 13 | * 1. Redistributions of source code must retain the above copyright notice, |
giovannivisentini | 13:685d95525ec8 | 14 | * this list of conditions and the following disclaimer. |
giovannivisentini | 13:685d95525ec8 | 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
giovannivisentini | 13:685d95525ec8 | 16 | * this list of conditions and the following disclaimer in the documentation |
giovannivisentini | 13:685d95525ec8 | 17 | * and/or other materials provided with the distribution. |
giovannivisentini | 13:685d95525ec8 | 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
giovannivisentini | 13:685d95525ec8 | 19 | * may be used to endorse or promote products derived from this software |
giovannivisentini | 13:685d95525ec8 | 20 | * without specific prior written permission. |
giovannivisentini | 13:685d95525ec8 | 21 | * |
giovannivisentini | 13:685d95525ec8 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
giovannivisentini | 13:685d95525ec8 | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
giovannivisentini | 13:685d95525ec8 | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
giovannivisentini | 13:685d95525ec8 | 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
giovannivisentini | 13:685d95525ec8 | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
giovannivisentini | 13:685d95525ec8 | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
giovannivisentini | 13:685d95525ec8 | 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
giovannivisentini | 13:685d95525ec8 | 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
giovannivisentini | 13:685d95525ec8 | 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
giovannivisentini | 13:685d95525ec8 | 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
giovannivisentini | 13:685d95525ec8 | 32 | * |
giovannivisentini | 13:685d95525ec8 | 33 | ****************************************************************************** |
giovannivisentini | 13:685d95525ec8 | 34 | */ |
giovannivisentini | 13:685d95525ec8 | 35 | |
giovannivisentini | 13:685d95525ec8 | 36 | #include "mbed.h" |
giovannivisentini | 13:685d95525ec8 | 37 | |
giovannivisentini | 17:d8d3d2088cac | 38 | #include "XNucleoNFC01A1.h" |
giovannivisentini | 13:685d95525ec8 | 39 | #include "NDefLib/NDefNfcTag.h" |
giovannivisentini | 13:685d95525ec8 | 40 | #include "NDefLib/RecordType/RecordURI.h" |
giovannivisentini | 13:685d95525ec8 | 41 | |
giovannivisentini | 13:685d95525ec8 | 42 | /** |
giovannivisentini | 13:685d95525ec8 | 43 | * Write a Ndef linking the st.com site. |
giovannivisentini | 13:685d95525ec8 | 44 | */ |
giovannivisentini | 13:685d95525ec8 | 45 | void sampleSync_writeUrl() { |
giovannivisentini | 17:d8d3d2088cac | 46 | I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN); |
giovannivisentini | 17:d8d3d2088cac | 47 | XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel); |
giovannivisentini | 13:685d95525ec8 | 48 | |
giovannivisentini | 13:685d95525ec8 | 49 | //retrieve the NdefLib interface |
giovannivisentini | 17:d8d3d2088cac | 50 | NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag(); |
giovannivisentini | 15:94c98d2aa235 | 51 | printf("System Init done: !\r\n"); |
giovannivisentini | 13:685d95525ec8 | 52 | //open the i2c session with the nfc chip |
Davidroid | 18:d596eb3f575f | 53 | if (tag.open_session()) { |
giovannivisentini | 17:d8d3d2088cac | 54 | nfcNucleo->get_led1()=1; |
giovannivisentini | 13:685d95525ec8 | 55 | |
giovannivisentini | 13:685d95525ec8 | 56 | //create the NDef message and record |
giovannivisentini | 13:685d95525ec8 | 57 | NDefLib::Message msg; |
giovannivisentini | 13:685d95525ec8 | 58 | NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com"); |
giovannivisentini | 17:d8d3d2088cac | 59 | msg.add_record(&rUri); |
giovannivisentini | 13:685d95525ec8 | 60 | |
giovannivisentini | 13:685d95525ec8 | 61 | //write the tag |
Davidroid | 18:d596eb3f575f | 62 | if (tag.write(msg)) { |
nikapov | 19:de38cedf89d6 | 63 | printf("Tag written \r\n"); |
giovannivisentini | 17:d8d3d2088cac | 64 | nfcNucleo->get_led2()=1; |
giovannivisentini | 13:685d95525ec8 | 65 | } |
giovannivisentini | 13:685d95525ec8 | 66 | |
giovannivisentini | 13:685d95525ec8 | 67 | |
giovannivisentini | 13:685d95525ec8 | 68 | //close the i2c session |
Davidroid | 18:d596eb3f575f | 69 | if (!tag.close_session()) { |
giovannivisentini | 15:94c98d2aa235 | 70 | printf("Error Closing the session\r\n"); |
Davidroid | 18:d596eb3f575f | 71 | } else { |
giovannivisentini | 17:d8d3d2088cac | 72 | nfcNucleo->get_led3()=1; |
Davidroid | 18:d596eb3f575f | 73 | } |
Davidroid | 18:d596eb3f575f | 74 | } else { |
giovannivisentini | 15:94c98d2aa235 | 75 | printf("Error open Session\r\n"); |
Davidroid | 18:d596eb3f575f | 76 | } |
giovannivisentini | 13:685d95525ec8 | 77 | } |