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@13:685d95525ec8, 2016-02-01 (annotated)
- Committer:
- giovannivisentini
- Date:
- Mon Feb 01 15:33:26 2016 +0000
- Revision:
- 13:685d95525ec8
- Child:
- 15:94c98d2aa235
add sync and async demos
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
giovannivisentini | 13:685d95525ec8 | 1 | /** |
giovannivisentini | 13:685d95525ec8 | 2 | ****************************************************************************** |
giovannivisentini | 13:685d95525ec8 | 3 | * @file Sample_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 | 13:685d95525ec8 | 38 | #include "X_NUCLEO_NFC01A1.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 | 13:685d95525ec8 | 46 | I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN); |
giovannivisentini | 13:685d95525ec8 | 47 | X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel); |
giovannivisentini | 13:685d95525ec8 | 48 | |
giovannivisentini | 13:685d95525ec8 | 49 | //retrieve the NdefLib interface |
giovannivisentini | 13:685d95525ec8 | 50 | NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag(); |
giovannivisentini | 13:685d95525ec8 | 51 | printf("System Init done: !\n\r"); |
giovannivisentini | 13:685d95525ec8 | 52 | //open the i2c session with the nfc chip |
giovannivisentini | 13:685d95525ec8 | 53 | if(tag.openSession()){ |
giovannivisentini | 13:685d95525ec8 | 54 | nfcNucleo->getLed1()=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 | 13:685d95525ec8 | 59 | msg.addRecord(&rUri); |
giovannivisentini | 13:685d95525ec8 | 60 | |
giovannivisentini | 13:685d95525ec8 | 61 | //write the tag |
giovannivisentini | 13:685d95525ec8 | 62 | if(tag.write(msg)){ |
giovannivisentini | 13:685d95525ec8 | 63 | printf("Tag writed \n\r"); |
giovannivisentini | 13:685d95525ec8 | 64 | nfcNucleo->getLed2()=1; |
giovannivisentini | 13:685d95525ec8 | 65 | } |
giovannivisentini | 13:685d95525ec8 | 66 | |
giovannivisentini | 13:685d95525ec8 | 67 | |
giovannivisentini | 13:685d95525ec8 | 68 | //close the i2c session |
giovannivisentini | 13:685d95525ec8 | 69 | if(!tag.closeSession()){ |
giovannivisentini | 13:685d95525ec8 | 70 | printf("Error Closing the session\n\r"); |
giovannivisentini | 13:685d95525ec8 | 71 | }else |
giovannivisentini | 13:685d95525ec8 | 72 | nfcNucleo->getLed3()=1; |
giovannivisentini | 13:685d95525ec8 | 73 | }else |
giovannivisentini | 13:685d95525ec8 | 74 | printf("Error open Session\n\r"); |
giovannivisentini | 13:685d95525ec8 | 75 | } |