Example application for the X-Nucleo-NFC01A1 Dynamic NFC Tag board.
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of HelloWorld_NFC01A1 by
X-NUCLEO-NFC01A1 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-NFC01A1 Dynamic NFC Tag Expansion Board based on M24SR.
Example Application
This is just a simple "hello world" style program for the X-NUCLEO-NFC01A1 Dynamic NFC Tag Expansion Board. The program writes a URI link to the M24SR dynamic tag using the synchronous programming model. The URI can then be retrieved from an NFC enabled smartphone/tablet.
A more complex example providing asynchronous access to the tag is also available.
Diff: main.cpp
- Revision:
- 20:3a6e6ae2d691
- Parent:
- 17:22e6c00f3a4c
- Child:
- 23:05ef41b77f9b
diff -r 2e9835fbd14f -r 3a6e6ae2d691 main.cpp --- a/main.cpp Fri Sep 30 12:38:35 2016 +0000 +++ b/main.cpp Fri Apr 28 12:15:16 2017 +0000 @@ -2,8 +2,8 @@ ****************************************************************************** * @file main.cpp * @author ST Central Labs - * @version V1.0.0 - * @date 21 Dic 2015 + * @version V2.0.0 + * @date 28 Apr 2017 * @brief This demo writes an ndef message with an url inside. ****************************************************************************** * @attention @@ -37,7 +37,7 @@ #include "mbed.h" -#include "X_NUCLEO_NFC01A1.h" +#include "XNucleoNFC01A1.h" #include "NDefLib/NDefNfcTag.h" #include "NDefLib/RecordType/RecordURI.h" @@ -46,32 +46,32 @@ * Write an NDef message with a Uri record linking the st.com site * @param nfcNucleo expansion board where write the NDef message */ -static void writeUrl(X_NUCLEO_NFC01A1 *nfcNucleo){ +static void write_url(XNucleoNFC01A1 *nfcNucleo){ //retrieve the NdefLib interface - NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag(); + NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag(); //open the i2c session with the nfc chip - if(tag.openSession()){ + if(tag.open_session()){ printf("Session opened\n\r"); - nfcNucleo->getLed1()=1; + nfcNucleo->get_led1()=1; //create the NDef message and record NDefLib::Message msg; NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com"); - msg.addRecord(&rUri); + msg.add_record(&rUri); //write the tag if(tag.write(msg)){ printf("Tag written\n\r"); - nfcNucleo->getLed2()=1; + nfcNucleo->get_led2()=1; }else{ printf("Error writing \n\r"); }//if-else //close the i2c session - if(tag.closeSession()){ + if(tag.close_session()){ printf("Session closed\n\r"); - nfcNucleo->getLed3()=1; + nfcNucleo->get_led3()=1; }else{ printf("Error closing the session\n\r"); }//if-else @@ -85,40 +85,40 @@ * the message * @param nfcNucleo expansion board from where read the message */ -static void readUrl(X_NUCLEO_NFC01A1 *nfcNucleo){ +static void read_url(XNucleoNFC01A1 *nfcNucleo){ //retrieve the NdefLib interface - NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag(); + NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag(); //open the i2c session with the nfc chip - if(tag.openSession()){ + if(tag.open_session()){ printf("Session opened\n\r"); - nfcNucleo->getLed1()=1; + nfcNucleo->get_led1()=1; //create the NDef message and record NDefLib::Message msg; //read the tag if(tag.read(&msg)){ - const uint32_t nRecords = msg.getNRecords(); - printf("Tag read: %d record\n\r",msg.getNRecords()); + const uint32_t nRecords = msg.get_N_records(); + printf("Tag read: %d record\n\r",msg.get_N_records()); for(int i =0 ;i<nRecords ;i++){ - if(msg[i]->getType()== NDefLib::Record::TYPE_URI){ + if(msg[i]->get_type()== NDefLib::Record::TYPE_URI){ NDefLib::RecordURI *rUri = (NDefLib::RecordURI *)msg[i]; printf("UriType: %x\n\rUriContent: %s\n\r", - rUri->getUriId(), - rUri->getContent().c_str()); + rUri->get_uri_id(), + rUri->get_content().c_str()); }//if }//for //free the read records - NDefLib::Message::removeAndDeleteAllRecord(msg); + NDefLib::Message::remove_and_delete_all_record(msg); }else{ printf("Error Reading \n\r"); }//if-else //close the i2c session - if(tag.closeSession()){ + if(tag.close_session()){ printf("Session closed\n\r"); - nfcNucleo->getLed3()=1; + nfcNucleo->get_led3()=1; }else{ printf("Error closing the session\n\r"); }//if-else @@ -129,7 +129,7 @@ static volatile bool buttonPress=false; -static void setButtonPress(){ +static void set_button_press(){ buttonPress=true; }//if buttonPress @@ -141,30 +141,30 @@ int main(void){ //use default board pinout - I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN); - X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,NULL, - X_NUCLEO_NFC01A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC01A1::DEFAULT_RF_DISABLE_PIN, - X_NUCLEO_NFC01A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC01A1::DEFAULT_LED2_PIN, - X_NUCLEO_NFC01A1::DEFAULT_LED3_PIN); + I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN); + XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel,NULL, + XNucleoNFC01A1::DEFAULT_GPO_PIN,XNucleoNFC01A1::DEFAULT_RF_DISABLE_PIN, + XNucleoNFC01A1::DEFAULT_LED1_PIN,XNucleoNFC01A1::DEFAULT_LED2_PIN, + XNucleoNFC01A1::DEFAULT_LED3_PIN); printf("System Init done: !\n\r"); // write an URI message - writeUrl(nfcNucleo); + write_url(nfcNucleo); //if run on a nucleo board enable the user button for read the ndef record #if defined(TARGET_STM) InterruptIn userButton(USER_BUTTON); - userButton.fall(setButtonPress); + userButton.fall(set_button_press); while(true){ if(buttonPress){ - readUrl(nfcNucleo); + read_url(nfcNucleo); buttonPress=false; }//if //wait next event __WFE(); }//while #else - readUrl(nfcNucleo); + read_url(nfcNucleo); #endif }