A simple mbed OS application providing an example of asynchronous access to the X-NUCLEO_NFC01A1 Dynamic NFC Tag board.

Dependencies:   NDefLib X_NUCLEO_NFC01A1

Fork of mbed-os-example-NFC01A1 by Nicola Capovilla

The application provides a simple example of asynchronous access to the X-NUCLEO-NFC01A1 Dynamic NFC Tag Expansion Board. It represents the multi-threaded mbed OS 5 version of the mbed classic HelloWorld_Async_NFC01A1 application.
The program writes a URI link to the M24SR dynamic tag using the asynchronous programming model. The URI can then be read and printed on the serial console by pressing the user button and/or via RF from an NFC enabled smartphone/tablet.

Revision:
1:951cd8fbff34
Parent:
0:3e88cb856f63
Child:
2:e06d881b4b3c
--- a/main.cpp	Thu Aug 10 16:59:44 2017 +0000
+++ b/main.cpp	Fri Aug 11 07:58:12 2017 +0000
@@ -58,23 +58,29 @@
     nfcEventsThread.signal_set(NFC_INTERRUPT_FLAG);
 }//nfcInterruptCallback
  
+/** ISR handling button pressure **/ 
 static void set_button_press() {
     nfcReadThread.signal_set(BUTTON_PRESSED_FLAG);    
 }//buttonPressed event
 
 
 void nfcEvents() {
-    
     while (true) {
         osEvent event = nfcEventsThread.signal_wait(NFC_INTERRUPT_FLAG); // wait for nfc event
-        printf("Got an NFC event!\n\r");  
+        //printf("Got an NFC event!\n\r");  
         nfcNucleo->get_M24SR().manage_event();
     }
 }
 
 void readNfc() {
     
+    //create the callback to read a tag
     ReadUriCallbacks NDefReadCallback(nfcNucleo->get_led1(),nfcNucleo->get_led2(),nfcNucleo->get_led3());
+    //create the callback to write a tag
+    WriteUriCallbacks NDefWriteCallback(nfcNucleo->get_led1(),nfcNucleo->get_led2(),nfcNucleo->get_led3());
+    // write the tag
+    printf("Writing Tag\n\r");
+    tag->open_session();
     
     while (true) {
         osEvent event = nfcReadThread.signal_wait(BUTTON_PRESSED_FLAG); // wait for button pressed
@@ -104,20 +110,14 @@
     nfcNucleo->get_M24SR().get_session();
     nfcNucleo->get_M24SR().manage_I2C_GPO(M24SR::I2C_ANSWER_READY); //switch to async mode
  
-    *tag = nfcNucleo->get_M24SR().get_NDef_tag();
-    printf("System Init done! Starting the threads.\n\r");
+    tag = &(nfcNucleo->get_M24SR().get_NDef_tag());
+    printf("System Init done!\n\r");
     
      //Start the nfc event handling thread
     nfcEventsThread.start(nfcEvents);
-    //Start the button pressed thread
+    //Start the nfc reading thread - also writes the tag once
     nfcReadThread.start(readNfc);
-    
-    printf("Writing Tag\n\r");
-    //create the callback to write a tag
-    WriteUriCallbacks NDefWriteCallback(nfcNucleo->get_led1(),nfcNucleo->get_led2(),nfcNucleo->get_led3());
-    // write the tag
-    tag->open_session(); 
-    
+      
     while (true) {
         __WFE();
     }