Demo NFC
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of HelloWorld_NFC01A1 by
main.cpp@0:151ae20d098f, 2015-12-21 (annotated)
- Committer:
- giovannivisentini
- Date:
- Mon Dec 21 10:17:57 2015 +0000
- Revision:
- 0:151ae20d098f
- Child:
- 1:eff1b8998438
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
giovannivisentini | 0:151ae20d098f | 1 | /** |
giovannivisentini | 0:151ae20d098f | 2 | ****************************************************************************** |
giovannivisentini | 0:151ae20d098f | 3 | * @file main.cpp |
giovannivisentini | 0:151ae20d098f | 4 | * @date 21/12/2015 |
giovannivisentini | 0:151ae20d098f | 5 | * @brief This demo write an ndef message with an url inside |
giovannivisentini | 0:151ae20d098f | 6 | ****************************************************************************** |
giovannivisentini | 0:151ae20d098f | 7 | * |
giovannivisentini | 0:151ae20d098f | 8 | * COPYRIGHT(c) 2015 STMicroelectronics |
giovannivisentini | 0:151ae20d098f | 9 | * |
giovannivisentini | 0:151ae20d098f | 10 | * Redistribution and use in source and binary forms, with or without modification, |
giovannivisentini | 0:151ae20d098f | 11 | * are permitted provided that the following conditions are met: |
giovannivisentini | 0:151ae20d098f | 12 | * 1. Redistributions of source code must retain the above copyright notice, |
giovannivisentini | 0:151ae20d098f | 13 | * this list of conditions and the following disclaimer. |
giovannivisentini | 0:151ae20d098f | 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
giovannivisentini | 0:151ae20d098f | 15 | * this list of conditions and the following disclaimer in the documentation |
giovannivisentini | 0:151ae20d098f | 16 | * and/or other materials provided with the distribution. |
giovannivisentini | 0:151ae20d098f | 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
giovannivisentini | 0:151ae20d098f | 18 | * may be used to endorse or promote products derived from this software |
giovannivisentini | 0:151ae20d098f | 19 | * without specific prior written permission. |
giovannivisentini | 0:151ae20d098f | 20 | * |
giovannivisentini | 0:151ae20d098f | 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
giovannivisentini | 0:151ae20d098f | 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
giovannivisentini | 0:151ae20d098f | 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
giovannivisentini | 0:151ae20d098f | 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
giovannivisentini | 0:151ae20d098f | 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
giovannivisentini | 0:151ae20d098f | 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
giovannivisentini | 0:151ae20d098f | 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
giovannivisentini | 0:151ae20d098f | 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
giovannivisentini | 0:151ae20d098f | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
giovannivisentini | 0:151ae20d098f | 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
giovannivisentini | 0:151ae20d098f | 31 | * |
giovannivisentini | 0:151ae20d098f | 32 | ****************************************************************************** |
giovannivisentini | 0:151ae20d098f | 33 | */ |
giovannivisentini | 0:151ae20d098f | 34 | |
giovannivisentini | 0:151ae20d098f | 35 | #include "mbed.h" |
giovannivisentini | 0:151ae20d098f | 36 | |
giovannivisentini | 0:151ae20d098f | 37 | #include "X_NUCLEO_NFC01A1.h" |
giovannivisentini | 0:151ae20d098f | 38 | #include "Type4NfcTagM24SR.h" |
giovannivisentini | 0:151ae20d098f | 39 | #include "NDefLib/RecordType/RecordURI.h" |
giovannivisentini | 0:151ae20d098f | 40 | |
giovannivisentini | 0:151ae20d098f | 41 | /** |
giovannivisentini | 0:151ae20d098f | 42 | * write a Ndef linking the st.com site |
giovannivisentini | 0:151ae20d098f | 43 | */ |
giovannivisentini | 0:151ae20d098f | 44 | int main(void){ |
giovannivisentini | 0:151ae20d098f | 45 | Serial pc(SERIAL_TX, SERIAL_RX); |
giovannivisentini | 0:151ae20d098f | 46 | |
giovannivisentini | 0:151ae20d098f | 47 | //use dafault board pin |
giovannivisentini | 0:151ae20d098f | 48 | I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN); |
giovannivisentini | 0:151ae20d098f | 49 | X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel); |
giovannivisentini | 0:151ae20d098f | 50 | |
giovannivisentini | 0:151ae20d098f | 51 | //create the wrapper for use the NdefLib |
giovannivisentini | 0:151ae20d098f | 52 | Type4NfcTagM24SR tag(nfcNucleo->getM24SR()); |
giovannivisentini | 0:151ae20d098f | 53 | pc.printf("System Init done: !\n\r"); |
giovannivisentini | 0:151ae20d098f | 54 | //open the i2c session with the nfc chip |
giovannivisentini | 0:151ae20d098f | 55 | if(tag.openSession()){ |
giovannivisentini | 0:151ae20d098f | 56 | nfcNucleo->getLed1()=1; |
giovannivisentini | 0:151ae20d098f | 57 | |
giovannivisentini | 0:151ae20d098f | 58 | //create the NDef message and record |
giovannivisentini | 0:151ae20d098f | 59 | NDefLib::Message msg; |
giovannivisentini | 0:151ae20d098f | 60 | NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com"); |
giovannivisentini | 0:151ae20d098f | 61 | msg.addRecord(&rUri); |
giovannivisentini | 0:151ae20d098f | 62 | |
giovannivisentini | 0:151ae20d098f | 63 | //write the tag |
giovannivisentini | 0:151ae20d098f | 64 | if(tag.write(msg)){ |
giovannivisentini | 0:151ae20d098f | 65 | pc.printf("Tag writed \n\r"); |
giovannivisentini | 0:151ae20d098f | 66 | nfcNucleo->getLed2()=1; |
giovannivisentini | 0:151ae20d098f | 67 | } |
giovannivisentini | 0:151ae20d098f | 68 | |
giovannivisentini | 0:151ae20d098f | 69 | |
giovannivisentini | 0:151ae20d098f | 70 | //close the i2c session |
giovannivisentini | 0:151ae20d098f | 71 | if(!tag.closeSession()){ |
giovannivisentini | 0:151ae20d098f | 72 | pc.printf("Error Closing the session\n\r"); |
giovannivisentini | 0:151ae20d098f | 73 | }else |
giovannivisentini | 0:151ae20d098f | 74 | nfcNucleo->getLed3()=1; |
giovannivisentini | 0:151ae20d098f | 75 | }else |
giovannivisentini | 0:151ae20d098f | 76 | pc.printf("Error open Session\n\r"); |
giovannivisentini | 0:151ae20d098f | 77 | } |