NFC library using PN532 to read/write NDEF Messages to NFC tags
Dependents:
Seeed_NFC_Shield_write
Nucleo_test_nfc
Fork of
PN532
by Yihui Xiong
« Back to documentation index
PN532 Class Reference
The PN532 class.
More...
#include <PN532.h >
Public Member Functions
void begin (void)
Setups the HW.
bool SAMConfig (void)
Configures the SAM (Secure Access Module)
uint32_t getFirmwareVersion (void)
Checks the firmware version of the PN5xx chip.
bool writeGPIO (uint8_t pinstate)
uint8_t readGPIO (void)
bool setPassiveActivationRetries (uint8_t maxRetries)
int8_t tgInitAsTarget (uint16_t timeout=0)
Init PN532 as a target.
bool inListPassiveTarget ()
'InLists' a passive target. PN532 acting as reader/initiator, peer acting as card/responder.
bool readPassiveTargetID (uint8_t cardbaudrate, uint8_t *uid, uint8_t *uidLength, uint16_t timeout=1000)
bool inDataExchange (uint8_t *send, uint8_t sendLength, uint8_t *response, uint8_t *responseLength)
Exchanges an APDU with the currently inlisted peer.
bool mifareclassic_IsFirstBlock (uint32_t uiBlock)
bool mifareclassic_IsTrailerBlock (uint32_t uiBlock)
uint8_t mifareclassic_AuthenticateBlock (uint8_t *uid, uint8_t uidLen, uint32_t blockNumber, uint8_t keyNumber, uint8_t *keyData)
uint8_t mifareclassic_ReadDataBlock (uint8_t blockNumber, uint8_t *data)
uint8_t mifareclassic_WriteDataBlock (uint8_t blockNumber, uint8_t *data)
uint8_t mifareclassic_FormatNDEF (void)
uint8_t mifareclassic_WriteNDEFURI (uint8_t sectorNumber, uint8_t uriIdentifier, const char *url)
uint8_t mifareultralight_ReadPage (uint8_t page, uint8_t *buffer)
Static Public Member Functions
static void PrintHex (const uint8_t *data, const uint32_t numBytes)
Prints a hexadecimal value in plain characters.
static void PrintHexChar (const uint8_t *pbtData, const uint32_t numBytes)
Prints a hexadecimal value in plain characters, along with the char equivalents in the following format.
Detailed Description
The PN532 class.
Definition at line 114 of file PN532.h .
Member Function Documentation
Setups the HW.
Definition at line 29 of file PN532.cpp .
uint32_t getFirmwareVersion
(
void
)
Checks the firmware version of the PN5xx chip.
Returns: The chip's firmware version and ID
Definition at line 119 of file PN532.cpp .
bool inDataExchange
(
uint8_t *
send ,
uint8_t
sendLength ,
uint8_t *
response ,
uint8_t *
responseLength
)
Exchanges an APDU with the currently inlisted peer.
Parameters:
send Pointer to data to send
sendLength Length of the data to send
response Pointer to response data
responseLength Pointer to the response data length
Definition at line 666 of file PN532.cpp .
bool inListPassiveTarget
(
)
'InLists' a passive target. PN532 acting as reader/initiator, peer acting as card/responder.
Definition at line 708 of file PN532.cpp .
uint8_t mifareclassic_AuthenticateBlock
(
uint8_t *
uid ,
uint8_t
uidLen ,
uint32_t
blockNumber ,
uint8_t
keyNumber ,
uint8_t *
keyData
)
Tries to authenticate a block of memory on a MIFARE card using the INDATAEXCHANGE command. See section 7.3.8 of the PN532 User Manual for more information on sending MIFARE and other commands.
Parameters:
uid Pointer to a byte array containing the card UID
uidLen The length (in bytes) of the card's UID (Should be 4 for MIFARE Classic)
blockNumber The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards).
keyNumber Which key type to use during authentication (0 = MIFARE_CMD_AUTH_A, 1 = MIFARE_CMD_AUTH_B)
keyData Pointer to a byte array containing the 6 bytes key value
Returns: 1 if everything executed properly, 0 for an error
Definition at line 390 of file PN532.cpp .
uint8_t mifareclassic_FormatNDEF
(
void
)
Formats a Mifare Classic card to store NDEF Records
Returns: 1 if everything executed properly, 0 for an error
Definition at line 507 of file PN532.cpp .
bool mifareclassic_IsFirstBlock
(
uint32_t
uiBlock )
Indicates whether the specified block number is the first block in the sector (block 0 relative to the current sector)
Definition at line 348 of file PN532.cpp .
bool mifareclassic_IsTrailerBlock
(
uint32_t
uiBlock )
Indicates whether the specified block number is the sector trailer
Definition at line 362 of file PN532.cpp .
uint8_t mifareclassic_ReadDataBlock
(
uint8_t
blockNumber ,
uint8_t *
data
)
Tries to read an entire 16-bytes data block at the specified block address.
Parameters:
blockNumber The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards).
data Pointer to the byte array that will hold the retrieved data (if any)
Returns: 1 if everything executed properly, 0 for an error
Definition at line 439 of file PN532.cpp .
uint8_t mifareclassic_WriteDataBlock
(
uint8_t
blockNumber ,
uint8_t *
data
)
Tries to write an entire 16-bytes data block at the specified block address.
Parameters:
blockNumber The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards).
data The byte array that contains the data to write.
Returns: 1 if everything executed properly, 0 for an error
Definition at line 482 of file PN532.cpp .
uint8_t mifareclassic_WriteNDEFURI
(
uint8_t
sectorNumber ,
uint8_t
uriIdentifier ,
const char *
url
)
Writes an NDEF URI Record to the specified sector (1..15)
Note that this function assumes that the Mifare Classic card is already formatted to work as an "NFC Forum Tag" and uses a MAD1 file system. You can use the NXP TagWriter app on Android to properly format cards for this.
Parameters:
sectorNumber The sector that the URI record should be written to (can be 1..15 for a 1K card)
uriIdentifier The uri identifier code (0 = none, 0x01 = "http://www.", etc.)
url The uri text to write (max 38 characters).
Returns: 1 if everything executed properly, 0 for an error
Definition at line 547 of file PN532.cpp .
uint8_t mifareultralight_ReadPage
(
uint8_t
page ,
uint8_t *
buffer
)
Tries to read an entire 4-bytes page at the specified address.
Parameters:
page The page number (0..63 in most cases)
buffer Pointer to the byte array that will hold the retrieved data (if any)
Definition at line 619 of file PN532.cpp .
void PrintHex
(
const uint8_t *
data ,
const uint32_t
numBytes
)
[static]
Prints a hexadecimal value in plain characters.
Parameters:
data Pointer to the uint8_t data
numBytes Data length in bytes
Definition at line 43 of file PN532.cpp .
void PrintHexChar
(
const uint8_t *
data ,
const uint32_t
numBytes
)
[static]
Prints a hexadecimal value in plain characters, along with the char equivalents in the following format.
00 00 00 00 00 00 ......
Parameters:
data Pointer to the data
numBytes Data length in bytes
Definition at line 74 of file PN532.cpp .
uint8_t readGPIO
(
void
)
Reads the state of the PN532's GPIO pins
Returns: An 8-bit value containing the pin state where:
pinState[0] = P30 pinState[1] = P31 pinState[2] = P32 pinState[3] = P33 pinState[4] = P34 pinState[5] = P35
Definition at line 203 of file PN532.cpp .
bool readPassiveTargetID
(
uint8_t
cardbaudrate ,
uint8_t *
uid ,
uint8_t *
uidLength ,
uint16_t
timeout = 1000
)
Waits for an ISO14443A target to enter the field
Parameters:
cardBaudRate Baud rate of the card
uid Pointer to the array that will be populated with the card's UID (up to 7 bytes)
uidLength Pointer to the variable that will hold the length of the card's UID.
Returns: 1 if everything executed properly, 0 for an error
Definition at line 290 of file PN532.cpp .
Configures the SAM (Secure Access Module)
Definition at line 236 of file PN532.cpp .
bool setPassiveActivationRetries
(
uint8_t
maxRetries )
Sets the MxRtyPassiveActivation uint8_t of the RFConfiguration register
Parameters:
maxRetries 0xFF to wait forever, 0x00..0xFE to timeout after mxRetries
Returns: 1 if everything executed properly, 0 for an error
Definition at line 261 of file PN532.cpp .
int8_t tgInitAsTarget
(
uint16_t
timeout = 0
)
Init PN532 as a target.
Peer to Peer.
Parameters:
timeout max time to wait, 0 means no timeout
Returns: > 0 success = 0 timeout < 0 failed
Definition at line 754 of file PN532.cpp .
bool writeGPIO
(
uint8_t
pinstate )
Writes an 8-bit value that sets the state of the PN532's GPIO pins
Warning: This function is provided exclusively for board testing and is dangerous since it will throw an error if any pin other than the ones marked "Can be used as GPIO" are modified! All pins that can not be used as GPIO should ALWAYS be left high (value = 1) or the system will become unstable and a HW reset will be required to recover the PN532 .
pinState[0] = P30 Can be used as GPIO pinState[1] = P31 Can be used as GPIO pinState[2] = P32 *** RESERVED (Must be 1!) *** pinState[3] = P33 Can be used as GPIO pinState[4] = P34 *** RESERVED (Must be 1!) *** pinState[5] = P35 Can be used as GPIO
Returns: 1 if everything executed properly, 0 for an error
Definition at line 168 of file PN532.cpp .