PN532 read card fail

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PN532 read card fail

1,933 Views
pylin
Contributor I

I try to use PN532 to read a card, and it fail. Attached is the PN532 driver code and below is the main function code 

 

    while (1)
    {

        uint8_t success;
        uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0}; // Buffer to store the returned UID
        uint8_t uidLength;                     // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

        // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
        // 'uid' will be populated with the UID, and uidLength will indicate
        // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
        success = pn532_readPassiveTargetID(&nfc, PN532_MIFARE_ISO14443A, uid, &uidLength, 0);

        if (success)
        {
            // Display some basic information about the card
       //     ESP_LOGI(TAG, "Found an ISO14443A card");
            ESP_LOGI(TAG, "Found an card");
            ESP_LOGI(TAG, "UID Length: %d bytes", uidLength);

            ESP_LOGI(TAG, "UID Value:");

        //    esp_log_buffer_hexdump_internal(TAG, uid, uidLength, ESP_LOG_INFO);
            ESP_LOG_BUFFER_HEX_LEVEL(TAG, uid, uidLength, ESP_LOG_INFO);

            if(uidLength==4)
            {
            	mifare_classic_handling();
            }
            else if(uidLength==7)
            {
            	mifare_ultralight_handling();
            }else
            {
            	ESP_LOGE(TAG, "unknown card detected");
            }



            vTaskDelay(1000 / portTICK_RATE_MS);         
        }
        else
        {
            // PN532 probably timed out waiting for a card
            ESP_LOGI(TAG, "Timed out waiting for a card");
        }
    	if(++count>=255)
    		count =0;
    }
void mifare_classic_handling(void)
{
	uint8_t write_buffer[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
	uint8_t read_buffer[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};


	ESP_LOGI(TAG, "mifare classic");
	write_buffer[0]=count;
	/*
	ESP_LOGI(TAG, "write test data:");
	ESP_LOG_BUFFER_HEX_LEVEL(TAG, write_buffer, 4, ESP_LOG_INFO);
	if(pn532_mifareclassic_WriteDataBlock(&nfc,0,write_buffer)==1)
	{
		  ESP_LOGI(TAG, "write test data succeed");
	}else   ESP_LOGI(TAG, "write test data fail");
	*/
	ESP_LOGI(TAG, "read test data:");

    if(pn532_mifareclassic_ReadDataBlock(&nfc,0,read_buffer)==1)
    {
    	  ESP_LOGI(TAG, "read test data succeed");
    	  ESP_LOG_BUFFER_HEX_LEVEL(TAG, read_buffer, 16, ESP_LOG_INFO);
    }else
    {
    	ESP_LOGI(TAG, "read test data fail");
    }

}

 

 

The console log output of the firmware is as following when I put a card above the pn532 antenna. It seems that it can read UID of the card. But it cannot read the data of the card. Please comment on this issue

I (32030) APP: Found an card
I (32030) APP: UID Length: 4 bytes
I (32030) APP: UID Value:
I (32030) APP: ba 08 f7 3f
I (32030) APP: mifare classic
I (32030) APP: read test data:
Trying to read 16 bytes from block 0
Unexpected response: 00 ff 03 fd d5 41 13 d7 00 aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
I (32410) APP: read test data fail

 

0 Kudos
Reply
2 Replies

1,908 Views
estephania_mart
NXP TechSupport
NXP TechSupport

Hello,

 

It would appear that are either a migration or a custom implementation is this correct?

In this case I would recommend you to check the NFC-FRI SDK (NFC Forum Reference Implementation)   and use the examples as a base for you implementation.

 

Hope this helps

 

regards,
Estephania

 

 

 

0 Kudos
Reply

1,918 Views
pylin
Contributor I

Add more description:

Inside pn532_mifareclassic_ReadDataBlock() function, it suppose that the 8th byte of PN532_COMMAND_INDATAEXCHANGE command response should be 0x00. However it is not. Therefore, it output error.

Anyone can help in this

0 Kudos
Reply