This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of X-MBED-NFC1 by
This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.
The available demos are:
- SAMPLE_WRITE_URL: write a tag with the ST home page URL
- SAMPLE_COUNT_CLICK: create a custom tag to count and report the user button clicks.
- SAMPLE_WRITE_AND_CHANGE_ALL: write a tag with all the supported records and update the tag contents when the user button is pressed.
- SAMPLE_LOCK_TAG_CONTENT: use the M24SR component API to set the NFC tag as read-only.
To enable the different demos comment/uncomment the SAMPLE_* macros provided in main.cpp .
Diff: main.cpp
- Revision:
- 0:674813bd5ec9
- Child:
- 1:6d202b62ed68
diff -r 000000000000 -r 674813bd5ec9 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Nov 19 08:50:18 2015 +0000
@@ -0,0 +1,137 @@
+#include <cstring>
+#include "mbed.h"
+
+#include "m24sr/m24sr_class.h"
+//#include "lib_NDEF/lib_TagType4.h"
+
+#include "Type4NfcTagSTM24SR.h"
+
+#include "NDefLib/RecordType/RecordAAR.h"
+#include "NDefLib/RecordType/RecordSMS.h"
+#include "NDefLib/RecordType/RecordGeo.h"
+#include "NDefLib/RecordType/RecordUri.h"
+#include "NDefLib/RecordType/RecordMail.h"
+#include "NDefLib/RecordType/RecordText.h"
+#include "NDefLib/RecordType/RecordMimeType.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+
+Serial pc(SERIAL_TX, SERIAL_RX);
+
+DigitalOut myled(LED1);
+
+void shiftLed(DigitalOut &led1,DigitalOut &led2,DigitalOut &led3){
+ const uint8_t prevLed1=led1;
+ const uint8_t prevLed2=led2;
+ const uint8_t prevLed3=led3;
+ led1=prevLed3;
+ led2=prevLed1;
+ led3=prevLed2;
+}
+
+
+static const PinName M24SR_SDA=D14;
+static const PinName M24SR_SDL=D15;
+
+static const uint32_t MAX_WRITE_TRY=5;
+
+I2C i2cChannel(M24SR_SDA,M24SR_SDL);
+M24SR *m24srDrv;
+
+void setNFCTag(){
+
+ Type4NfcTagSTM24SR tag(*m24srDrv);
+ bool writeStatus,closeStatus;
+ if(tag.openSession()){
+ NDefLib::Message msg;
+
+ NDefLib::RecordAAR rAAR("com.st.BlueMS");
+ msg.addRecord(&rAAR);
+
+ NDefLib::RecordSMS rSMS("123456789","st.com.BlueMS");
+ msg.addRecord(&rSMS);
+
+ NDefLib::RecordGeo rGeo("123.123","456.789");
+ msg.addRecord(&rGeo);
+
+ NDefLib::RecordUri rUri(NDefLib::RecordUri::HTTP_WWW,"http://www.st.com");
+ msg.addRecord(&rUri);
+
+ NDefLib::RecordMail rMail("mail@st.com","ciao","da nfc tag");
+ msg.addRecord(&rMail);
+
+ NDefLib::RecordMimeType rText1("text/plain",(const uint8_t*)"ciao",4);
+ msg.addRecord(&rText1);
+
+ NDefLib::RecordText rText2("ciao");
+ msg.addRecord(&rText2);
+
+ NDefLib::RecordText rText3(NDefLib::RecordText::UTF8,"it","ciao");
+ msg.addRecord(&rText3);
+
+ uint32_t writeTry=0;
+ do{
+ writeStatus = tag.write(msg);
+ writeTry++;
+ }while(!writeStatus && writeTry<MAX_WRITE_TRY);
+
+ closeStatus = tag.closeSession();
+
+ }else
+ pc.printf("Error open Session\n\r");
+
+ if(writeStatus)
+ pc.printf("writeOk\n\r");
+ else
+ pc.printf("writeFail\n\r");
+
+ if(closeStatus)
+ pc.printf("closeOk\n\r");
+ else
+ pc.printf("CloseFail\n\r");
+
+/*
+ sURI_Info URI;
+ sAARInfo aar;
+ sSMSInfo sms;
+ std::strcpy(sms.PhoneNumber,"123456789\0");
+ std::strcpy(sms.Message,"st.com.BlueMS\0");
+ std::strcpy(sms.Information,"\0");
+
+ std::strcpy(aar.PakageName,"st.com.BlueMS");
+
+ // Prepare URI NDEF message content
+ std::strcpy(URI.protocol,URI_ID_0x01_STRING);
+ std::strcpy(URI.URI_Message,"st3.com");
+ std::strcpy(URI.Information,"\0");
+
+
+ while (TT4_Init() != NFC_OK);
+ // Prepare URI NDEF message content
+ std::strcpy(URI.protocol,URI_ID_0x01_STRING);
+ std::strcpy(URI.URI_Message,"st2.com");
+ std::strcpy(URI.Information,"\0");
+ //while (TT4_WriteURI(&URI) != NFC_OK);
+ while (TT4_WriteSMS(&sms) != NFC_OK);
+ //while (TT4_Write(&sms) != NFC_OK);
+*/
+}
+
+int main() {
+ i2cChannel.frequency(400000);
+ X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
+ m24srDrv=&nfcNucleo->getM24SR();
+
+ pc.printf("Hello World !\n");
+ nfcNucleo->getLed1()=1;
+ nfcNucleo->getLed2()=0;
+ nfcNucleo->getLed3()=0;
+
+ setNFCTag();
+ while(1) {
+ wait(1);
+ myled = !myled;
+ shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
+ }
+}
+
