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 Giovanni Visentini

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 .

Files at this revision

API Documentation at this revision

Comitter:
giovannivisentini
Date:
Mon Feb 01 15:33:26 2016 +0000
Parent:
12:c4a778f52d8a
Child:
14:3b604972b89f
Commit message:
add sync and async demos

Changed in this revision

NDefLib.lib Show annotated file Show diff for this revision Revisions of this file
Samples/MyRecord.h Show annotated file Show diff for this revision Revisions of this file
Samples/SampleAsync_countClick.cpp Show annotated file Show diff for this revision Revisions of this file
Samples/SampleAsync_writeAndChangeAll.cpp Show annotated file Show diff for this revision Revisions of this file
Samples/SampleAsync_writeUrl.cpp Show annotated file Show diff for this revision Revisions of this file
Samples/SampleSync_countClick.cpp Show annotated file Show diff for this revision Revisions of this file
Samples/SampleSync_lockWriteTag.cpp Show annotated file Show diff for this revision Revisions of this file
Samples/SampleSync_writeAndChangeAll.cpp Show annotated file Show diff for this revision Revisions of this file
Samples/SampleSync_writeUrl.cpp Show annotated file Show diff for this revision Revisions of this file
Samples/Sample_countClick.cpp Show diff for this revision Revisions of this file
Samples/Sample_writeAndChangeAll.cpp Show diff for this revision Revisions of this file
Samples/Sample_writeUrl.cpp Show diff for this revision Revisions of this file
Samples/Samples.h Show annotated file Show diff for this revision Revisions of this file
Samples/sampleAsync_lockWriteTag.cpp Show annotated file Show diff for this revision Revisions of this file
Samples/sample_lockWriteTag.cpp Show diff for this revision Revisions of this file
X_NUCLEO_NFC01A1.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/NDefLib.lib	Thu Jan 14 09:17:03 2016 +0000
+++ b/NDefLib.lib	Mon Feb 01 15:33:26 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/giovannivisentini/code/NDefLib/#ed4d9b8d1410
+http://developer.mbed.org/users/giovannivisentini/code/NDefLib/#01fc5a4b8366
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/MyRecord.h	Mon Feb 01 15:33:26 2016 +0000
@@ -0,0 +1,69 @@
+/**
+  ******************************************************************************
+  * @file       MyRecord.cpp
+  * @author     ST / Central Labs
+  * @date       03 Dic 2015
+  * @brief      Simple castom record used in the countClick demo
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+
+#include "NDefLib/RecordType/RecordText.h"
+
+/**
+ * Custom record that map an integer in a text record.
+ */
+class MyRecord : public NDefLib::RecordText{
+    
+private:
+    char nClickStringBuffer[12]; ///buffer used for print the number
+    uint32_t nClick; /// number to show
+    
+    /**
+     * Convert the number in char and update the tag content.
+     */
+    void syncTextValue(){
+        sprintf(nClickStringBuffer,"%d",nClick);
+        setText(nClickStringBuffer);
+    }
+        
+public: 
+    
+    MyRecord():nClick(0){
+        syncTextValue();
+    }
+    
+    /**
+     * Increment the stored number and update the racord content.
+     */
+    void incrementClick(){
+        nClick++;
+        syncTextValue();
+    }
+
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/SampleAsync_countClick.cpp	Mon Feb 01 15:33:26 2016 +0000
@@ -0,0 +1,201 @@
+/**
+  ******************************************************************************
+  * @file       Sample_countClick.cpp
+  * @author     ST / Central Labs
+  * @date       03 Dic 2015
+  * @brief      This demo define a custom record that contains the number of time the user
+  *             press the user button
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+  
+#include "mbed.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+#include "NDefLib/NDefNfcTag.h"
+
+#include "MyRecord.h"
+
+/**
+ * class with the callback needed to update the record in the tag
+ */
+class WriteMyRecordCallback : public NDefLib::NDefNfcTag::Callback {
+
+	/**
+	 * board where change the led status
+	 */
+	X_NUCLEO_NFC01A1 *mNfcNucleo;
+
+	/**
+	 * message to write
+	 */
+	NDefLib::Message &mMsg;
+
+	/**
+	 * true if the message is wrote in the tag
+	 */
+	bool mCommandFinish;
+
+	/**
+	 * true if an update request is done while writing a tag
+	 */
+	bool mRequestRefresh;
+
+
+	public:
+
+		/**
+		 * build an object write an message into a nfc tag
+		 * @param nfcNucleo board with the leds and nfc tag
+		 * @param msg message to write
+		 */
+		WriteMyRecordCallback(X_NUCLEO_NFC01A1 *nfcNucleo,NDefLib::Message &msg):
+			mNfcNucleo(nfcNucleo),mMsg(msg),mCommandFinish(true),
+			mRequestRefresh(false){}
+
+		/**
+		 * start the write process
+		 */
+		void updateMessage(){
+			if(mCommandFinish){
+				mNfcNucleo->getM24SR().getNDefTag().openSession();
+			}else// if it is doing something remember this request
+				mRequestRefresh=true;
+		}//updateMessage
+
+	private:
+
+		void onError(){
+			printf("Error updating the tag\n\r");
+			mCommandFinish=false;
+		}
+
+		/**
+		 * when the session is open change the led status and ask to write the message
+		 */
+		virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+			if(!success)
+				return onError();
+			mNfcNucleo->getLed1()=!mNfcNucleo->getLed1();
+			tag->write(mMsg);
+		}
+
+		/**
+		 * if the user ask for update the value it write again the message, otherwise close the session
+		 */
+		virtual void onMessageWrite(NDefLib::NDefNfcTag *tag,bool success,
+				const NDefLib::Message&){
+			if(!success)
+				return onError();
+			mNfcNucleo->getLed2()=!mNfcNucleo->getLed2();
+			if(mRequestRefresh){
+				mRequestRefresh=false;
+				tag->write(mMsg);
+			}else
+				tag->closeSession();
+			//if-else
+
+		};
+
+		/**
+		 * if the user ask for update the value it open a new session
+		 */
+		virtual void onSessionClose(NDefLib::NDefNfcTag *tag,bool success){
+			if(!success)
+				return onError();
+			mNfcNucleo->getLed3()=!mNfcNucleo->getLed3();
+			if(mRequestRefresh){
+				mRequestRefresh=false;
+				tag->openSession();
+			}else
+				mCommandFinish=true;
+			//if-else
+		};
+
+};
+
+
+static volatile bool buttonPress=false; /// true when the user press the message
+static volatile bool nfcEvent=false; /// true when the user press the message
+
+/**
+ * Call back called when the user press the button.
+ */
+static void setButtonPress(){
+    buttonPress=true;
+}//if buttonPress
+
+static void setNfcEventCallback(){
+	nfcEvent=true;
+}//if buttonPress
+
+/**
+ * Write a custom record that count how many times the user press the button.
+ */
+void sampleAsync_countClick() {
+    
+    //instance the board with the default parameters
+    I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+    X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,&setNfcEventCallback);
+
+    //set the button interrupt
+    InterruptIn userButton(USER_BUTTON);    
+    //InterruptIn userButton(SW1);    
+    userButton.fall(setButtonPress);
+    
+	//No call back needed since default behavior is sync
+	//nfcNucleo->getM24SR().GetSession();
+	//nfcNucleo->getM24SR().ManageI2CGPO(I2C_ANSWER_READY); //switch to async mode
+
+    //create the NDef message and record
+    NDefLib::Message msg;
+    MyRecord rClickCount;
+    msg.addRecord(&rClickCount);
+    
+    WriteMyRecordCallback writeMyRecordCallback(nfcNucleo,msg);
+
+    nfcNucleo->getM24SR().getNDefTag().setCallback(&writeMyRecordCallback);
+    writeMyRecordCallback.updateMessage();
+    while(true){
+        
+        if(buttonPress){
+        	buttonPress=false;
+            //change the record content
+            rClickCount.incrementClick();
+            writeMyRecordCallback.updateMessage();
+        }//if
+        if(nfcEvent){
+        	nfcEvent=false;
+        	nfcNucleo->getM24SR().ManageEvent();
+        }//if
+        //wait next event
+        __WFE();
+    }//while
+
+}//sample_countClick
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/SampleAsync_writeAndChangeAll.cpp	Mon Feb 01 15:33:26 2016 +0000
@@ -0,0 +1,490 @@
+/**
+  ******************************************************************************
+  * @file       Sample_writeAndChangeAll.cpp
+  * @author     ST / Central Labs
+  * @date       03 Dic 2015
+  * @brief      This demo write an ndef message different records, when the user press the buttun
+  *             read the tag, change some data and write it again
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+  
+#include "mbed.h"
+
+#include "NDefLib/NDefNfcTag.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 "NDefLib/RecordType/RecordVCard.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+
+/**
+ * Shift the led status between the 3 leds.
+ */
+static 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;
+}
+
+/**
+ * Print in the console some data about the record.
+ * @param r Record to print.
+ */
+static void printRecord(NDefLib::Record *const r){
+    using namespace NDefLib;
+    switch(r->getType()){
+        case Record::TYPE_TEXT: {
+            const RecordText *const temp = ( RecordText* )r;
+            printf("Read Text: %s\r\n",temp->getText().c_str());
+            break; }
+        case Record::TYPE_AAR:{
+            const RecordAAR *const temp = ( RecordAAR* )r;
+            printf("Read ARR: %s\r\n",temp->getPackage().c_str());
+            break; }
+        case Record::TYPE_MIME:{
+            const RecordMimeType *const temp = ( RecordMimeType* )r;
+            printf("Read mimeType: %s\r\n",temp->getMimeType().c_str());
+            printf("Read mimeData: %s\r\n",
+                    std::string((const char*)temp->getMimeData(),
+                            temp->getMimeDataLenght()).c_str());
+            break;}
+        case Record::TYPE_URI:{
+            RecordURI *const temp = (RecordURI*)r;
+            printf("Read uriId: %d\r\n",temp->getUriId());
+            printf("Read uriType: %s\r\n",temp->getUriType().c_str());
+            printf("Read uriContent: %s\r\n",temp->getContent().c_str());
+            break;}
+        case Record::TYPE_URI_MAIL:{
+            const RecordMail*const temp = (RecordMail*)r;
+            printf("Read Dest: %s\r\n",temp->getToAddress().c_str());
+            printf("Read Subject: %s\r\n",temp->getSubject().c_str());
+            printf("Read Body: %s\r\n",temp->getBody().c_str());
+            break;}
+        case Record::TYPE_URI_SMS:{
+            const RecordSMS*const temp = (RecordSMS*)r;
+            printf("Read number: %s\r\n",temp->getNumber().c_str());
+            printf("Read message: %s\r\n",temp->getMessagge().c_str());
+            break;}
+        case Record::TYPE_URI_GEOLOCATION:{
+            const RecordGeo*const temp = (RecordGeo*)r;
+            printf("Read lat: %f\r\n",temp->getLatitude());
+            printf("Read long: %f\r\n",temp->getLongitude());
+            break;}
+        case Record::TYPE_MIME_VCARD:{
+            const RecordVCard *const temp = (RecordVCard*)r;
+            printf("Read Name: %s\r\n",(*temp)[RecordVCard::NAME].c_str());
+            printf("Read Mail: %s\r\n",(*temp)[RecordVCard::EMAIL_WORK].c_str());
+            printf("Read ORG: %s\r\n",(*temp)[RecordVCard::ORGANIZATION].c_str());
+            break;}
+        case Record::TYPE_UNKNOWN:{
+            printf("Unknown record\r\n");
+            break;}
+    }//switch
+}//printRecord
+
+/**
+ * Change the record content.
+ * @param r Record to change.
+ */
+static void changeRecord(NDefLib::Record const* r){
+    using namespace NDefLib;
+    switch(r->getType()){
+        case Record::TYPE_TEXT: {
+            RecordText *temp = (RecordText*)r;
+            temp->setText("CIAOCiao");
+            break; }
+        case Record::TYPE_AAR:{
+            RecordAAR *temp = (RecordAAR*)r;
+            temp->setPackage("set Package Ok");
+            break; }
+        case Record::TYPE_MIME:{
+            RecordMimeType *temp = (RecordMimeType*)r;
+            temp->copyMimeData((const uint8_t *)"String2",sizeof("String2"));
+            break;}
+        case Record::TYPE_URI:{
+            RecordURI *temp = (RecordURI*)r;
+            temp->setContent("google.it");
+            break;}
+        case Record::TYPE_URI_MAIL:{
+            RecordMail *temp = (RecordMail*)r;
+            temp->setToAddress("newMail@st.com");
+            temp->setSubject("tag change");
+            temp->setBody("read/change Works!");
+            break;}
+        case Record::TYPE_URI_SMS:{
+            RecordSMS *temp = (RecordSMS*)r;
+            temp->setMessage("Message Change");
+            temp->setNumber("0987654321");
+            break;}
+        case Record::TYPE_URI_GEOLOCATION:{
+            RecordGeo *temp = (RecordGeo*)r;
+            temp->setLatitude(-temp->getLatitude());
+            temp->setLongitude(-temp->getLongitude());
+            break;}
+        case Record::TYPE_MIME_VCARD:{
+            RecordVCard *temp = (RecordVCard*)r;
+            (*temp)[RecordVCard::NAME]="name change";
+            (*temp)[RecordVCard::NICKNAME]="nic change";
+            break;}
+        case Record::TYPE_UNKNOWN:{
+            printf("Unknown record\r\n");
+            break;}
+    }//switch
+}//changeRecord
+
+
+/**
+ * Class that print read a message and print it on console,
+ * and enable the user button when it finish
+ */
+class ReadMessageCallback : public NDefLib::NDefNfcTag::Callback{
+
+	NDefLib::Message *mMsg; /// Message where read
+	bool *mDisableButton; /// enable the user button
+
+	void onFinish(char *msg){
+		printf(msg);
+		*mDisableButton=false;
+	}
+
+public:
+	/**
+	 *
+	 * @param disableEnable set to false when the read finish
+	 */
+	ReadMessageCallback(bool *disableEnable):mMsg(NULL),
+		mDisableButton(disableEnable){}
+
+	/**
+	 * Create the message and ask to read it
+	 */
+	virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+		if(!success){
+			return onFinish("Error Opening Session\r\n");
+		}//if
+		mMsg = new NDefLib::Message;
+		tag->read(mMsg);
+	}
+
+	/**
+	 * Print all the record inside the message
+	 */
+	virtual void onMessageRead(NDefLib::NDefNfcTag *tag,bool success,
+			const NDefLib::Message *readMsg){
+		if(!success || readMsg->getNRecords()==0){
+			delete mMsg;
+			return onFinish("Error Reading\r\n");
+		}else{
+			for(uint32_t i=0;i<readMsg->getNRecords();i++){
+				NDefLib::Record *r = (*readMsg)[i];
+				printRecord(r);
+				delete r;
+			}//for
+			delete mMsg;
+		}//if-else
+		tag->closeSession();
+	}
+
+	/**
+	 * Enable the button
+	 */
+	virtual void onSessionClose(NDefLib::NDefNfcTag *,bool success){
+		if(success)
+			onFinish("Read Session close\r\n");
+		else
+			onFinish("Read Session close Error\r\n");
+	}
+
+};
+
+/**
+ * Read the message, change some data and write it back
+ */
+class ChangeMessageCallback : public NDefLib::NDefNfcTag::Callback{
+
+	ReadMessageCallback* mReadMessage;
+	NDefLib::Message *mMsg;
+
+	/**
+	 * Change all the record in the message.
+	 * @param readMsg Message to change.
+	 */
+	static void changeContent(const NDefLib::Message *readMsg){
+		for(uint32_t i=0;i<readMsg->getNRecords();i++){
+			changeRecord((*readMsg)[i]);
+		}//for
+	}//changeContent
+
+	/**
+	 * Delete all the record and the message.
+	 */
+	void deleteMessage(){
+		for(uint32_t i=0;i<mMsg->getNRecords();i++){
+			delete (*mMsg)[i];
+		}//for
+		delete mMsg;
+	}//deleteMessage
+
+public:
+
+	/**
+	 * @param readCallback Callback needed for print the tag content after the change
+	 */
+	ChangeMessageCallback(ReadMessageCallback* readCallback):
+		mReadMessage(readCallback),mMsg(NULL){}
+
+	/**
+	 * Ask to read the tag content
+	 */
+	virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+		if(!success){
+			printf("Error Opening the session");
+			return;
+		}//else
+		mMsg = new NDefLib::Message;
+		tag->read(mMsg);
+	}
+
+	/**
+	 * Change the message content and write it back
+	 */
+	virtual void onMessageRead(NDefLib::NDefNfcTag *tag,bool success,
+			const NDefLib::Message *readMsg){
+		if(!success || readMsg->getNRecords()==0){
+			printf("Error Reading\r\n");
+			deleteMessage();
+		}else{
+			changeContent(readMsg);
+			tag->write(*mMsg);
+		}//if-else
+	}
+
+	/**
+	 * Delete the Message and close the session
+	 */
+	virtual void onMessageWrite(NDefLib::NDefNfcTag *tag,bool success,
+							const NDefLib::Message &){
+		deleteMessage();
+		if(success)
+			tag->closeSession();
+		else
+			printf("Error Writing\r\n");
+	}//onMessageWrite
+
+	/**
+	 * Set the callback for print the tag content and open a new session
+	 */
+	virtual void onSessionClose(NDefLib::NDefNfcTag *tag,bool success){
+		if(success){
+			printf("Change Session close\r\n");
+			tag->setCallback(mReadMessage);
+			tag->openSession();
+		}else
+			printf("Change Session close Error\r\n");
+	}
+
+};
+
+/**
+ * Create and write a message in a nfc tag
+ */
+class WriteMessageCallback : public NDefLib::NDefNfcTag::Callback{
+
+	ReadMessageCallback* mReadMessage;
+
+public:
+
+	/**
+	 *
+	 * @param readCallback Callbacks to use for print the tag content
+	 */
+	WriteMessageCallback(ReadMessageCallback* readCallback):
+		mReadMessage(readCallback){}
+
+	/**
+	 *
+	 */
+	virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+		if(!success){
+			printf("Error Opening the Session\r\n");
+			return;
+		}//else
+
+		//create the message
+		 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 rText3(NDefLib::RecordText::UTF8,"it","ciao");
+		msg.addRecord(&rText3);
+
+		NDefLib::RecordVCard::VCardInfo_t cardInfo;
+		cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="prova prova1";
+		cardInfo[NDefLib::RecordVCard::ADDRESS_HOME]=";;1 Main St.;Springfield;IL;12345;USA";
+		cardInfo[NDefLib::RecordVCard::ADDRESS_WORK]=";;2 Main St.;Springfield;IL;12345;USA";
+		cardInfo[NDefLib::RecordVCard::EMAIL_WORK]="workmail@st.com";
+		cardInfo[NDefLib::RecordVCard::EMAIL_HOME]="homemail@st.com";
+		cardInfo[NDefLib::RecordVCard::GEO]="39.95;-75.1667";
+		cardInfo[NDefLib::RecordVCard::IMPP]="aim:johndoe@aol.com";
+		cardInfo[NDefLib::RecordVCard::NAME]="prova2;prova3";
+		cardInfo[NDefLib::RecordVCard::NICKNAME]="test";
+		cardInfo[NDefLib::RecordVCard::NOTE]="A good test";
+		cardInfo[NDefLib::RecordVCard::ORGANIZATION]="STM";
+		cardInfo[NDefLib::RecordVCard::TEL_HOME]="123";
+		cardInfo[NDefLib::RecordVCard::TEL_MOBILE]="456";
+		cardInfo[NDefLib::RecordVCard::TEL_WORK]="789";
+		cardInfo[NDefLib::RecordVCard::TITLE]="King";
+		cardInfo[NDefLib::RecordVCard::URL]="www.st.com";
+		cardInfo[NDefLib::RecordVCard::PHOTO_URI]="http://www.st.com/st-web-ui/static/active/en/fragment/multimedia/image/picture/customer_focus.jpg";
+		NDefLib::RecordVCard rVCard(cardInfo);
+		msg.addRecord(&rVCard);
+
+		//write it
+		tag->write(msg);
+	}
+
+
+	/**
+	 * Close the session
+	 */
+	virtual void onMessageWrite(NDefLib::NDefNfcTag *tag,bool success,
+						const NDefLib::Message &){
+		if(!success)
+			printf("Error Writing\r\n");
+
+		tag->closeSession();
+	}
+
+	/**
+	 * Set the callback for print the tag content and open a new session
+	 */
+	virtual void onSessionClose(NDefLib::NDefNfcTag *tag,bool success){
+		if(success){
+			printf("Write Session close\r\n");
+			tag->setCallback(mReadMessage);
+			tag->openSession();
+		}else
+			printf("Write Session close Error\r\n");
+	}//onSessionClose
+
+};
+
+
+static bool buttonPress=false; /// true when the user press the message
+
+/**
+ * Call back called when the user press the button
+ */
+static void setButtonPress(){
+    buttonPress=true;
+}//if buttonPress
+
+static bool nfcEvent=false; /// true if there is an nfc interrupt
+
+/**
+ * Call back called when the user press the button
+ */
+static void setNfcEvent(){
+	nfcEvent=true;
+}//if buttonPress
+
+/**
+ * Write a message and when the user press the button it read the message, change it and update it.
+ */
+void sampleAsync_writeAndChangeAll() {
+    DigitalOut nucleoLed(LED1);
+    
+    //instance the board with the default parameters
+    I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+    X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,&setNfcEvent);
+
+    //retrieve the Nfc component
+    M24SR &nfc = nfcNucleo->getM24SR();
+    //retrieve the NdefLib interface
+    NDefLib::NDefNfcTag& tag = nfc.getNDefTag();
+
+    //switch on the first led    
+    nfcNucleo->getLed1()=1;
+    nfcNucleo->getLed2()=0;
+    nfcNucleo->getLed3()=0;
+
+    ReadMessageCallback readMessageCallback(&buttonPress);
+    WriteMessageCallback writeBigMessageCallback(&readMessageCallback);
+    ChangeMessageCallback changeMessageCallback(&readMessageCallback);
+
+    //Enable async mode
+    if(nfcNucleo->getM24SR().GetSession()!=NFC_SUCCESS)
+        	nfcNucleo->getM24SR().ManageI2CGPO(I2C_ANSWER_READY);
+
+    //write the message
+    tag.setCallback(&writeBigMessageCallback);
+    tag.openSession();
+
+    //enable the button
+    InterruptIn mybutton(USER_BUTTON);
+    mybutton.fall(setButtonPress);
+
+    while(true) {
+        if(buttonPress){
+        	shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
+        	tag.setCallback(&changeMessageCallback);
+        	tag.openSession();
+        }else if (nfcEvent){
+        	nucleoLed=!nucleoLed;
+        	nfcNucleo->getM24SR().ManageEvent();
+        }//if-else
+        __WFE();
+    }//while
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/SampleAsync_writeUrl.cpp	Mon Feb 01 15:33:26 2016 +0000
@@ -0,0 +1,158 @@
+/**
+  ******************************************************************************
+  * @file       Sample_writeUrl.cpp
+  * @author     ST / Central Labs
+  * @date       03 Dic 2015
+  * @brief      This demo write an ndef message with an url inside
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+  
+#include "mbed.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+#include "NDefLib/NDefNfcTag.h"
+#include "NDefLib/RecordType/RecordURI.h"
+
+/**
+ * Chain of callback that will crate a Uri record and write it.
+ * After each operation the class will switch on a led
+ */
+class WriteUriCallbacks : public NDefLib::NDefNfcTag::Callback{
+
+	DigitalOut &mOnOpenSession;
+	DigitalOut &mOnWrite;
+	DigitalOut &mOnCloseSession;
+
+public:
+
+	/**
+	 * create the callback chain
+	 * @param onOpenSession led to switch on when the session open
+	 * @param onWrite led to switch on when the write end
+	 * @param onCloseSession led to switch on when the session end
+	 */
+	WriteUriCallbacks(DigitalOut &onOpenSession,DigitalOut &onWrite,
+			DigitalOut &onCloseSession):mOnOpenSession(onOpenSession),
+					mOnWrite(onWrite),mOnCloseSession(onCloseSession){};
+
+	/**
+	 * crate the new message and write it
+	 * @param tag tag where write the message
+	 * @param success true if the session correctly open
+	 */
+	virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+		if(!success){
+			printf("Error OpenSession\n\r");
+		}//else
+		printf("Session Open\n\r");
+		//ask to have an interrupt when the command finish
+		mOnOpenSession=1;
+		NDefLib::Message msg;
+
+		NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
+		msg.addRecord(&rUri);
+
+		tag->write(msg);
+	}
+
+	/**
+	 * request to close the session
+	 * @param tag tag where close the session
+	 * @param success true if the message is correctly wrote
+	 * @param message wrote
+	 */
+	virtual void onMessageWrite(NDefLib::NDefNfcTag *tag,bool success,
+			const NDefLib::Message&){
+
+		if(!success)
+			printf("Error writing tag!\n\r");
+		else{
+			printf("Tag Wrote!\n\r");
+			mOnWrite=1;
+		}//if-else
+		tag->closeSession();
+	}
+
+	/**
+	 * switch on the led
+	 * @param tag where the session is closed
+	 * @param success true if the session is correctly close
+	 */
+	virtual void onSessionClose(NDefLib::NDefNfcTag*,bool success){
+		if(success){
+			printf("Session closed\n\r");
+			mOnCloseSession=1;
+		}else
+			printf("Error Session closed\n\r");
+	}
+
+};
+
+
+/** variable set to true when we receive an interrupt from the nfc component*/
+static bool nfcInterruptFlag;
+
+/** Nfc ISR called when the nfc component has a message ready*/
+static void nfcInterruptCallback(){
+	nfcInterruptFlag=true;
+}//nfcInterruptCallback
+
+void sampleAsync_writeUrl(){
+	//create the nfc component
+	I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+	X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,&nfcInterruptCallback,
+			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);
+
+	//No call back needed since default behavior is sync
+	nfcNucleo->getM24SR().GetSession();
+	nfcNucleo->getM24SR().ManageI2CGPO(I2C_ANSWER_READY); //switch to async mode
+
+	NDefLib::NDefNfcTag &tag = nfcNucleo->getM24SR().getNDefTag();
+	printf("System Init done!\n\r");
+
+	//crate the callback to use for write a tag
+	WriteUriCallbacks NDefCallback(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
+	tag.setCallback(&NDefCallback); //set the callback
+	tag.openSession(); //start the callback chain
+
+	printf("Start Main Loop\n\r");
+	while(true){
+		if(nfcInterruptFlag){
+			nfcInterruptFlag=false;
+			//manage an async event from the nfc component
+			nfcNucleo->getM24SR().ManageEvent();
+
+		}//if
+		__WFE();
+	}//while
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/SampleSync_countClick.cpp	Mon Feb 01 15:33:26 2016 +0000
@@ -0,0 +1,112 @@
+/**
+  ******************************************************************************
+  * @file       Sample_countClick.cpp
+  * @author     ST / Central Labs
+  * @date       03 Dic 2015
+  * @brief      This demo define a custom record that contains the number of time the user
+  *             press the user button
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+  
+#include "mbed.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+#include "NDefLib/NDefNfcTag.h"
+#include "MyRecord.h"
+
+/* Write a nfc message into a tag
+ * @param nfcNucleo Board where write the data.
+ * @param msg Message to write.
+ */
+static void writeMessage(X_NUCLEO_NFC01A1 *nfcNucleo,NDefLib::Message &msg){
+    NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
+    //open the i2c session with the nfc chip
+    if(tag.openSession()){
+        nfcNucleo->getLed1()=! nfcNucleo->getLed1();
+        
+        //write the tag
+        if(tag.write(msg)){
+            nfcNucleo->getLed2()=!nfcNucleo->getLed2();
+        }//if
+
+        //close the i2c session
+        if(tag.closeSession())
+            nfcNucleo->getLed3()=!nfcNucleo->getLed3();
+    }//if open session
+}//writeMessage
+
+
+static volatile bool buttonPress=false; /// true when the user press the message
+
+/**
+ * Call back called when the user press the button.
+ */
+static void setButtonPress(){
+    buttonPress=true;
+}//if buttonPress
+
+/**
+ * Write a castum record that count how many times the user press the button.
+ */
+void sampleSync_countClick() {
+    
+    //instance the board with the default paramiters
+    I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+    X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
+    
+    //retrieve the NdefLib interface
+    NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
+    
+    //set the button interrupt
+    InterruptIn userButton(USER_BUTTON);    
+    //InterruptIn userButton(SW1);    
+    userButton.fall(setButtonPress);
+    
+    //create the NDef message and record
+    NDefLib::Message msg;
+    MyRecord rClickCount;
+    msg.addRecord(&rClickCount);
+    
+    writeMessage(nfcNucleo,msg);
+    
+    while(true){
+        
+        if(buttonPress){
+            //change the record content
+            rClickCount.incrementClick();
+            //write the new record content
+            writeMessage(nfcNucleo,msg);  
+            //wait a new button press          
+            buttonPress=false;
+        }//if
+        //wait next event
+        __WFE();
+    }//while
+
+}//sample_countClick
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/SampleSync_lockWriteTag.cpp	Mon Feb 01 15:33:26 2016 +0000
@@ -0,0 +1,270 @@
+/**
+  ******************************************************************************
+  * @file       Sample_lockWriteTag.cpp
+  * @author     ST / Central Labs
+  * @date       03 Dic 2015
+  * @brief      This demo define a lock/unlock the tag content when the user press
+  *  the user button
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+
+#include "mbed.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+
+static bool buttonPress=false; /// true when the user press the message
+static bool nfcEvent=false; /// true when the user press the message
+
+static void setNfcEventCallback(){
+	nfcEvent=true;
+}//if buttonPress
+/**
+ * Call back called when the user press the button.
+ */
+static void setButtonPress(){
+    buttonPress=true;
+}//if buttonPress
+
+/**
+ * Class with the command chain needed for remove all the read/write password
+ */
+class RemoveAllPasswordStatusCallback : public Nfc::Callback {
+
+public:
+
+	RemoveAllPasswordStatusCallback():mIsComamndRunning(false){}
+
+	/**
+	 * true when the command chain finish, and the the tag can now be read and write
+	 * @return true if the command chain finish
+	 */
+	bool isFinish(){
+		return !mIsComamndRunning;
+	}
+
+
+private:
+	bool mIsComamndRunning; /// false when the command chain finish
+
+	/**
+	 * end the command chain and print an error message
+	 * @param status error code of the last command
+	 */
+	void onError(const NFC_StatusTypeDef status){
+		mIsComamndRunning=false;
+		printf("Error Code: %X \r\n",status);
+	}
+
+	virtual void onSessionOpen(Nfc *tag,NFC_StatusTypeDef status){
+		if(status!=NFC_SUCCESS)
+			return onError(status);
+		mIsComamndRunning=true;
+
+		tag->SelectApplication();
+	}
+
+	virtual void onSelectedApplication(Nfc *tag,NFC_StatusTypeDef status){
+		if(status!=NFC_SUCCESS)
+			return onError(status);
+
+		tag->SelectNDEFfile(0x0001);
+	}
+
+	virtual void onSelectedNDEFFile(Nfc *tag,NFC_StatusTypeDef status){
+		if(status!=NFC_SUCCESS)
+			return onError(status);
+
+		tag->DisableAllPassword(M24SR::DEFAULT_PASSWORD);
+	}
+
+	virtual void onDisableAllPassword(Nfc *tag, NFC_StatusTypeDef status){
+		if(status!=NFC_SUCCESS)
+			return onError(status);
+
+		tag->Deselect();
+	}
+
+	virtual void onDeselect(Nfc *,NFC_StatusTypeDef status){
+		if(status!=NFC_SUCCESS)
+			return onError(status);
+		mIsComamndRunning=false;
+	}
+
+};
+
+/**
+ * Chain of call needed for change the tag status between read only and write/read
+ */
+class ChangeTagStatusCallback : public Nfc::Callback {
+
+	M24SR &mNfcTag; /// object to change
+	DigitalOut& mReadOnlyLed; /// led to switch on when it is in read only mode
+	DigitalOut& mReadWriteWriteLed; /// led to switch on when is in read/write mode
+
+	bool mIsReadOnly; /// current tag status
+	bool mIsComamndRunning; /// true if the chain is running
+
+	public:
+
+		/**
+		 * Build a chain of callback needed for change the tag status.
+		 * @param nfcTag Tag to change.
+		 * @param readLed Led to switch on when in read only mode.
+		 * @param writeLed Led to switch on when in read/write mode.
+		 */
+		ChangeTagStatusCallback(M24SR &nfcTag, DigitalOut& readLed, DigitalOut& writeLed):
+			mNfcTag(nfcTag),mReadOnlyLed(readLed),mReadWriteWriteLed(writeLed),mIsReadOnly(false),
+			mIsComamndRunning(false){
+			mReadOnlyLed=false;
+			mReadWriteWriteLed=true;
+		}
+
+		/**
+		 * Change the tag status
+		 */
+		void changeStatus(){
+			mIsReadOnly=!mIsReadOnly;
+			//if it is not running a previous command
+			if(!mIsComamndRunning){
+				mNfcTag.GetSession();
+			}//if
+		}//changeStatus;
+
+	private:
+
+		/**
+		 * When an error happen switch on both the led and print the error code.
+		 * @param status Error code.
+		 */
+		void onError(const NFC_StatusTypeDef status){
+			mIsComamndRunning=false;
+			mReadOnlyLed=true;
+			mReadWriteWriteLed=true;
+			printf("Error %X changing the status\r\n",status);
+		}
+
+		virtual void onSessionOpen(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+			mNfcTag.SelectApplication();
+		}
+
+		virtual void onSelectedApplication(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+			mNfcTag.SelectNDEFfile(0x0001);
+		}
+
+		virtual void onSelectedNDEFFile(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+
+			if(mIsReadOnly){
+				mNfcTag.EnableReadOnly(M24SR::DEFAULT_PASSWORD);
+			}else
+				mNfcTag.DisableReadOnly(M24SR::DEFAULT_PASSWORD);
+		}
+
+
+		virtual void onEnableReadOnly(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+
+			if(!mIsReadOnly) //if in the meantime the status change
+				mNfcTag.DisableReadOnly(M24SR::DEFAULT_PASSWORD);
+			else{
+				mReadOnlyLed=true;
+				mReadWriteWriteLed=false;
+				mNfcTag.Deselect();
+			}
+		}
+
+		virtual void onDisableReadOnly(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+
+			if(mIsReadOnly) //if in the meantime the status change
+				mNfcTag.EnableReadOnly(M24SR::DEFAULT_PASSWORD);
+			else{
+				mReadOnlyLed=false;
+				mReadWriteWriteLed=true;
+				mNfcTag.Deselect();
+			}
+		}
+
+		virtual void onDeselect(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+			mIsComamndRunning=false;
+		}
+};
+
+/**
+ * When the user press the button enable/disable the tag write protection.
+ */
+void sample_lockTagContent() {
+
+    //instance the board with the default parameters
+    I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+    X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,&setNfcEventCallback);
+	
+    //when the user press the button set buttonPress to true
+    InterruptIn userButton(USER_BUTTON);
+    userButton.fall(setButtonPress);
+    
+    M24SR &nfcTag =nfcNucleo->getM24SR();
+
+    //set async mode
+    if(nfcTag.GetSession()!=NFC_SUCCESS)
+    	nfcTag.ManageI2CGPO(I2C_ANSWER_READY);
+
+
+    ChangeTagStatusCallback changeTagStatus(nfcTag,nfcNucleo->getLed2(),nfcNucleo->getLed3());
+    RemoveAllPasswordStatusCallback removeAllPasswordStatusCallback;
+
+    nfcTag.SetCallback(&removeAllPasswordStatusCallback);
+    nfcTag.GetSession();
+    nfcNucleo->getLed1()=true;
+
+    while(true){
+
+        if(buttonPress && removeAllPasswordStatusCallback.isFinish()){
+        	buttonPress=false;
+            nfcTag.SetCallback(&changeTagStatus);
+        	changeTagStatus.changeStatus();
+        }//if
+        if(nfcEvent){
+        	nfcEvent=false;
+        	nfcTag.ManageEvent();
+        }
+        //wait next event
+        __WFE();
+    }//while
+
+}//sample_countClick
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/SampleSync_writeAndChangeAll.cpp	Mon Feb 01 15:33:26 2016 +0000
@@ -0,0 +1,350 @@
+/**
+  ******************************************************************************
+  * @file       Sample_writeAndChangeAll.cpp
+  * @author     ST / Central Labs
+  * @date       03 Dic 2015
+  * @brief      This demo write an ndef message different records, when the user press the buttun
+  *             read the tag, change some data and write it again
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+  
+#include "mbed.h"
+
+#include "NDefLib/NDefNfcTag.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 "NDefLib/RecordType/RecordVCard.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+
+/**
+ * Shift the led status between the 3 leds.
+ */
+static 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;
+}
+
+/**
+ * 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){
+
+    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 rText3(NDefLib::RecordText::UTF8,"it","ciao");
+        msg.addRecord(&rText3);
+
+        NDefLib::RecordVCard::VCardInfo_t cardInfo;
+        cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="prova prova1";
+        cardInfo[NDefLib::RecordVCard::ADDRESS_HOME]=";;1 Main St.;Springfield;IL;12345;USA";
+        cardInfo[NDefLib::RecordVCard::ADDRESS_WORK]=";;2 Main St.;Springfield;IL;12345;USA";
+        cardInfo[NDefLib::RecordVCard::EMAIL_WORK]="workmail@st.com";
+        cardInfo[NDefLib::RecordVCard::EMAIL_HOME]="homemail@st.com";
+        cardInfo[NDefLib::RecordVCard::GEO]="39.95;-75.1667";
+        cardInfo[NDefLib::RecordVCard::IMPP]="aim:johndoe@aol.com";
+        cardInfo[NDefLib::RecordVCard::NAME]="prova2;prova3";
+        cardInfo[NDefLib::RecordVCard::NICKNAME]="test";
+        cardInfo[NDefLib::RecordVCard::NOTE]="A good test";
+        cardInfo[NDefLib::RecordVCard::ORGANIZATION]="STM";
+        cardInfo[NDefLib::RecordVCard::TEL_HOME]="123";
+        cardInfo[NDefLib::RecordVCard::TEL_MOBILE]="456";
+        cardInfo[NDefLib::RecordVCard::TEL_WORK]="789";
+        cardInfo[NDefLib::RecordVCard::TITLE]="King";
+        cardInfo[NDefLib::RecordVCard::URL]="www.st.com";
+        cardInfo[NDefLib::RecordVCard::PHOTO_URI]="http://www.st.com/st-web-ui/static/active/en/fragment/multimedia/image/picture/customer_focus.jpg";
+        NDefLib::RecordVCard rVCard(cardInfo);
+        msg.addRecord(&rVCard);
+
+        writeStatus = tag.write(msg);
+
+        closeStatus = tag.closeSession();
+
+    }else
+        printf("Error open Session\n\r");
+
+    if(writeStatus)
+        printf("writeOk\n\r");
+    else
+        printf("writeFail\n\r");
+
+    if(closeStatus)
+        printf("closeOk\n\r");
+    else
+        printf("CloseFail\n\r");
+}
+
+/**
+ * Print the record content.
+ * @param r Record to print.
+ */
+static void printRecord(NDefLib::Record *const r){
+    using namespace NDefLib;
+    switch(r->getType()){
+        case Record::TYPE_TEXT: {
+            const RecordText *const temp = ( RecordText* )r;
+            printf("Read Text: %s\r\n",temp->getText().c_str());
+            break; }
+        case Record::TYPE_AAR:{
+            const RecordAAR *const temp = ( RecordAAR* )r;
+            printf("Read ARR: %s\r\n",temp->getPackage().c_str());
+            break; }
+        case Record::TYPE_MIME:{
+            const RecordMimeType *const temp = ( RecordMimeType* )r;
+            printf("Read mimeType: %s\r\n",temp->getMimeType().c_str());
+            printf("Read mimeData: %s\r\n",
+                    std::string((const char*)temp->getMimeData(),
+                            temp->getMimeDataLenght()).c_str());
+            break;}
+        case Record::TYPE_URI:{
+            RecordURI *const temp = (RecordURI*)r;
+            printf("Read uriId: %d\r\n",temp->getUriId());
+            printf("Read uriType: %s\r\n",temp->getUriType().c_str());
+            printf("Read uriContent: %s\r\n",temp->getContent().c_str());
+            break;}
+        case Record::TYPE_URI_MAIL:{
+            const RecordMail*const temp = (RecordMail*)r;
+            printf("Read Dest: %s\r\n",temp->getToAddress().c_str());
+            printf("Read Subject: %s\r\n",temp->getSubject().c_str());
+            printf("Read Body: %s\r\n",temp->getBody().c_str());
+            break;}
+        case Record::TYPE_URI_SMS:{
+            const RecordSMS*const temp = (RecordSMS*)r;
+            printf("Read number: %s\r\n",temp->getNumber().c_str());
+            printf("Read message: %s\r\n",temp->getMessagge().c_str());
+            break;}
+        case Record::TYPE_URI_GEOLOCATION:{
+            const RecordGeo*const temp = (RecordGeo*)r;
+            printf("Read lat: %f\r\n",temp->getLatitude());
+            printf("Read long: %f\r\n",temp->getLongitude());
+            break;}
+        case Record::TYPE_MIME_VCARD:{
+            const RecordVCard *const temp = (RecordVCard*)r;
+            printf("Read Name: %s\r\n",(*temp)[RecordVCard::NAME].c_str());
+            printf("Read Mail: %s\r\n",(*temp)[RecordVCard::EMAIL_WORK].c_str());
+            printf("Read ORG: %s\r\n",(*temp)[RecordVCard::ORGANIZATION].c_str());
+            break;}
+        case Record::TYPE_UNKNOWN:{
+            printf("Unknown record\r\n");
+            break;}
+    }//switch
+}
+
+/**
+ * Change the record content.
+ * @param r Record to change.
+ */
+static void changeRecord(NDefLib::Record const* r){
+    using namespace NDefLib;
+    switch(r->getType()){
+        case Record::TYPE_TEXT: {
+            RecordText *temp = (RecordText*)r;
+            temp->setText("CIAOCiao");
+            break; }
+        case Record::TYPE_AAR:{
+            RecordAAR *temp = (RecordAAR*)r;
+            temp->setPackage("set Package Ok");
+            break; }
+        case Record::TYPE_MIME:{
+            RecordMimeType *temp = (RecordMimeType*)r;
+            temp->copyMimeData((const uint8_t *)"String2",sizeof("String2"));
+            break;}
+        case Record::TYPE_URI:{
+            RecordURI *temp = (RecordURI*)r;
+            temp->setContent("google.it");
+            break;}
+        case Record::TYPE_URI_MAIL:{
+            RecordMail *temp = (RecordMail*)r;
+            temp->setToAddress("newMail@st.com");
+            temp->setSubject("tag change");
+            temp->setBody("read/change Works!");
+            break;}
+        case Record::TYPE_URI_SMS:{
+            RecordSMS *temp = (RecordSMS*)r;
+            temp->setMessage("Message Change");
+            temp->setNumber("0987654321");
+            break;}
+        case Record::TYPE_URI_GEOLOCATION:{
+            RecordGeo *temp = (RecordGeo*)r;
+            temp->setLatitude(-temp->getLatitude());
+            temp->setLongitude(-temp->getLongitude());
+            break;}
+        case Record::TYPE_MIME_VCARD:{
+            RecordVCard *temp = (RecordVCard*)r;
+            (*temp)[RecordVCard::NAME]="name change";
+            (*temp)[RecordVCard::NICKNAME]="nic change";
+            break;}
+        case Record::TYPE_UNKNOWN:{
+            printf("Unknown record\r\n");
+            break;}
+    }//switch
+}
+
+/**
+ * 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){
+    using namespace NDefLib;
+
+    if(tag.openSession()){
+        NDefLib::Message readMsg;
+
+        tag.read(&readMsg);
+
+        if(readMsg.getNRecords()==0){
+            printf("Error Read\r\n");
+        }else{
+            for(uint32_t i=0;i<readMsg.getNRecords();i++){
+                Record *r = readMsg[i];
+                printRecord(r);
+                delete r;
+            }//for
+        }//if-else
+
+        tag.closeSession();
+    }else{
+        printf("Error open read Session\n\r");
+    }
+}
+
+/**
+ * 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){
+    using NDefLib::Record;
+    using NDefLib::Message;
+
+    if(tag.openSession()){
+        Message readMsg;
+
+        tag.read(&readMsg);
+
+        if(readMsg.getNRecords()==0){
+            printf("Error Read\r\n");
+        }else{
+            for(uint32_t i=0;i<readMsg.getNRecords();i++){
+                Record *r = readMsg[i];
+                changeRecord(r);
+            }//for
+            tag.write(readMsg);
+        }//if-else
+
+        tag.closeSession();
+    }else{
+        printf("Error open SessionChange\n\r");
+    }
+}
+
+static volatile bool buttonPress=false; /// true when the user press the message
+
+/**
+ * Call back called when the user press the button
+ */
+static void setButtonPress(){
+    buttonPress=true;
+}//if buttonPress
+
+/**
+ * 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();
+    
+    //switch on the first led    
+    nfcNucleo->getLed1()=1;
+    nfcNucleo->getLed2()=0;
+    nfcNucleo->getLed3()=0;
+
+    //write the message
+    setNFCTag(tag);
+    //read the message and write it on console
+    readNfcTag(tag);
+
+    //enable the button
+    InterruptIn mybutton(USER_BUTTON);
+    //InterruptIn mybutton(SW2);
+    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());
+        
+        if(buttonPress){
+            //update the message content
+            changeNfcTag(tag);
+            //write the new message on console
+            readNfcTag(tag);
+            buttonPress=false;
+        }
+    }
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/SampleSync_writeUrl.cpp	Mon Feb 01 15:33:26 2016 +0000
@@ -0,0 +1,75 @@
+/**
+  ******************************************************************************
+  * @file       Sample_writeUrl.cpp
+  * @author     ST / Central Labs
+  * @date       03 Dic 2015
+  * @brief      This demo write an ndef message with an url inside
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+  
+#include "mbed.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+#include "NDefLib/NDefNfcTag.h"
+#include "NDefLib/RecordType/RecordURI.h"
+
+/**
+ * Write a Ndef linking the st.com site.
+ */
+void sampleSync_writeUrl() {    
+    I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+    X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
+
+    //retrieve the NdefLib interface
+    NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
+    printf("System Init done: !\n\r");
+    //open the i2c session with the nfc chip
+    if(tag.openSession()){
+        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 writed \n\r");
+            nfcNucleo->getLed2()=1;
+        }
+
+    
+        //close the i2c session
+        if(!tag.closeSession()){
+            printf("Error Closing the session\n\r");
+        }else
+            nfcNucleo->getLed3()=1;
+    }else
+        printf("Error open Session\n\r");
+}
--- a/Samples/Sample_countClick.cpp	Thu Jan 14 09:17:03 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-/**
-  ******************************************************************************
-  * @file       Sample_countClick.cpp
-  * @author     ST / Central Labs
-  * @date       03 Dic 2015
-  * @brief      This demo define a custom record that contains the number of time the user
-  *             press the user button
-  ******************************************************************************
-  *
-  * COPYRIGHT(c) 2015 STMicroelectronics
-  *
-  * Redistribution and use in source and binary forms, with or without modification,
-  * are permitted provided that the following conditions are met:
-  *   1. Redistributions of source code must retain the above copyright notice,
-  *      this list of conditions and the following disclaimer.
-  *   2. Redistributions in binary form must reproduce the above copyright notice,
-  *      this list of conditions and the following disclaimer in the documentation
-  *      and/or other materials provided with the distribution.
-  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-  *      may be used to endorse or promote products derived from this software
-  *      without specific prior written permission.
-  *
-  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-  *
-  ******************************************************************************
-  */
-  
-#include "mbed.h"
-
-#include "X_NUCLEO_NFC01A1.h"
-#include "NDefLib/NDefNfcTag.h"
-#include "NDefLib/RecordType/RecordText.h"
-
-/**
- * Castom record that map an integer in a text record.
- */
-class MyRecord : public NDefLib::RecordText{
-    
-private:
-    char nClickStringBuffer[12]; ///buffer used for print the number
-    uint32_t nClick; /// number to show
-    
-    /**
-     * Convert the number in char and update the tag content.
-     */
-    void syncTextValue(){
-        sprintf(nClickStringBuffer,"%d",nClick);
-        setText(nClickStringBuffer);
-    }
-        
-public: 
-    
-    MyRecord():nClick(0){
-        syncTextValue();
-    }
-    
-    /**
-     * Increment the stored number and update the racord content.
-     */
-    void incrementClick(){
-        nClick++;
-        syncTextValue();
-    }
-
-};
-
-/* Write a nfc message into a tag
- * @param nfcNucleo Board where write the data.
- * @param msg Message to write.
- */
-static void writeMessage(X_NUCLEO_NFC01A1 *nfcNucleo,NDefLib::Message &msg){
-    NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
-    //open the i2c session with the nfc chip
-    if(tag.openSession()){
-        nfcNucleo->getLed1()=! nfcNucleo->getLed1();
-        
-        //write the tag
-        if(tag.write(msg)){
-            nfcNucleo->getLed2()=!nfcNucleo->getLed2();
-        }//if
-
-        //close the i2c session
-        if(tag.closeSession())
-            nfcNucleo->getLed3()=!nfcNucleo->getLed3();
-    }//if open session
-}//writeMessage
-
-
-static volatile bool buttonPress=false; /// true when the user press the message
-
-/**
- * Call back called when the user press the button.
- */
-static void setButtonPress(){
-    buttonPress=true;
-}//if buttonPress
-
-/**
- * Write a castum record that count how many times the user press the button.
- */
-void sample_countClick() {
-    
-    //instance the board with the default paramiters
-    I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
-    X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
-    
-    //retrieve the NdefLib interface
-    NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
-    
-    //set the button interrupt
-    InterruptIn userButton(USER_BUTTON);    
-    userButton.fall(setButtonPress);
-    
-    //create the NDef message and record
-    NDefLib::Message msg;
-    MyRecord rClickCount;
-    msg.addRecord(&rClickCount);
-    
-    writeMessage(nfcNucleo,msg);
-    
-    while(true){
-        
-        if(buttonPress){
-            //change the record content
-            rClickCount.incrementClick();
-            //write the new record content
-            writeMessage(nfcNucleo,msg);  
-            //wait a new button press          
-            buttonPress=false;
-        }//if
-        //wait next event
-        __WFE();
-    }//while
-
-}//sample_countClick
\ No newline at end of file
--- a/Samples/Sample_writeAndChangeAll.cpp	Thu Jan 14 09:17:03 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,352 +0,0 @@
-/**
-  ******************************************************************************
-  * @file       Sample_writeAndChangeAll.cpp
-  * @author     ST / Central Labs
-  * @date       03 Dic 2015
-  * @brief      This demo write an ndef message different records, when the user press the buttun
-  *             read the tag, change some data and write it again
-  ******************************************************************************
-  *
-  * COPYRIGHT(c) 2015 STMicroelectronics
-  *
-  * Redistribution and use in source and binary forms, with or without modification,
-  * are permitted provided that the following conditions are met:
-  *   1. Redistributions of source code must retain the above copyright notice,
-  *      this list of conditions and the following disclaimer.
-  *   2. Redistributions in binary form must reproduce the above copyright notice,
-  *      this list of conditions and the following disclaimer in the documentation
-  *      and/or other materials provided with the distribution.
-  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-  *      may be used to endorse or promote products derived from this software
-  *      without specific prior written permission.
-  *
-  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-  *
-  ******************************************************************************
-  */
-  
-#include "mbed.h"
-
-#include "NDefLib/NDefNfcTag.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 "NDefLib/RecordType/RecordVCard.h"
-
-#include "X_NUCLEO_NFC01A1.h"
-
-static Serial pc(SERIAL_TX, SERIAL_RX); ///serial console
-
-
-/**
- * Shift the led status between the 3 leds.
- */
-static 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;
-}
-
-/**
- * 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){
-
-    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 rText3(NDefLib::RecordText::UTF8,"it","ciao");
-        msg.addRecord(&rText3);
-
-        NDefLib::RecordVCard::VCardInfo_t cardInfo;
-        cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="prova prova1";
-        cardInfo[NDefLib::RecordVCard::ADDRESS_HOME]=";;1 Main St.;Springfield;IL;12345;USA";
-        cardInfo[NDefLib::RecordVCard::ADDRESS_WORK]=";;2 Main St.;Springfield;IL;12345;USA";
-        cardInfo[NDefLib::RecordVCard::EMAIL_WORK]="workmail@st.com";
-        cardInfo[NDefLib::RecordVCard::EMAIL_HOME]="homemail@st.com";
-        cardInfo[NDefLib::RecordVCard::GEO]="39.95;-75.1667";
-        cardInfo[NDefLib::RecordVCard::IMPP]="aim:johndoe@aol.com";
-        cardInfo[NDefLib::RecordVCard::NAME]="prova2;prova3";
-        cardInfo[NDefLib::RecordVCard::NICKNAME]="test";
-        cardInfo[NDefLib::RecordVCard::NOTE]="A good test";
-        cardInfo[NDefLib::RecordVCard::ORGANIZATION]="STM";
-        cardInfo[NDefLib::RecordVCard::TEL_HOME]="123";
-        cardInfo[NDefLib::RecordVCard::TEL_MOBILE]="456";
-        cardInfo[NDefLib::RecordVCard::TEL_WORK]="789";
-        cardInfo[NDefLib::RecordVCard::TITLE]="King";
-        cardInfo[NDefLib::RecordVCard::URL]="www.st.com";
-        cardInfo[NDefLib::RecordVCard::PHOTO_URI]="http://www.st.com/st-web-ui/static/active/en/fragment/multimedia/image/picture/customer_focus.jpg";
-        NDefLib::RecordVCard rVCard(cardInfo);
-        msg.addRecord(&rVCard);
-
-        writeStatus = tag.write(msg);
-
-        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");
-}
-
-/**
- * Print the record content.
- * @param r Record to print.
- */
-static void printRecord(NDefLib::Record *const r){
-    using namespace NDefLib;
-    switch(r->getType()){
-        case Record::TYPE_TEXT: {
-            const RecordText *const temp = ( RecordText* )r;
-            pc.printf("Read Text: %s\r\n",temp->getText().c_str());
-            break; }
-        case Record::TYPE_AAR:{
-            const RecordAAR *const temp = ( RecordAAR* )r;
-            pc.printf("Read ARR: %s\r\n",temp->getPackage().c_str());
-            break; }
-        case Record::TYPE_MIME:{
-            const RecordMimeType *const temp = ( RecordMimeType* )r;
-            pc.printf("Read mimeType: %s\r\n",temp->getMimeType().c_str());
-            pc.printf("Read mimeData: %s\r\n",
-                    std::string((const char*)temp->getMimeData(),
-                            temp->getMimeDataLenght()).c_str());
-            break;}
-        case Record::TYPE_URI:{
-            RecordURI *const temp = (RecordURI*)r;
-            pc.printf("Read uriId: %d\r\n",temp->getUriId());
-            pc.printf("Read uriType: %s\r\n",temp->getUriType().c_str());
-            pc.printf("Read uriContent: %s\r\n",temp->getContent().c_str());
-            break;}
-        case Record::TYPE_URI_MAIL:{
-            const RecordMail*const temp = (RecordMail*)r;
-            pc.printf("Read Dest: %s\r\n",temp->getToAddress().c_str());
-            pc.printf("Read Subject: %s\r\n",temp->getSubject().c_str());
-            pc.printf("Read Body: %s\r\n",temp->getBody().c_str());
-            break;}
-        case Record::TYPE_URI_SMS:{
-            const RecordSMS*const temp = (RecordSMS*)r;
-            pc.printf("Read number: %s\r\n",temp->getNumber().c_str());
-            pc.printf("Read message: %s\r\n",temp->getMessagge().c_str());
-            break;}
-        case Record::TYPE_URI_GEOLOCATION:{
-            const RecordGeo*const temp = (RecordGeo*)r;
-            pc.printf("Read lat: %f\r\n",temp->getLatitude());
-            pc.printf("Read long: %f\r\n",temp->getLongitude());
-            break;}
-        case Record::TYPE_MIME_VCARD:{
-            const RecordVCard *const temp = (RecordVCard*)r;
-            pc.printf("Read Name: %s\r\n",(*temp)[RecordVCard::NAME].c_str());
-            pc.printf("Read Mail: %s\r\n",(*temp)[RecordVCard::EMAIL_WORK].c_str());
-            pc.printf("Read ORG: %s\r\n",(*temp)[RecordVCard::ORGANIZATION].c_str());
-            break;}
-        case Record::TYPE_UNKNOWN:{
-            pc.printf("Unknown record\r\n");
-            break;}
-    }//switch
-}
-
-/**
- * Change the record content.
- * @param r Record to change.
- */
-static void changeRecord(NDefLib::Record const* r){
-    using namespace NDefLib;
-    switch(r->getType()){
-        case Record::TYPE_TEXT: {
-            RecordText *temp = (RecordText*)r;
-            temp->setText("CIAOCiao");
-            break; }
-        case Record::TYPE_AAR:{
-            RecordAAR *temp = (RecordAAR*)r;
-            temp->setPackage("set Package Ok");
-            break; }
-        case Record::TYPE_MIME:{
-            RecordMimeType *temp = (RecordMimeType*)r;
-            temp->copyMimeData((const uint8_t *)"String2",sizeof("String2"));
-            break;}
-        case Record::TYPE_URI:{
-            RecordURI *temp = (RecordURI*)r;
-            temp->setContent("google.it");
-            break;}
-        case Record::TYPE_URI_MAIL:{
-            RecordMail *temp = (RecordMail*)r;
-            temp->setToAddress("newMail@st.com");
-            temp->setSubject("tag change");
-            temp->setBody("read/change Works!");
-            break;}
-        case Record::TYPE_URI_SMS:{
-            RecordSMS *temp = (RecordSMS*)r;
-            temp->setMessage("Message Change");
-            temp->setNumber("0987654321");
-            break;}
-        case Record::TYPE_URI_GEOLOCATION:{
-            RecordGeo *temp = (RecordGeo*)r;
-            temp->setLatitude(-temp->getLatitude());
-            temp->setLongitude(-temp->getLongitude());
-            break;}
-        case Record::TYPE_MIME_VCARD:{
-            RecordVCard *temp = (RecordVCard*)r;
-            (*temp)[RecordVCard::NAME]="name change";
-            (*temp)[RecordVCard::NICKNAME]="nic change";
-            break;}
-        case Record::TYPE_UNKNOWN:{
-            pc.printf("Unknown record\r\n");
-            break;}
-    }//switch
-}
-
-/**
- * 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){
-    using namespace NDefLib;
-
-    if(tag.openSession()){
-        NDefLib::Message readMsg;
-
-        tag.read(&readMsg);
-
-        if(readMsg.getNRecords()==0){
-            pc.printf("Error Read\r\n");
-        }else{
-            for(uint32_t i=0;i<readMsg.getNRecords();i++){
-                Record *r = readMsg[i];
-                printRecord(r);
-                delete r;
-            }//for
-        }//if-else
-
-        tag.closeSession();
-    }else{
-        pc.printf("Error open read Session\n\r");
-    }
-}
-
-/**
- * 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){
-    using NDefLib::Record;
-    using NDefLib::Message;
-
-    if(tag.openSession()){
-        Message readMsg;
-
-        tag.read(&readMsg);
-
-        if(readMsg.getNRecords()==0){
-            pc.printf("Error Read\r\n");
-        }else{
-            for(uint32_t i=0;i<readMsg.getNRecords();i++){
-                Record *r = readMsg[i];
-                changeRecord(r);
-            }//for
-            tag.write(readMsg);
-        }//if-else
-
-        tag.closeSession();
-    }else{
-        pc.printf("Error open SessionChange\n\r");
-    }
-}
-
-static volatile bool buttonPress=false; /// true when the user press the message
-
-/**
- * Call back called when the user press the button
- */
-static void setButtonPress(){
-    buttonPress=true;
-}//if buttonPress
-
-/**
- * Write a message and when the user press the button it read the message, change it and update it.
- */
-void sample_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);
-    X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
-    
-    //retrieve the NdefLib interface
-    NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
-    
-    //switch on the first led    
-    nfcNucleo->getLed1()=1;
-    nfcNucleo->getLed2()=0;
-    nfcNucleo->getLed3()=0;
-
-    //write the message
-    setNFCTag(tag);
-    //read the message and write it on console
-    readNfcTag(tag);
-
-    //enable the button
-    InterruptIn mybutton(USER_BUTTON);
-    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());
-        
-        if(buttonPress){
-            //update the message content
-            changeNfcTag(tag);
-            //write the new message on console
-            readNfcTag(tag);
-            buttonPress=false;
-        }
-    }
-
-}
\ No newline at end of file
--- a/Samples/Sample_writeUrl.cpp	Thu Jan 14 09:17:03 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-/**
-  ******************************************************************************
-  * @file       Sample_writeUrl.cpp
-  * @author     ST / Central Labs
-  * @date       03 Dic 2015
-  * @brief      This demo write an ndef message with an url inside
-  ******************************************************************************
-  *
-  * COPYRIGHT(c) 2015 STMicroelectronics
-  *
-  * Redistribution and use in source and binary forms, with or without modification,
-  * are permitted provided that the following conditions are met:
-  *   1. Redistributions of source code must retain the above copyright notice,
-  *      this list of conditions and the following disclaimer.
-  *   2. Redistributions in binary form must reproduce the above copyright notice,
-  *      this list of conditions and the following disclaimer in the documentation
-  *      and/or other materials provided with the distribution.
-  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-  *      may be used to endorse or promote products derived from this software
-  *      without specific prior written permission.
-  *
-  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-  *
-  ******************************************************************************
-  */
-  
-#include "mbed.h"
-
-#include "X_NUCLEO_NFC01A1.h"
-#include "NDefLib/NDefNfcTag.h"
-#include "NDefLib/RecordType/RecordURI.h"
-
-/**
- * Write a Ndef linking the st.com site.
- */
-void sample_writeUrl() {
-    Serial pc(SERIAL_TX, SERIAL_RX);
-    
-    I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
-        
-    X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
-    
-    //retrieve the NdefLib interface
-    NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
-    pc.printf("System Init done: !\n\r");
-    //open the i2c session with the nfc chip
-    if(tag.openSession()){
-        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)){
-            pc.printf("Tag writed \n\r");
-            nfcNucleo->getLed2()=1;
-        }
-
-    
-        //close the i2c session
-        if(!tag.closeSession()){
-            pc.printf("Error Closing the session\n\r");
-        }else
-            nfcNucleo->getLed3()=1;
-    }else
-        pc.printf("Error open Session\n\r");
-}
--- a/Samples/Samples.h	Thu Jan 14 09:17:03 2016 +0000
+++ b/Samples/Samples.h	Mon Feb 01 15:33:26 2016 +0000
@@ -1,8 +1,9 @@
 /**
   ******************************************************************************
-  * @file       Samples.h
+  * @file       SamplesSync.h
   * @date       03/12/2015
-  * @brief      This file contains definitions for the sample function.
+  * @brief      This file contains definitions for the sample functions that are
+  * that are using the nfc component in a sync way.
   ******************************************************************************
   *
   * COPYRIGHT(c) 2015 STMicroelectronics
@@ -38,21 +39,25 @@
 /**
  * Wirte a tag with a web site link
  */
-void sample_writeUrl();
+void sampleSync_writeUrl();
+void sampleAsync_writeUrl();
 
 /**
  * Write a castom tag that count how many times the user press the button
  */
-void sample_countClick();
+void sampleSync_countClick();
+void sampleAsync_countClick();
 
 /**
  * Write a message with all the tag, when the user press the button read the message and change the
  * tag content
  */
-void sample_writeAndChangeAll();
+void sampleSync_writeAndChangeAll();
+void sampleAsync_writeAndChangeAll();
 
 /**
  * Set the tag as read only when the user pres the button
  */
-void sample_lockTagContent();
+void sampleSync_lockTagContent();
+void sampleAsync_lockTagContent();
 #endif /* __SAMPLES_H__ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/sampleAsync_lockWriteTag.cpp	Mon Feb 01 15:33:26 2016 +0000
@@ -0,0 +1,270 @@
+/**
+  ******************************************************************************
+  * @file       Sample_lockWriteTag.cpp
+  * @author     ST / Central Labs
+  * @date       03 Dic 2015
+  * @brief      This demo define a lock/unlock the tag content when the user press
+  *  the user button
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+
+#include "mbed.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+
+static bool buttonPress=false; /// true when the user press the message
+static bool nfcEvent=false; /// true when the user press the message
+
+static void setNfcEventCallback(){
+	nfcEvent=true;
+}//if buttonPress
+/**
+ * Call back called when the user press the button.
+ */
+static void setButtonPress(){
+    buttonPress=true;
+}//if buttonPress
+
+/**
+ * Class with the command chain needed for remove all the read/write password
+ */
+class RemoveAllPasswordStatusCallback : public Nfc::Callback {
+
+public:
+
+	RemoveAllPasswordStatusCallback():mIsComamndRunning(false){}
+
+	/**
+	 * true when the command chain finish, and the the tag can now be read and write
+	 * @return true if the command chain finish
+	 */
+	bool isFinish(){
+		return !mIsComamndRunning;
+	}
+
+
+private:
+	bool mIsComamndRunning; /// false when the command chain finish
+
+	/**
+	 * end the command chain and print an error message
+	 * @param status error code of the last command
+	 */
+	void onError(const NFC_StatusTypeDef status){
+		mIsComamndRunning=false;
+		printf("Error Code: %X \r\n",status);
+	}
+
+	virtual void onSessionOpen(Nfc *tag,NFC_StatusTypeDef status){
+		if(status!=NFC_SUCCESS)
+			return onError(status);
+		mIsComamndRunning=true;
+
+		tag->SelectApplication();
+	}
+
+	virtual void onSelectedApplication(Nfc *tag,NFC_StatusTypeDef status){
+		if(status!=NFC_SUCCESS)
+			return onError(status);
+
+		tag->SelectNDEFfile(0x0001);
+	}
+
+	virtual void onSelectedNDEFFile(Nfc *tag,NFC_StatusTypeDef status){
+		if(status!=NFC_SUCCESS)
+			return onError(status);
+
+		tag->DisableAllPassword(M24SR::DEFAULT_PASSWORD);
+	}
+
+	virtual void onDisableAllPassword(Nfc *tag, NFC_StatusTypeDef status){
+		if(status!=NFC_SUCCESS)
+			return onError(status);
+
+		tag->Deselect();
+	}
+
+	virtual void onDeselect(Nfc *,NFC_StatusTypeDef status){
+		if(status!=NFC_SUCCESS)
+			return onError(status);
+		mIsComamndRunning=false;
+	}
+
+};
+
+/**
+ * Chain of call needed for change the tag status between read only and write/read
+ */
+class ChangeTagStatusCallback : public Nfc::Callback {
+
+	M24SR &mNfcTag; /// object to change
+	DigitalOut& mReadOnlyLed; /// led to switch on when it is in read only mode
+	DigitalOut& mReadWriteWriteLed; /// led to switch on when is in read/write mode
+
+	bool mIsReadOnly; /// current tag status
+	bool mIsComamndRunning; /// true if the chain is running
+
+	public:
+
+		/**
+		 * Build a chain of callback needed for change the tag status.
+		 * @param nfcTag Tag to change.
+		 * @param readLed Led to switch on when in read only mode.
+		 * @param writeLed Led to switch on when in read/write mode.
+		 */
+		ChangeTagStatusCallback(M24SR &nfcTag, DigitalOut& readLed, DigitalOut& writeLed):
+			mNfcTag(nfcTag),mReadOnlyLed(readLed),mReadWriteWriteLed(writeLed),mIsReadOnly(false),
+			mIsComamndRunning(false){
+			mReadOnlyLed=false;
+			mReadWriteWriteLed=true;
+		}
+
+		/**
+		 * Change the tag status
+		 */
+		void changeStatus(){
+			mIsReadOnly=!mIsReadOnly;
+			//if it is not running a previous command
+			if(!mIsComamndRunning){
+				mNfcTag.GetSession();
+			}//if
+		}//changeStatus;
+
+	private:
+
+		/**
+		 * When an error happen switch on both the led and print the error code.
+		 * @param status Error code.
+		 */
+		void onError(const NFC_StatusTypeDef status){
+			mIsComamndRunning=false;
+			mReadOnlyLed=true;
+			mReadWriteWriteLed=true;
+			printf("Error %X changing the status\r\n",status);
+		}
+
+		virtual void onSessionOpen(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+			mNfcTag.SelectApplication();
+		}
+
+		virtual void onSelectedApplication(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+			mNfcTag.SelectNDEFfile(0x0001);
+		}
+
+		virtual void onSelectedNDEFFile(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+
+			if(mIsReadOnly){
+				mNfcTag.EnableReadOnly(M24SR::DEFAULT_PASSWORD);
+			}else
+				mNfcTag.DisableReadOnly(M24SR::DEFAULT_PASSWORD);
+		}
+
+
+		virtual void onEnableReadOnly(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+
+			if(!mIsReadOnly) //if in the meantime the status change
+				mNfcTag.DisableReadOnly(M24SR::DEFAULT_PASSWORD);
+			else{
+				mReadOnlyLed=true;
+				mReadWriteWriteLed=false;
+				mNfcTag.Deselect();
+			}
+		}
+
+		virtual void onDisableReadOnly(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+
+			if(mIsReadOnly) //if in the meantime the status change
+				mNfcTag.EnableReadOnly(M24SR::DEFAULT_PASSWORD);
+			else{
+				mReadOnlyLed=false;
+				mReadWriteWriteLed=true;
+				mNfcTag.Deselect();
+			}
+		}
+
+		virtual void onDeselect(Nfc *,NFC_StatusTypeDef status){
+			if(status!=NFC_SUCCESS)
+				return onError(status);
+			mIsComamndRunning=false;
+		}
+};
+
+/**
+ * When the user press the button enable/disable the tag write protection.
+ */
+void sampleAsync_lockTagContent() {
+
+    //instance the board with the default parameters
+    I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+    X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,&setNfcEventCallback);
+	
+    //when the user press the button set buttonPress to true
+    InterruptIn userButton(USER_BUTTON);
+    userButton.fall(setButtonPress);
+    
+    M24SR &nfcTag =nfcNucleo->getM24SR();
+
+    //set async mode
+    if(nfcTag.GetSession()!=NFC_SUCCESS)
+    	nfcTag.ManageI2CGPO(I2C_ANSWER_READY);
+
+
+    ChangeTagStatusCallback changeTagStatus(nfcTag,nfcNucleo->getLed2(),nfcNucleo->getLed3());
+    RemoveAllPasswordStatusCallback removeAllPasswordStatusCallback;
+
+    nfcTag.SetCallback(&removeAllPasswordStatusCallback);
+    nfcTag.GetSession();
+    nfcNucleo->getLed1()=true;
+
+    while(true){
+
+        if(buttonPress && removeAllPasswordStatusCallback.isFinish()){
+        	buttonPress=false;
+            nfcTag.SetCallback(&changeTagStatus);
+        	changeTagStatus.changeStatus();
+        }//if
+        if(nfcEvent){
+        	nfcEvent=false;
+        	nfcTag.ManageEvent();
+        }
+        //wait next event
+        __WFE();
+    }//while
+
+}//sampleAsync_lockTagContent
\ No newline at end of file
--- a/Samples/sample_lockWriteTag.cpp	Thu Jan 14 09:17:03 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,156 +0,0 @@
-/**
-  ******************************************************************************
-  * @file       Sample_lockWriteTag.cpp
-  * @author     ST / Central Labs
-  * @date       03 Dic 2015
-  * @brief      This demo define a lock/unlock the tag content when the user press
-  *  the user button
-  ******************************************************************************
-  *
-  * COPYRIGHT(c) 2015 STMicroelectronics
-  *
-  * Redistribution and use in source and binary forms, with or without modification,
-  * are permitted provided that the following conditions are met:
-  *   1. Redistributions of source code must retain the above copyright notice,
-  *      this list of conditions and the following disclaimer.
-  *   2. Redistributions in binary form must reproduce the above copyright notice,
-  *      this list of conditions and the following disclaimer in the documentation
-  *      and/or other materials provided with the distribution.
-  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-  *      may be used to endorse or promote products derived from this software
-  *      without specific prior written permission.
-  *
-  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-  *
-  ******************************************************************************
-  */
-
-#include "mbed.h"
-
-#include "X_NUCLEO_NFC01A1.h"
-
-static volatile bool buttonPress=false; /// true when the user press the message
-
-/**
- * Call back called when the user press the button.
- */
-static void setButtonPress(){
-    buttonPress=true;
-}//if buttonPress
-
-/**
- * Return the led that tell if the tag is read only.
- * @param nfcNucleo Board where the lead lives.
- * @return let to switch on if the tag is read only
- */
-static inline DigitalOut& getReadOnlyLed(X_NUCLEO_NFC01A1 *nfcNucleo){
-	return nfcNucleo->getLed2();
-}
-
-/**
- * Return the led that tell if the tag is write only.
- * @param nfcNucleo Board where the lead lives.
- * @return let to switch on if the tag is write only
- */
-static inline DigitalOut& getWriteableLed(X_NUCLEO_NFC01A1 *nfcNucleo){
-	return nfcNucleo->getLed3();
-}
-
-/**
- * Set the tag as read only and switch the led on.
- * @param nfcNucleo Board where the lead lives.
- * @return true if the change has effect
- */
-bool enableReadOnly( X_NUCLEO_NFC01A1 *nfcNucleo){
-
-	if(nfcNucleo->getM24SR().enableReadOnly()==NFC_SUCCESS){
-		getReadOnlyLed(nfcNucleo)=true;
-		getWriteableLed(nfcNucleo)=false;
-		return true;
-	}else
-		return false;
-}
-
-/**
- * Set the tag as read/write and switch the led on.
- * @param nfcNucleo Board where the lead lives.
- * @return true if the change has effect
- */
-bool disableReadOnly( X_NUCLEO_NFC01A1 *nfcNucleo){
-
-	if(nfcNucleo->getM24SR().disableReadOnly()==NFC_SUCCESS){
-		getReadOnlyLed(nfcNucleo)=false;
-		getWriteableLed(nfcNucleo)=true;
-		return true;
-	}else
-		return false;
-}
-
-/**
- * When the user press the button enable/disable the tag write protetion.
- */
-void sample_lockTagContent() {
-	Serial console(SERIAL_TX, SERIAL_RX);
-	
-    //instance the board with the default paramiters
-    I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
-    X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
-	
-    //retrieve the NdefLib interface
-	NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
-
-    //when the user press the button set buttonPress to true
-    InterruptIn userButton(USER_BUTTON);
-    userButton.fall(setButtonPress);
-    
-    //restore the board as read/write, set the led1 if it is ok
-    tag.openSession(true);
-    nfcNucleo->getLed1()= (nfcNucleo->getM24SR().disableAllPassword()==NFC_SUCCESS);
-    tag.closeSession();
-    
-	// now we are in read/write -> switch on the writable led    
-    getReadOnlyLed(nfcNucleo)=false;
-    getWriteableLed(nfcNucleo)=true;
-    bool tagIsLock=false;
-
-    while(true){
-
-        if(buttonPress){
-        	if(tag.openSession()){
-        		bool changeStatusResult;
-				//switch the status
-				if(tagIsLock)
-					changeStatusResult=enableReadOnly(nfcNucleo);
-				else
-					changeStatusResult=disableReadOnly(nfcNucleo);
-
-				if(changeStatusResult)
-					tagIsLock=!tagIsLock;
-				else
-					console.printf("Error change the tag status\r\n");
-				tag.closeSession();
-        	}else{
-        		console.printf("Error opening the session, tag is in use\r\n");
-        	}
-        	buttonPress=false;
-        }//if
-
-        //wait next event
-        __WFE();
-    }//while
-
-}//sample_countClick
-
-
-
-
-
--- a/X_NUCLEO_NFC01A1.lib	Thu Jan 14 09:17:03 2016 +0000
+++ b/X_NUCLEO_NFC01A1.lib	Mon Feb 01 15:33:26 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/giovannivisentini/code/X_NUCLEO_NFC01A1/#d1f5eaa85deb
+http://developer.mbed.org/users/giovannivisentini/code/X_NUCLEO_NFC01A1/#d07138541feb
--- a/main.cpp	Thu Jan 14 09:17:03 2016 +0000
+++ b/main.cpp	Mon Feb 01 15:33:26 2016 +0000
@@ -31,28 +31,46 @@
   ******************************************************************************
   */
 
+//#define SYNC_MODE
+
 #include "Samples/Samples.h"
  
 //#define SAMPLE_WRITE_URL
 //#define SAMPLE_COUNT_CLICK
-#define SAMPLE_WRITE_AND_CHANGE_ALL
-//#define SAMPLE_LOCK_TAG_CONTENT
+//#define SAMPLE_WRITE_AND_CHANGE_ALL
+#define SAMPLE_LOCK_TAG_CONTENT
  
 int main(void)
 {
 #ifdef SAMPLE_WRITE_URL
-    sample_writeUrl();
+    #ifdef SYNC_MODE
+        sampleSync_writeUrl();
+    #else
+        sampleAsync_writeUrl();
+    #endif
 #endif /* SAMPLE_WRITE_URL */
 
 #ifdef SAMPLE_COUNT_CLICK
-    sample_countClick();
+    #ifdef SYNC_MODE
+        sampleSync_countClick();
+    #else
+        sampleAsync_countClick();
+    #endif
 #endif /* SAMPLE_COUNT_CLICK */
 
 #ifdef SAMPLE_WRITE_AND_CHANGE_ALL
-    sample_writeAndChangeAll();
+    #ifdef SYNC_MODE
+        sampleSync_writeAndChangeAll();
+    #else
+        sampleAsync_writeAndChangeAll();
+    #endif
 #endif /* SAMPLE_WRITE_AND_CHANGE_ALL */
 
 #ifdef SAMPLE_LOCK_TAG_CONTENT
-    sample_lockTagContent();
+    #ifdef SYNC_MODE
+        sampleSync_lockTagContent();
+    #else
+        sampleAsync_lockTagContent();
+    #endif
 #endif /* SAMPLE_LOCK_TAG_CONTENT */
-}
\ No newline at end of file
+}
--- a/mbed.bld	Thu Jan 14 09:17:03 2016 +0000
+++ b/mbed.bld	Mon Feb 01 15:33:26 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file