M2M im2ag M2PGI
Dependencies: mbed X_NUCLEO_NFC01A1 NDefLib
main.cpp
- Committer:
- hellmak
- Date:
- 2016-03-15
- Revision:
- 4:47b9a09a74bf
- Parent:
- 2:7183a6189b65
- Child:
- 5:b75a06d210fd
File content as of revision 4:47b9a09a74bf:
#include "mbed.h" #include "X_NUCLEO_NFC01A1.h" #include "NDefLib/NDefNfcTag.h" #include "NDefLib/Message.h" #include "NDefLib/RecordType/RecordURI.h" Serial pc(SERIAL_TX, SERIAL_RX); DigitalOut myled(LED1); /** * Write a Ndef URI message linking to st.com site. */ void init(){ pc.baud(115200); pc.format(8,SerialBase::None, 1); } int main(void){ init(); pc.printf("System Init now !\n"); myled = 0; // LED is OFF //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); nfcNucleo->getLed1()=0; //retrieve the NdefLib interface NDefLib::NDefNfcTag& tag =nfcNucleo->getM24SR().getNDefTag(); printf("System Init done: !\n"); //open the i2c session with the nfc chip if(tag.openSession()){ printf("Session opened\n"); nfcNucleo->getLed1()=1; //create the NDef message and record NDefLib::Message msg; NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com"); msg.addRecord(&rUri); //write the tag if(tag.write(msg)){ printf("Tag written\n"); nfcNucleo->getLed2()=1; }else{ printf("Error writing \n"); }//if-else NDefLib::Message message; while(!tag.read(&message)){ } while(!tag.read(&message)){ } uint8_t buffer[64]; buffer[0]=0; buffer[1]=3; message.write(buffer); buffer[63]=0; for(int i=0; i< 63; i++){ printf("%c",buffer[i]); } printf("\n"); //close the i2c session if(tag.closeSession()){ myled = 1; // LED is ON printf("Session closed\n"); nfcNucleo->getLed3()=1; }else{ printf("Error closing the session\n"); }//if-else }else printf("Error opening the session\n"); }