nfc - Writing to Mifare Ultralight C with PN532 library for Arduino Uno -


i use sample code read mifare ultralight , write mifare classic, definition in .h file:

#define pn532_response_indataexchange       (0x41) #define mifare_cmd_write                    (0xa0) 

but when run code below:

/**************************************************************************/ uint8_t pn532::mifareultralight_writepage (uint8_t page, uint8_t *buffer1) {     /* prepare first command */     pn532_packetbuffer[0] = pn532_command_indataexchange;     pn532_packetbuffer[1] = 1;                      /* card number */     pn532_packetbuffer[2] = mifare_cmd_write;       /* mifare write command = 0xa0 */     pn532_packetbuffer[3] = page;                   /* page number (0..63 in cases) */     memcpy (pn532_packetbuffer + 4, buffer1, 4);        /* data payload */      /* send command */     if (hal(writecommand)(pn532_packetbuffer, 8)) {         serial.println(f("go here 1"));         return 0;     }     serial.println(f("go here 2"));     /* read response packet */     return (0 < hal(readresponse)(pn532_packetbuffer, sizeof(pn532_packetbuffer))); } 

the result this:

scan nfc tag  write:  4a 1 0 read:   4b 1 1 0 44 0 7 4 c1 37 ca 2c 2c 80 atqa: 0x 44sak: 0x 0 writing mifare ultralight write:  40 1 30 4 read:   41 0 2 0 0 10 0 6 1 10 11 ff 0 0 0 0 0 0 write:  40 1 30 3 read:   41 0 0 0 0 0 2 0 0 10 0 6 1 10 11 ff 0 0 tag capacity 0 bytes write:  40 1 a0 5 1 2 3 4 go here 2 write failed 0 

it not go "go here 1", means no write command reader, know why?

that write command using seems wrong. using compatibility_write command code (0xa0) pass parameters of write command.

i suggest stick write command:

+-----------+------+------+---------------------+ | wrapping  | cmd  | addr | data (1 page)       | +-----------+------+------+---------------------+ | 0x40 0x01 | 0xa2 | 0x05 | 0x01 0x02 0x03 0x04 | +-----------+------+------+---------------------+ 

or use compatibility_write command:

  1. you start sending command , address:

    +-----------+------+------+ | wrapping  | cmd  | addr | +-----------+------+------+ | 0x40 0x01 | 0xa0 | 0x05 | +-----------+------+------+ 

    you should receive ack/nak status tag.

  2. then send data in second frame:

    +-----------+---------------------+------------------------------------------------------------+ | wrapping  | data (1 page)       | filler (3 empty pages) +-----------+---------------------+------------------------------------------------------------+ | 0x40 0x01 | 0x01 0x02 0x03 0x04 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +-----------+---------------------+------------------------------------------------------------+ 

Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -

basic authentication with http post params android -