Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PN532 by
Diff: PN532.cpp
- Revision:
- 8:7ffdaea03ff9
- Parent:
- 7:26c1b3b6c192
- Parent:
- 5:51f820fbd18a
--- a/PN532.cpp Tue Mar 25 16:48:10 2014 +0000 +++ b/PN532.cpp Wed Oct 08 01:52:33 2014 +0000 @@ -287,7 +287,7 @@ @returns 1 if everything executed properly, 0 for an error */ /**************************************************************************/ -bool PN532::readPassiveTargetID(uint8_t cardbaudrate, uint8_t *uid, uint8_t *uidLength, uint16_t timeout) +bool PN532::readPassiveTargetID(uint8_t cardbaudrate, uint8_t *uid, uint8_t *uidLength, uint16_t *atqa, uint8_t *sak, uint16_t timeout) { pn532_packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET; pn532_packetbuffer[1] = 1; // max 1 cards at once (we can set this to 2 later) @@ -321,7 +321,8 @@ uint16_t sens_res = pn532_packetbuffer[2]; sens_res <<= 8; sens_res |= pn532_packetbuffer[3]; - + *atqa = sens_res; + *sak = pn532_packetbuffer[4]; DMSG("ATQA: 0x"); DMSG_HEX(sens_res); DMSG("SAK: 0x"); DMSG_HEX(pn532_packetbuffer[4]); DMSG("\n"); @@ -496,6 +497,35 @@ /* Read the response packet */ return (0 < HAL(readResponse)(pn532_packetbuffer, sizeof(pn532_packetbuffer))); } +/**************************************************************************/ +/*! + Tries to write an entire 4-bytes data block at the specified block + address. + + @param blockNumber The block number to authenticate. (0..63 for + 1KB cards, and 0..255 for 4KB cards). + @param data The byte array that contains the data to write. + + @returns 1 if everything executed properly, 0 for an error +*/ +/**************************************************************************/ +uint8_t PN532::mifareultralight_WritePage (uint8_t blockNumber, uint8_t *data) +{ + /* Prepare the first command */ + pn532_packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE; + pn532_packetbuffer[1] = 1; /* Card number */ + pn532_packetbuffer[2] = MIFARE_UL_CMD_WRITE_PAGE; /* Mifare Write command = 0xA0 */ + pn532_packetbuffer[3] = blockNumber; /* Block Number (0..63 for 1K, 0..255 for 4K) */ + memcpy (pn532_packetbuffer + 4, data, 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))); +} /**************************************************************************/ /*!