SECTOR_SELECT command with PN532

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

SECTOR_SELECT command with PN532

1,343 Views
nkose13
Contributor I

Hello,

I am trying to read the session registers in an NXP NTAG I2C 1k with a PN532 using an Arduino board to eventually communicate in Pass-through mode. I downloaded an NFC library for Arduino that includes most of the functions like "Read Page" or "Write Page". For example, WritePage command looks like this:

uint8_t PN532::mifareultralight_WritePage (uint8_t page, uint8_t *buffer)
{
/* Prepare the first command */
pn532_packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE;
pn532_packetbuffer[1] = 1; /* Card number */
pn532_packetbuffer[2] = MIFARE_CMD_WRITE_ULTRALIGHT; /* Mifare UL Write cmd = 0xA2 */
pn532_packetbuffer[3] = page; /* page Number (0..63) */
memcpy (pn532_packetbuffer + 4, buffer, 4); /* Data Payload */

/* Send the command */
if (HAL(writeCommand)(pn532_packetbuffer, 8)) {
return 0;
}

/* Read the response packet */
return (0 < HAL(readResponse)(pn532_packetbuffer, sizeof(pn532_packetbuffer)));
}

So I added a SectorSelect command based on the WritePage function. I used PN532_COMMAND_INCOMMUNICATETHRU instead of INDATAEXCHANGE, and the function expects a timeout after the second command instead of an ACK response:

uint8_t PN532::SectorSelect (uint8_t sectorNumber)
{
/* Prepare the command */
pn532_packetbuffer[0] = PN532_COMMAND_INCOMMUNICATETHRU; //(0x42)
pn532_packetbuffer[1] = 1; /* Card number */
pn532_packetbuffer[2] = PN532_CMD_SECTOR_SELECT; 
pn532_packetbuffer[3] = 0xFF;

/* Send the command */
if (HAL(writeCommand)(pn532_packetbuffer, 4)) {
Serial.print("\n1st Sector Select Command Failed");
return 0;
}

/* Read the response packet */ 
HAL(readResponse)(pn532_packetbuffer, sizeof(pn532_packetbuffer));

/* Prepare the 2nd command */ 
pn532_packetbuffer[0] = PN532_COMMAND_INCOMMUNICATETHRU; //(0x42)
pn532_packetbuffer[1] = 1; /* Card number */
pn532_packetbuffer[2] = sectorNumber; 
pn532_packetbuffer[3] = 0x00; 
pn532_packetbuffer[4] = 0x00; 
pn532_packetbuffer[5] = 0x00;

/* Send the 2nd command */
if (HAL(writeCommand)(pn532_packetbuffer, 6) > -2 ){
Serial.print("\n2nd Sector Select Command Failed");
return 0;
}

/* Read the response packet */
HAL(readResponse)(pn532_packetbuffer, sizeof(pn532_packetbuffer));

Serial.print("\n2nd Sector Select Command Successful");
// Return OK signal
return 1;
}

I have a few questions regarding this piece of code I wrote. 

1) The timeout duration defined in this library is 10 ms, however the datasheet says that 1 ms of no response is enough for a Passive ACK. So at the beginning, I only waited for 1 ms and did not get any response so the function returned the OK signal. However, when I try sending a ReadPage command after a sector select command I got an error with the read function even though it works normally before a sector select.

2) After that I tried waiting for 10 ms for the Passive ACK signal, but weird enough instead of getting no response or a NACK response, I eventually get an ACK response after the second sector_select command as well, so the function gives an error, and a ReadPage command does not work afterwards either.

Any advice or comment would be much appreciated.

*** The library I originally used and changed is at : https://github.com/Seeed-Studio/PN532

Labels (1)
  • RF

0 Kudos
5 Replies

997 Views
sebastian_matt
Contributor I

Hello,

did you solve the problem?

I have the same hardware (Arduino and PN532) here and want to read some pages from the sector 1 of an NT3H2211.

Best regards

0 Kudos

997 Views
nkose13
Contributor I

Hello,

I'm sorry but I stopped working on that project a year ago, and as far as I remember I was not able to solve it.

Good luck

0 Kudos

997 Views
Kan_Li
NXP TechSupport
NXP TechSupport

I am sorry, but which data sheet you referred to? I didn't find the "1 ms" statement you mentioned. Please kindly clarify.

Thanks for your patience!


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

997 Views
nkose13
Contributor I

sectorselect.PNG

This is the SECTOR SELECT command explained in the datasheet of NT3H1101

(you can find it here: https://www.mouser.com/ds/2/302/NT3H1101_1201-1127167.pdf )

0 Kudos

997 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Thanks for the information!

but maybe you have some misunderstanding with the data sheet, referring to the following info from the data sheet of NT3H1101, you have to wait for 10 ms for the Passive ACK.

pastedImage_1.png


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos