Ashok R
Published

Simple NFC Reader

This project demonstrates reading an NFC tag and controlling the RGB LED with a PN1720 controller.

EasyShowcase (no instructions)4 hours67
Simple NFC Reader

Things used in this project

Hardware components

NXP NFC Reader - PN7120
×1
NXP LPC824 Xpresso Board
×1
NFC Coins
×4

Story

Read more

Schematics

Schematic

Only I2c & LED connections
Nfc reader demo sch wkiulectr2

Code

NFCTasks

C/C++
Only changes required with Basic Demo
void NdefPull_Cb(unsigned char *pNdefMessage, unsigned short NdefMessageSize)
{
    unsigned char *pNdefRecord = pNdefMessage;
    unsigned char save;

    NdefRecord_t NdefRecord;

    if (pNdefMessage == NULL)
    {
        printf("--- Provisioned buffer size too small or NDEF message empty \n");
        return;
    }

    while (pNdefRecord != NULL)
    {
        printf("--- NDEF record received:\n");

        NdefRecord = DetectNdefRecordType(pNdefRecord);

        if(NdefRecord.recordType == WELL_KNOWN_SIMPLE_TEXT)
        {

                save = NdefRecord.recordPayload[NdefRecord.recordPayloadSize];
                NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = '\0';
                printf("   Text record: %s\n", &NdefRecord.recordPayload[NdefRecord.recordPayload[0]+1]);

                memcpy(&read_message_buffer[0],&NdefRecord.recordPayload[NdefRecord.recordPayload[0]+1], NdefRecord.recordPayloadSize);
                NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = save;

                switch(read_message_buffer[0]){

                case 'R':
                	Board_LED_Set(0, false);
                    Board_LED_Set(1, false);
                    Board_LED_Set(2, true);
                    break;
                case 'G':
                	Board_LED_Set(0, false);
                    Board_LED_Set(1, true);
                    Board_LED_Set(2, false);
                    break;
                case 'B':
                	Board_LED_Set(0, true);
                    Board_LED_Set(1, false);
                    Board_LED_Set(2, false);
                    break;
                case 'W':
                	Board_LED_Set(0, true);
                    Board_LED_Set(1, true);
                    Board_LED_Set(2, true);
                    break;
                }
            }
        else{
            printf("   Unsupported NDEF record, cannot parse\n");
        }
        pNdefRecord = GetNextRecord(pNdefRecord);
    }

    printf("\n");
}

Credits

Ashok R

Ashok R

14 projects • 42 followers
Hobbyist/Engineer/Director/Animatior

Comments