Adafruit PN532 NFC Library

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
MrBlue1234
 
Posts: 4
Joined: Thu Jun 10, 2021 5:54 pm

Adafruit PN532 NFC Library

Post by MrBlue1234 »

Hello everyone.

1.) I am using the Adafruit PN532 NFC shield, Nordic nRF52840 Development kit and the Nordic SDK that includes the Adafruit examples projects for reading from an NFC tag.

2.) Using the project "as-is" I am able to get some basic information about the tag that is being scanned. (NTAG213)
tag_read.PNG
tag_read.PNG (217.07 KiB) Viewed 420 times
3.) You can see that there are 29 bytes in plain text that I would like to read back.

4.) I am calling the function adafruit_pn532_tag2_read(), using the function from the Adafruit library, but it seems that I am not able to read back the information as expected.

- I am not getting the NRF_LOG_INFO() output as expect in the function adafruit_pn532_tag2_read(). But when I call NRF_LOG_INFO() directly in main.c this works correctly. I am not sure why I am not seeing the log info from within this function.

- What are the prerequisites to call adafruit_pn532_tag2_read() ?

- What should the parameters be if I am just trying to read back those 29 bytes?

- Can someone confirm that this adafruit_pn532_tag2_read() works? (And again note I am using an NXP based NTAG213 NFC tag, not sure if that is going to be an issue)

Code: Select all

ret_code_t adafruit_pn532_tag2_read(uint8_t start_page, uint8_t * p_buffer)
{
    NRF_LOG_INFO("Trying to read pages: %d-%d", start_page, start_page + T2T_END_PAGE_OFFSET);

    ret_code_t err_code;

    uint8_t cmd_buf[2];
    uint8_t response_len = T2T_MAX_DATA_EXCHANGE;

    cmd_buf[0] = MIFARE_CMD_READ;
    cmd_buf[1] = start_page;

    err_code = adafruit_pn532_in_data_exchange(cmd_buf, 2, p_buffer, &response_len);
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_INFO("Failed to read pages: %d-%d",
                     start_page,
                     start_page + T2T_END_PAGE_OFFSET);
        return err_code;
    }

    NRF_LOG_INFO("Pages %d-%d", start_page, start_page + T2T_END_PAGE_OFFSET);
    NRF_LOG_HEXDUMP_INFO(p_buffer, response_len);

    return NRF_SUCCESS;
}

5.) I tried adding in a few reads but nothing is happening. See the code below:
scan.PNG
scan.PNG (47.66 KiB) Viewed 420 times

Code: Select all

/*
* This function waits for a Tag to appear in the field. When a Tag is detected, Tag Platform
 * Type (2/4) is identified and appropriate read procedure is run.
 */
ret_code_t tag_detect_and_read(void)
{
    ret_code_t     err_code;
    nfc_a_tag_info tag_info;
    uint8_t data_read[32];
    uint32_t error_result;


    error_result = 0;

    // Detect a NFC-A Tag in the field and initiate a communication. This function activates
    // the NFC RF field. If a Tag is present, basic information about detected Tag is returned
    // in tag info structure.
    err_code = adafruit_pn532_nfc_a_target_init(&tag_info, TAG_DETECT_TIMEOUT);

    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_NOT_FOUND;
    }
    adafruit_pn532_tag_info_printout(&tag_info);

    nfc_tag_type_t tag_type = tag_type_identify(tag_info.sel_res);
    switch (tag_type)
    {
        case NFC_T2T:
            NRF_LOG_INFO("Type 2 Tag Platform detected. ");

            NRF_LOG_INFO("Testing....read page 0? \n");
            error_result = adafruit_pn532_tag2_read(0, data_read);
            NRF_LOG_FLUSH();

            NRF_LOG_INFO("Testing....read page 1? \n");
            error_result = adafruit_pn532_tag2_read(1, data_read);
            NRF_LOG_FLUSH();

            NRF_LOG_INFO("Testing....read page 2? \n");
            error_result = adafruit_pn532_tag2_read(2, data_read);
            NRF_LOG_FLUSH();

            return t2t_data_read_and_analyze(&tag_info);

        case NFC_T4T:
            NRF_LOG_INFO("Type 4 Tag Platform detected. ");
            return t4t_data_read_and_analyze(&tag_info);

        default:
            return NRF_ERROR_NOT_SUPPORTED;
    }
}


Thank you for any suggestions.

-Mike

User avatar
MrBlue1234
 
Posts: 4
Joined: Thu Jun 10, 2021 5:54 pm

Re: Adafruit PN532 NFC Library

Post by MrBlue1234 »

Anyone?

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”