Any suggested methods for utilizing NFC?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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 ) );

            }

            else

            {

                WPRINT_APP_INFO( ( "\\%02x", buffer ) );

            }

        }

        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.

0 Likes
4 Replies
Anonymous
Not applicable

Hey andrew997,

The approach that you have followed seems to be correct.

Have you resolved the problem?

Best Regards,

AB

0 Likes
Anonymous
Not applicable

It's been a while since I looked at this as I've been pulled into other areas.. I'll see if 3.4.0 has any improvements in this area in terms of stability.

0 Likes
Anonymous
Not applicable

Hey,

Can you check this post:-

T/R switch/external PA on WICED WiFi dev boards

It listens to the NFC Reader only when a switch is pressed. The moment the user release the switch, the nfc stops reading from the antenna.

Hope that helps.

Best Regards,

AB

0 Likes
Anonymous
Not applicable

abirjepatil

So it's been a LONG time since I looked at this but I believe I understand now why things were crashing.  According to this post:

Printing from a timed event function in a worker thread causes watchdog

The stack size allocated to the WICED_HARDWARE_IO_WORKER_THREAD isn't large enough to accomodate a printf statement.  It would work once and then crash which is exactly what was happening to me.  I'm not able to verify this on hardware at the moment but I strongly suspect this was my issue.

0 Likes