4 Replies Latest reply on Jan 27, 2016 10:07 AM by ankr_1205151

    Any suggested methods for utilizing NFC?

      I'm having some issues getting NFC to work properly in SDK 3.3.1.  The demo apps (snip.nfc.tag_reader and snip.nfc.tag_writer) work properly on my BCM943341 development board.  However, these example apps call the wiced_nfc_read_tag and wiced_nfc_write_tag APIs forever in a while (1) loop.  I would like to implement these calls in an interrupt-driven fashion, starting by using the two buttons on the demo board.  I placed these two calls in a routine assigned to the hardware worker thread as follows - this routine is called once a second and checks the status of the two buttons:

       

      // Fire up the worker thread for NFC read and write

      wiced_rtos_register_timed_event( &nfc_worker_event, WICED_HARDWARE_IO_WORKER_THREAD, nfc_worker, 1000, 0 );

       

      ....

       

       

      static void nfc_worker ( )

      {

          wiced_result_t result;

          int    i;

       

          WPRINT_APP_INFO (("NFC worker called.  %d\n", timeout++));

          wiced_gpio_output_low( WICED_LED1 );

          wiced_gpio_output_low( WICED_LED2 );

          // NFC Read

          if (start_nfc_read == WICED_TRUE)

          {

              start_nfc_read = WICED_FALSE;

              wiced_gpio_output_high( WICED_LED2 );

              WPRINT_APP_INFO (("Starting NFC Read.\n"));

              /* Reset the buffer_length variable. Note that this is used for both input and output */

              buffer_length = NFC_DATA_LENGTH;

       

              /* Wait for, and read, and NFC tag */

              result = wiced_nfc_read_tag( buffer, &buffer_length, NFC_READ_TIMEOUT );

              if ( result != WICED_SUCCESS )

              {

                  if ( result == WICED_TIMEOUT )

                  {

                      WPRINT_APP_INFO( ( "Tag not detected\n" ) );

                  }

                  return;

              }

       

              WPRINT_APP_INFO( ( "Received %lu bytes:\n", buffer_length ) );

       

              /* Print the contents of the NFC tag */

              for ( i = 0; i < buffer_length; i++ )

              {

                  /* Check if the character is printable, otherwise use hex notation*/

                  if ( buffer[ i ] >= 0x20 && buffer[ i ] <= 0x7E )

                  {

                      WPRINT_APP_INFO( ( "%c", buffer[i] ) );

                  }

                  else

                  {

                      WPRINT_APP_INFO( ( "\\%02x", buffer[i] ) );

                  }

              }

              WPRINT_APP_INFO( ( "\n" ) );

       

          }

          else if (start_nfc_write == WICED_TRUE)

          {

              start_nfc_write = WICED_FALSE;

              wiced_gpio_output_high( WICED_LED1 );

              WPRINT_APP_INFO (("Starting NFC Write.\n"));

       

              WPRINT_APP_INFO( ("\nWaiting for tag...\n") );

              result = wiced_nfc_write_tag( &tag_write_message, NFC_WRITE_TIMEOUT );

       

              if ( result == WICED_SUCCESS )

              {

                  WPRINT_APP_INFO( ("Tag write successful\n") );

       

                  /* Delay for a short time to allow tag to be removed */

                  //wiced_rtos_delay_milliseconds( 1000 );

              }

              else if ( result == WICED_TIMEOUT )

              {

                  WPRINT_APP_INFO( ( "Tag not detected\n" ) );

              }

       

          }

      }

       

      Ultimately the hardware works and I can read or write an NFC tag but it only works once:  It gets stuck somewhere in the above routine and the design crashes.

       

      Is there a recommended way of calling the NFC tag read and write API?  The NFC stuff appears to run within a separate thread of its own.