• sales

    +86-0755-88291180

Raspberry Pi PN532 NFC write block 2 --> timeout

2024-05-22 16:06:30 Ask

Hello

I want to write some data to Block 2, but I got this error:

Found PN532 with firmware version: 1.6

Waiting for RFID/NFC card to write to!

.Found card with UID: ['0xFF', '0xFF', '0xFF', '0xFF']

PN532 ERROR TIMEOUT

here is my code:

block_number = 2

key_a = b'\x33\xCD\x45\xFA\x45\xFF'

data = bytes([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F])

try:

   pn532.mifare_classic_authenticate_block(

       uid, block_number=block_number, key_number=nfc.MIFARE_CMD_AUTH_A, key=key_a)

   pn532.mifare_classic_write_block(block_number, data)

   if pn532.mifare_classic_read_block(block_number) == data:

       print('write block %d successfully' % block_number)

except nfc.PN532Error as e:

   print(e.errmsg)

GPIO.cleanup()


where is my mistake? I can read this block, but I can't write :-(


Greetings

Thomas

Raspberry Pi PN532 NFC write block 2 --> timeout
APost Reply
Like0| timeout| --> report
View 425
3answers
SpotPearGuest8bb15
Answer time:
2024-05-22 16:48:37

1】Make sure you have sufficient permissions to perform write operations. You can add sudo or chmod and other commands to obtain permissions.

2】Maybe the card itself does not allow writing or is in some special state causing writing to time out. Check whether the card can be written and whether it meets the conditions for writing. You can use another card to compare and test.

3】 Check whether the connection to PN532 is stable and reliable and whether the hardware is working properly.

Code logic problem: Although you can read the block, there may be some detailed errors in the writing logic. Carefully check whether the parameter settings and execution order of the two operations pn532.mifare_classic_authenticate_block and pn532.mifare_classic_write_block are correct.

It is recommended to use our sample programs for comparison and testing, all of which have been verified; or use this tool for comparison and testing

https://files.waveshare.com/upload/8/83/Nfc-tools_reference_manual.pdf

Like0

report

SpotPearGuestef4ae
Answer time:
2024-05-22 16:56:46

1) I have tried the code with sudo, same error

2) with the example I can write to the card.

3.) it is your example, the only different is Block 2 instead of 6.

Like0

report

SpotPearGuestef4ae
Answer time:
2024-05-23 01:38:12

when I want so write the block 2 with the right key, I got the error: timeout

I use the samples from your webpage...

block 6 is writing

Like0

report

Price: $13.89
Part Number: PN532-NFC-HAT
Brand: Spotpear