Demo NFC
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of HelloWorld_NFC01A1 by
main.cpp
00001 #include "mbed.h" 00002 00003 #include "X_NUCLEO_NFC01A1.h" 00004 #include "NDefLib/NDefNfcTag.h" 00005 #include "NDefLib/RecordType/RecordURI.h" 00006 #include "NDefLib/RecordType/RecordText.h" 00007 00008 00009 int updateM24SR(X_NUCLEO_NFC01A1* nfcNucleo, char* data){ 00010 00011 //retrieve the NdefLib interface 00012 NDefLib::NDefNfcTag& tag =nfcNucleo->getM24SR().getNDefTag(); 00013 printf("System Init done: !\n\r"); 00014 /*SESSION 1*/ 00015 //open the i2c session with the nfc chip 00016 if(tag.openSession()){ 00017 printf("Session opened\n\r"); 00018 nfcNucleo->getLed1()=1; 00019 00020 //create the NDef message and record 00021 NDefLib::Message msg; 00022 NDefLib::RecordText rText(data); 00023 msg.addRecord(&rText); 00024 00025 //write the tag 00026 if(tag.write(msg)){ 00027 printf("Tag written\n\r"); 00028 nfcNucleo->getLed2()=1; 00029 00030 }else{ 00031 printf("Error writing \n\r"); 00032 }//if-else 00033 00034 //close the i2c session 00035 if(tag.closeSession()){ 00036 printf("Session closed\n\r"); 00037 nfcNucleo->getLed3()=1; 00038 }else{ 00039 printf("Error closing the session\n\r"); 00040 }//if-else 00041 00042 }else 00043 printf("Error opening the session\n\r"); 00044 } 00045 00046 int main(void){ 00047 00048 //use default board pinout 00049 I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN); 00050 X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,NULL, 00051 X_NUCLEO_NFC01A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC01A1::DEFAULT_RF_DISABLE_PIN, 00052 X_NUCLEO_NFC01A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC01A1::DEFAULT_LED2_PIN, 00053 X_NUCLEO_NFC01A1::DEFAULT_LED3_PIN); 00054 00055 //retrieve the NdefLib interface 00056 NDefLib::NDefNfcTag& tag =nfcNucleo->getM24SR().getNDefTag(); 00057 printf("System Init done: !\n\r"); 00058 00059 updateM24SR(nfcNucleo,"CIAO ANITA"); 00060 00061 }
Generated on Wed Jul 13 2022 16:30:55 by
1.7.2
