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 .
Revision 15:94c98d2aa235, committed 2016-08-31
- Comitter:
- giovannivisentini
- Date:
- Wed Aug 31 13:58:17 2016 +0000
- Parent:
- 14:3b604972b89f
- Child:
- 16:02611ca49f48
- Commit message:
- add printf to the demos
Changed in this revision
--- a/Samples/SampleAsync_countClick.cpp Wed Aug 31 13:06:13 2016 +0000
+++ b/Samples/SampleAsync_countClick.cpp Wed Aug 31 13:58:17 2016 +0000
@@ -91,7 +91,7 @@
private:
void onError(){
- printf("Error updating the tag\n\r");
+ printf("Error updating the tag\r\n");
mCommandFinish=false;
}
@@ -102,6 +102,7 @@
if(!success)
return onError();
mNfcNucleo->getLed1()=!mNfcNucleo->getLed1();
+ printf("Session opened\r\n");
tag->write(mMsg);
}
@@ -113,6 +114,7 @@
if(!success)
return onError();
mNfcNucleo->getLed2()=!mNfcNucleo->getLed2();
+ printf("Tag wrote\r\n");
if(mRequestRefresh){
mRequestRefresh=false;
tag->write(mMsg);
@@ -129,6 +131,7 @@
if(!success)
return onError();
mNfcNucleo->getLed3()=!mNfcNucleo->getLed3();
+ printf("Session Close\r\n");
if(mRequestRefresh){
mRequestRefresh=false;
tag->openSession();
@@ -187,6 +190,7 @@
buttonPress=false;
//change the record content
rClickCount.incrementClick();
+ printf("upgade Ndef message\r\n");
writeMyRecordCallback.updateMessage();
}//if
if(nfcEvent){
--- a/Samples/SampleAsync_writeAndChangeAll.cpp Wed Aug 31 13:06:13 2016 +0000
+++ b/Samples/SampleAsync_writeAndChangeAll.cpp Wed Aug 31 13:58:17 2016 +0000
@@ -138,7 +138,7 @@
break;}
case Record::TYPE_URI:{
RecordURI *temp = (RecordURI*)r;
- temp->setContent("google.it");
+ temp->setContent("mbed.com");
break;}
case Record::TYPE_URI_MAIL:{
RecordMail *temp = (RecordMail*)r;
@@ -210,6 +210,7 @@
delete mMsg;
return onFinish("Error Reading\r\n");
}else{
+ printf("Message Read\r\n\n");
for(uint32_t i=0;i<readMsg->getNRecords();i++){
NDefLib::Record *r = (*readMsg)[i];
printRecord(r);
@@ -289,7 +290,9 @@
printf("Error Reading\r\n");
deleteMessage();
}else{
+ printf("Message Read: change message content\r\n");
changeContent(readMsg);
+ printf("Start write new message\r\n");
tag->write(*mMsg);
}//if-else
}
@@ -300,9 +303,10 @@
virtual void onMessageWrite(NDefLib::NDefNfcTag *tag,bool success,
const NDefLib::Message &){
deleteMessage();
- if(success)
+ if(success){
+ printf("Message Wrote\r\n");
tag->closeSession();
- else
+ }else
printf("Error Writing\r\n");
}//onMessageWrite
@@ -345,6 +349,8 @@
return;
}//else
+ printf("Session open\r\n");
+
//create the message
NDefLib::Message msg;
@@ -403,6 +409,7 @@
if(!success)
printf("Error Writing\r\n");
+ printf("Message wrote\r\n");
tag->closeSession();
}
@@ -421,7 +428,7 @@
};
-static volatile bool buttonPress=false; /// true when the user press the message
+static bool buttonPress=false; /// true when the user press the message
/**
* Call back called when the user press the button
--- a/Samples/SampleSync_countClick.cpp Wed Aug 31 13:06:13 2016 +0000
+++ b/Samples/SampleSync_countClick.cpp Wed Aug 31 13:58:17 2016 +0000
@@ -48,16 +48,21 @@
NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
//open the i2c session with the nfc chip
if(tag.openSession()){
+ printf("Session opened\r\n");
+
nfcNucleo->getLed1()=! nfcNucleo->getLed1();
//write the tag
if(tag.write(msg)){
+ printf("message wriote\r\n");
nfcNucleo->getLed2()=!nfcNucleo->getLed2();
}//if
//close the i2c session
- if(tag.closeSession())
+ if(tag.closeSession()){
+ printf("Session closed\r\n");
nfcNucleo->getLed3()=!nfcNucleo->getLed3();
+ }
}//if open session
}//writeMessage
@@ -88,6 +93,8 @@
//InterruptIn userButton(SW1);
userButton.fall(setButtonPress);
+ printf("Init Done\r\n");
+
//create the NDef message and record
NDefLib::Message msg;
MyRecord rClickCount;
@@ -95,6 +102,7 @@
writeMessage(nfcNucleo,msg);
+ printf("Start Main Loop\r\n");
while(true){
if(buttonPress){
--- a/Samples/SampleSync_lockWriteTag.cpp Wed Aug 31 13:06:13 2016 +0000
+++ b/Samples/SampleSync_lockWriteTag.cpp Wed Aug 31 13:58:17 2016 +0000
@@ -71,6 +71,7 @@
bool enableReadOnly( X_NUCLEO_NFC01A1 *nfcNucleo){
if(nfcNucleo->getM24SR().EnableReadOnly(M24SR::DEFAULT_PASSWORD)){
+ printf("Enable Read Only\r\n");
getReadOnlyLed(nfcNucleo)=true;
getWriteableLed(nfcNucleo)=false;
return true;
@@ -87,6 +88,7 @@
bool disableReadOnly( X_NUCLEO_NFC01A1 *nfcNucleo){
if(nfcNucleo->getM24SR().DisableReadOnly(M24SR::DEFAULT_PASSWORD)){
+ printf("Disable Read Only\r\n");
getReadOnlyLed(nfcNucleo)=false;
getWriteableLed(nfcNucleo)=true;
return true;
@@ -107,7 +109,9 @@
//when the user press the button set buttonPress to true
InterruptIn userButton(USER_BUTTON);
userButton.fall(setButtonPress);
-
+
+ printf("Init Done\r\n");
+
//restore the board as read/write
tag.openSession(true);
nfcNucleo->getM24SR().DisableAllPassword(M24SR::DEFAULT_PASSWORD);
@@ -115,7 +119,9 @@
getReadOnlyLed(nfcNucleo)=false;
getWriteableLed(nfcNucleo)=true;
bool tagIsLock=false;
-
+
+ printf("All Protection removed\r\n");
+
nfcNucleo->getLed1()=true;
while(true){
@@ -123,7 +129,7 @@
if(tag.openSession()){
bool changeStatusResult;
- if(tagIsLock)
+ if(!tagIsLock)
changeStatusResult=enableReadOnly(nfcNucleo);
else
changeStatusResult=disableReadOnly(nfcNucleo);
--- a/Samples/SampleSync_writeAndChangeAll.cpp Wed Aug 31 13:06:13 2016 +0000
+++ b/Samples/SampleSync_writeAndChangeAll.cpp Wed Aug 31 13:58:17 2016 +0000
@@ -65,10 +65,11 @@
* Create a message that contains all the possible records, and write it in the tag.
* @param tag Nfc tag where write the message.
*/
-static void setNFCTag(NDefLib::NDefNfcTag &tag){
+static void writeNFCTag(NDefLib::NDefNfcTag &tag){
bool writeStatus,closeStatus;
if(tag.openSession()){
+ printf("Open session\r\n");
NDefLib::Message msg;
NDefLib::RecordAAR rAAR("com.st.BlueMS");
@@ -121,14 +122,14 @@
printf("Error open Session\n\r");
if(writeStatus)
- printf("writeOk\n\r");
+ printf("Write Done\n\r");
else
- printf("writeFail\n\r");
+ printf("Write Fail\n\r");
if(closeStatus)
- printf("closeOk\n\r");
+ printf("Close Done\n\r");
else
- printf("CloseFail\n\r");
+ printf("Close Fail\n\r");
}
/**
@@ -241,14 +242,16 @@
* Read the nfc message and print the content on the serial console
* @param tag Nfc tag where read the content
*/
-static void readNfcTag(NDefLib::NDefNfcTag &tag){
+static void readAndPrintNfcTag(NDefLib::NDefNfcTag &tag){
using namespace NDefLib;
if(tag.openSession()){
+ 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{
@@ -260,6 +263,7 @@
}//if-else
tag.closeSession();
+ printf("Close session\r\n");
}else{
printf("Error open read Session\n\r");
}
@@ -269,15 +273,17 @@
* Read a nfc message, change the content of each record and write the new message.
* @param tag Tag where read and write the nfc message.
*/
-static void changeNfcTag(NDefLib::NDefNfcTag &tag){
+static void readAndChangeNfcTag(NDefLib::NDefNfcTag &tag){
using NDefLib::Record;
using NDefLib::Message;
if(tag.openSession()){
+ printf("Open Session\r\n");
Message readMsg;
tag.read(&readMsg);
-
+ printf("Read Message\r\n");
+
if(readMsg.getNRecords()==0){
printf("Error Read\r\n");
}else{
@@ -286,9 +292,11 @@
changeRecord(r);
}//for
tag.write(readMsg);
+ printf("Message Wrote\r\n");
}//if-else
tag.closeSession();
+ printf("Close Session\r\n");
}else{
printf("Error open SessionChange\n\r");
}
@@ -307,11 +315,9 @@
* Write a message and when the user press the button it read the message, change it and update it.
*/
void sampleSync_writeAndChangeAll() {
- DigitalOut nucleoLed(LED1);
//instance the board with the default paramiters
I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- //i2cChannel.frequency(400000);
X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
//retrieve the NdefLib interface
NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
@@ -320,11 +326,13 @@
nfcNucleo->getLed1()=1;
nfcNucleo->getLed2()=0;
nfcNucleo->getLed3()=0;
+
+ printf("Init Done\r\n");
//write the message
- setNFCTag(tag);
+ writeNFCTag(tag);
//read the message and write it on console
- readNfcTag(tag);
+ readAndPrintNfcTag(tag);
//enable the button
InterruptIn mybutton(USER_BUTTON);
@@ -332,17 +340,13 @@
mybutton.fall(setButtonPress);
//each second change the led status and see if the user press the button
- while(true) {
- wait(1);
- //update the status
- nucleoLed = !nucleoLed;
- shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
-
+ while(true) {
if(buttonPress){
//update the message content
- changeNfcTag(tag);
+ readAndChangeNfcTag(tag);
//write the new message on console
- readNfcTag(tag);
+ readAndPrintNfcTag(tag);
+ shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
buttonPress=false;
}
}
--- a/Samples/SampleSync_writeUrl.cpp Wed Aug 31 13:06:13 2016 +0000
+++ b/Samples/SampleSync_writeUrl.cpp Wed Aug 31 13:58:17 2016 +0000
@@ -48,7 +48,7 @@
//retrieve the NdefLib interface
NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
- printf("System Init done: !\n\r");
+ printf("System Init done: !\r\n");
//open the i2c session with the nfc chip
if(tag.openSession()){
nfcNucleo->getLed1()=1;
@@ -60,16 +60,16 @@
//write the tag
if(tag.write(msg)){
- printf("Tag writed \n\r");
+ printf("Tag writed \r\n");
nfcNucleo->getLed2()=1;
}
//close the i2c session
if(!tag.closeSession()){
- printf("Error Closing the session\n\r");
+ printf("Error Closing the session\r\n");
}else
nfcNucleo->getLed3()=1;
}else
- printf("Error open Session\n\r");
+ printf("Error open Session\r\n");
}
--- a/Samples/sampleAsync_lockWriteTag.cpp Wed Aug 31 13:06:13 2016 +0000
+++ b/Samples/sampleAsync_lockWriteTag.cpp Wed Aug 31 13:58:17 2016 +0000
@@ -86,14 +86,15 @@
if(status!=NFC_SUCCESS)
return onError(status);
mIsComamndRunning=true;
-
+ printf("Session Opened\r\n");
tag->SelectApplication();
}
virtual void onSelectedApplication(Nfc *tag,NFC_StatusTypeDef status){
if(status!=NFC_SUCCESS)
return onError(status);
-
+
+ printf("Select application\r\n");
tag->SelectNDEFfile(0x0001);
}
@@ -101,19 +102,23 @@
if(status!=NFC_SUCCESS)
return onError(status);
+ printf("Select NDef\r\n");
tag->DisableAllPassword(M24SR::DEFAULT_PASSWORD);
}
virtual void onDisableAllPassword(Nfc *tag, NFC_StatusTypeDef status){
if(status!=NFC_SUCCESS)
return onError(status);
-
+
+ printf("Disable all Password\r\n");
tag->Deselect();
}
virtual void onDeselect(Nfc *,NFC_StatusTypeDef status){
if(status!=NFC_SUCCESS)
return onError(status);
+
+ printf("Close Application\r\n");
mIsComamndRunning=false;
}
@@ -173,19 +178,22 @@
virtual void onSessionOpen(Nfc *,NFC_StatusTypeDef status){
if(status!=NFC_SUCCESS)
return onError(status);
+ printf("Session Open\r\n");
mNfcTag.SelectApplication();
}
virtual void onSelectedApplication(Nfc *,NFC_StatusTypeDef status){
if(status!=NFC_SUCCESS)
return onError(status);
+
+ printf("Select Application\r\n");
mNfcTag.SelectNDEFfile(0x0001);
}
virtual void onSelectedNDEFFile(Nfc *,NFC_StatusTypeDef status){
if(status!=NFC_SUCCESS)
return onError(status);
-
+ printf("Select NDef file\r\n");
if(mIsReadOnly){
mNfcTag.EnableReadOnly(M24SR::DEFAULT_PASSWORD);
}else
@@ -196,7 +204,7 @@
virtual void onEnableReadOnly(Nfc *,NFC_StatusTypeDef status){
if(status!=NFC_SUCCESS)
return onError(status);
-
+ printf("Ready only Enabled\r\n");
if(!mIsReadOnly) //if in the meantime the status change
mNfcTag.DisableReadOnly(M24SR::DEFAULT_PASSWORD);
else{
@@ -209,7 +217,7 @@
virtual void onDisableReadOnly(Nfc *,NFC_StatusTypeDef status){
if(status!=NFC_SUCCESS)
return onError(status);
-
+ printf("Ready only Disabled\r\n");
if(mIsReadOnly) //if in the meantime the status change
mNfcTag.EnableReadOnly(M24SR::DEFAULT_PASSWORD);
else{
@@ -222,6 +230,7 @@
virtual void onDeselect(Nfc *,NFC_StatusTypeDef status){
if(status!=NFC_SUCCESS)
return onError(status);
+ printf("Close Application\r\n");
mIsComamndRunning=false;
}
};
--- a/mbed.bld Wed Aug 31 13:06:13 2016 +0000 +++ b/mbed.bld Wed Aug 31 13:58:17 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/2241e3a39974 \ No newline at end of file
