M2M im2ag M2PGI
Dependencies: mbed X_NUCLEO_NFC01A1 NDefLib
Revision 2:7183a6189b65, committed 2016-03-08
- Comitter:
- ThibaudB
- Date:
- Tue Mar 08 15:32:58 2016 +0000
- Parent:
- 1:20d7b4998087
- Child:
- 3:3b71ec7ae3bd
- Commit message:
- Hello world avec NFC
Changed in this revision
| 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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_NFC01A1.lib Tue Mar 08 15:32:58 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ST/code/X_NUCLEO_NFC01A1/#2090378b0b51
--- a/main.cpp Tue Mar 08 15:14:42 2016 +0000
+++ b/main.cpp Tue Mar 08 15:32:58 2016 +0000
@@ -1,12 +1,52 @@
+
#include "mbed.h"
-DigitalOut myled(LED1);
+#include "X_NUCLEO_NFC01A1.h"
+#include "NDefLib/NDefNfcTag.h"
+#include "NDefLib/RecordType/RecordURI.h"
-int main() {
- while(1) {
- myled = 1; // LED is ON
- wait(0.1); // 200 ms
- myled = 0; // LED is OFF
- wait(0.1); // 1 sec
- }
-}
+/**
+ * Write a Ndef URI message linking to st.com site.
+ */
+int main(void){
+
+ //use default board pinout
+ I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+ X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,NULL,
+ X_NUCLEO_NFC01A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC01A1::DEFAULT_RF_DISABLE_PIN,
+ X_NUCLEO_NFC01A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC01A1::DEFAULT_LED2_PIN,
+ X_NUCLEO_NFC01A1::DEFAULT_LED3_PIN);
+
+ //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()){
+ printf("Session opened\n\r");
+ nfcNucleo->getLed1()=1;
+
+ //create the NDef message and record
+ NDefLib::Message msg;
+ NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com");
+ msg.addRecord(&rUri);
+
+ //write the tag
+ if(tag.write(msg)){
+ printf("Tag written\n\r");
+ nfcNucleo->getLed2()=1;
+ }else{
+ printf("Error writing \n\r");
+ }//if-else
+
+ //close the i2c session
+ if(tag.closeSession()){
+ printf("Session closed\n\r");
+ nfcNucleo->getLed3()=1;
+ }else{
+ printf("Error closing the session\n\r");
+ }//if-else
+
+ }else
+ printf("Error opening the session\n\r");
+}
\ No newline at end of file
