Complete mbed library/workspace for HelloWorld_NFC02A1
Dependencies: NDefLib X_NUCLEO_NFC02A1 mbed
Fork of HelloWorld_NFC02A1 by
X-NUCLEO-NFC02A1 Dynamic NFC Tag Expansion Board Firmware Package
Introduction
This firmware package includes Components Device Drivers, Board Support Package and example applications for STMicroelectronics X-NUCLEO-NFC02A1 Dynamic NFC Tag Expansion Board based on M24LR.
Example Application
This is just a simple "hello world" style program for the X-NUCLEO-NFC02A1 Dynamic NFC Tag Expansion Board. The program writes a URI link to the M24LR dynamic tag using the synchronous programming model. It then reads back the URI from the tag to display it on terminal. The URI can also be retrieved from an NFC enabled smartphone/tablet.
Diff: main.cpp
- Revision:
- 8:9bdd16ebccfb
- Parent:
- 7:699836375630
- Child:
- 9:0bd2f0c13d3d
diff -r 699836375630 -r 9bdd16ebccfb main.cpp --- a/main.cpp Thu Sep 29 05:48:44 2016 +0000 +++ b/main.cpp Fri Sep 30 11:46:24 2016 +0000 @@ -42,9 +42,54 @@ #include "m24lr.h" #include "NDefLib/NDefNfcTag.h" #include "NDefLib/RecordType/RecordURI.h" + +#if 0 +/*----------------------------------------------------------------------------*/ +static volatile bool buttonPress=false; // true when the user press the message + +static void setButtonPress(){ + buttonPress=true; +}//if buttonPress + + static void readAndPrintNfcTag(NDefLib::NDefNfcTag &tag){ + using namespace NDefLib; + + if(tag.openSession() == true){ + printf("Open Session\r\n"); + NDefLib::Message readMsg; + + tag.read(&readMsg); + printf("Message Read\r\n"); + + if(readMsg.getNRecords()==0){ + printf("Error Read\r\n"); + }else{ + for(uint32_t i=0;i<readMsg.getNRecords();i++){ + Record *r = readMsg[i]; + // printRecord(r); + //----- + RecordURI *const temp = (RecordURI*)r; + printf("Read uriId: %d\r\n",temp->getUriId()); + printf("Read uriType: %s\r\n",temp->getUriType().c_str()); + printf("Read uriContent: %s\r\n",temp->getContent().c_str()); + //------ + delete r; + }//for + }//if-else + + tag.closeSession(); + printf("Close session\r\n"); + }else{ + printf("Error open read Session\n\r"); + } +} +/*----------------------------------------------------------------------------*/ +#endif + /** * Write a Ndef URI message linking to st.com site. */ + int main(void) { @@ -64,7 +109,7 @@ printf("System Initialization done: !\n\r"); /*open the i2c session with the nfc chip*/ - if(tag.openSession() == NFC_SUCCESS) + if(tag.openSession() == true) { printf("Session opened\n\r"); nfcNucleo->getLed1()=1; @@ -75,16 +120,19 @@ msg.addRecord(&rUri); /*write the tag*/ - if(tag.write(msg) == NDEF_OK){ + if(tag.write(msg) == true) + { printf("Tag written\n\r"); nfcNucleo->getLed2()=1; - }else{ + } + else + { printf("Error writing \n\r"); nfcNucleo->getLed1()=0; }//if-else /*close the i2c session*/ - if(tag.closeSession() == NFC_SUCCESS) + if(tag.closeSession() == true) { printf("Session closed\n\r"); nfcNucleo->getLed3()=1; @@ -97,9 +145,30 @@ } else printf("Error opening the session\n\r"); + +#if 0 +/*----------------------------------------------------------------------------*/ + /* enable the button */ + InterruptIn mybutton(USER_BUTTON); + + mybutton.fall(setButtonPress); + + /*each second change the led status and see if the user press the button*/ + while(1) + { + if(buttonPress) + { + /*write the read message on console*/ + readAndPrintNfcTag(tag); + buttonPress=false; + } + } +/*----------------------------------------------------------------------------*/ +#endif + } + /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ -