PN532 Class
- ID: pn532
- Name: NFC/RFID Reader/Writer
- Category: rfid
- Manufacturer: adafruit
- Link: http://www.adafruit.com/products/364
- Connection: i2c
Identify a card and print out basic info Add a URI to an already NDEF formatted ultralight or NTAG2XX tag
Item Index
Methods
- PN532
- init
- getFirmwareVersion
- sendCommandCheckAck
- SAMConfig
- setPassiveActivationRetries
- readPassiveTargetID
- inDataExchange
- inListPassiveTarget
- mifareclassic_IsFirstBlock
- mifareclassic_IsTrailerBlock
- mifareclassic_AuthenticateBlock
- mifareclassic_ReadDataBlock
- mifareclassic_WriteDataBlock
- mifareclassic_FormatNDEF
- mifareclassic_WriteNDEFURI
- ntag2xx_ReadPage
- ntag2xx_WritePage
- ntag2xx_WriteNDEFURI
- getATQA
- getSAK
- i2cContext
- pn532Debug
- mifareDebug
- tagType
Properties
- CMD_DIAGNOSE
- CMD_GETFIRMWAREVERSION
- CMD_GETGENERALSTATUS
- CMD_READREGISTER
- CMD_WRITEREGISTER
- CMD_READGPIO
- CMD_WRITEGPIO
- CMD_SETSERIALBAUDRATE
- CMD_SETPARAMETERS
- CMD_SAMCONFIGURATION
- CMD_POWERDOWN
- CMD_RFCONFIGURATION
- CMD_RFREGULATIONTEST
- CMD_INJUMPFORDEP
- CMD_INJUMPFORPSL
- CMD_INLISTPASSIVETARGET
- CMD_INATR
- CMD_INPSL
- CMD_INDATAEXCHANGE
- CMD_INCOMMUNICATETHRU
- CMD_INDESELECT
- CMD_INRELEASE
- CMD_INSELECT
- CMD_INAUTOPOLL
- CMD_TGINITASTARGET
- CMD_TGSETGENERALBYTES
- CMD_TGGETDATA
- CMD_TGSETDATA
- CMD_TGSETMETADATA
- CMD_TGGETINITIATORCOMMAND
- CMD_TGRESPONSETOINITIATOR
- CMD_TGGETTARGETSTATUS
- RSP_INDATAEXCHANGE
- RSP_INLISTPASSIVETARGET
- MIFARE_CMD_AUTH_A
- MIFARE_CMD_AUTH_B
- MIFARE_CMD_READ
- MIFARE_CMD_WRITE
- MIFARE_CMD_TRANSFER
- MIFARE_CMD_DECREMENT
- MIFARE_CMD_INCREMENT
- MIFARE_CMD_STORE
- MIFARE_ULTRALIGHT_CMD_WRITE
- NDEF_URIPREFIX_NONE
- NDEF_URIPREFIX_HTTP_WWWDOT
- NDEF_URIPREFIX_HTTPS_WWWDOT
- NDEF_URIPREFIX_HTTP
- NDEF_URIPREFIX_HTTPS
- NDEF_URIPREFIX_TEL
- NDEF_URIPREFIX_MAILTO
- NDEF_URIPREFIX_FTP_ANONAT
- NDEF_URIPREFIX_FTP_FTPDOT
- NDEF_URIPREFIX_FTPS
- NDEF_URIPREFIX_SFTP
- NDEF_URIPREFIX_SMB
- NDEF_URIPREFIX_NFS
- NDEF_URIPREFIX_FTP
- NDEF_URIPREFIX_DAV
- NDEF_URIPREFIX_NEWS
- NDEF_URIPREFIX_TELNET
- NDEF_URIPREFIX_IMAP
- NDEF_URIPREFIX_RTSP
- NDEF_URIPREFIX_URN
- NDEF_URIPREFIX_POP
- NDEF_URIPREFIX_SIP
- NDEF_URIPREFIX_SIPS
- NDEF_URIPREFIX_TFTP
- NDEF_URIPREFIX_BTSPP
- NDEF_URIPREFIX_BTL2CAP
- NDEF_URIPREFIX_BTGOEP
- NDEF_URIPREFIX_TCPOBEX
- NDEF_URIPREFIX_IRDAOBEX
- NDEF_URIPREFIX_FILE
- NDEF_URIPREFIX_URN_EPC_ID
- NDEF_URIPREFIX_URN_EPC_TAG
- NDEF_URIPREFIX_URN_EPC_PAT
- NDEF_URIPREFIX_URN_EPC_RAW
- NDEF_URIPREFIX_URN_EPC
- NDEF_URIPREFIX_URN_NFC
- BAUD_MIFARE_ISO14443A
- TAG_TYPE_UNKNOWN
- TAG_TYPE_MIFARE_CLASSIC
- TAG_TYPE_NFC2
Methods
PN532
-
irq
-
reset
-
bus
-
address
pn532 constructor
Parameters:
-
irq
Numberpin to use for IRQ
-
reset
Numberreset pin
-
bus
Numberi2c bus to use
-
address
Numberthe address for this device
Returns:
init
()
Boolean
set up initial values and start operation
Returns:
true if successful
getFirmwareVersion
()
Number
Checks the firmware version of the PN5xx chip
Returns:
the chip's firmware version and ID
sendCommandCheckAck
-
cmd
-
cmdlen
-
timeout
sends a command and waits a specified period for the ACK
Parameters:
-
cmd
Uint8_t *Pointer to the command buffer
-
cmdlen
Numberthe size of the command in bytes
-
timeout
Numbertimeout before giving up (in ms)
Returns:
true if everything is OK, false if timeout occurred before an ACK was received
SAMConfig
()
Boolean
configures the SAM (Secure Access Module)
Returns:
true if successfully configured
setPassiveActivationRetries
-
maxRetries
sets the MxRtyPassiveActivation byte of the RFConfiguration register. By default the pn532 will retry indefinitely.
Sets the MxRtyPassiveActivation byte of the RFConfiguration register
Parameters:
-
maxRetries
Number0xFF to wait forever, 0x00..0xFE to timeout after maxRetries. 0x00 means try once, with no retries on failure.
Returns:
true if everything executed properly, false for an error
readPassiveTargetID
-
cardbaudrate
-
uid
-
uidLength
-
timeout
waits for an ISO14443A target to enter the field
Waits for an ISO14443A target to enter the field
Parameters:
-
cardbaudrate
BAUD_Tbaud rate of the card, one of the BAUD_T values
-
uid
Uint8_t *Pointer to the array that will be populated with the cards UID, up to 7 bytes
-
uidLength
Uint8_t *Pointer to the variable that will hold the length of the card's UID.
-
timeout
Numberthe number of milliseconds to wait
Returns:
true if everything executed properly, false for an error
inDataExchange
-
send
-
sendLength
-
response
-
responseLength
exchanges an APDU (Application Protocol Data Unit) with the currently inlisted peer
Parameters:
-
send
Uint8_t *Pointer to data to send
-
sendLength
NumberLength of the data to send
-
response
Uint8_t *Pointer to response data
-
responseLength
Uint8_t *Pointer to the response data length
Returns:
true if everything executed properly, false for an error
inListPassiveTarget
()
Boolean
'InLists' a passive target. PN532 acting as reader/initiator, peer acting as card/responder.
Returns:
true if everything executed properly, false for an error
mifareclassic_IsFirstBlock
-
uiBlock
Indicates whether the specified block number is the first block in the sector (block 0 relative to the current sector)
Indicates whether the specified block number is the first block in the sector (block 0 relative to the current sector)
Parameters:
-
uiBlock
Numberundefined
Returns:
true if it's the first block, false otherwise
mifareclassic_IsTrailerBlock
-
uiBlock
indicates whether the specified block number is the sector trailer
Indicates whether the specified block number is the sector trailer
Parameters:
-
uiBlock
Numberundefined
Returns:
true if it's the trailer block, false otherwise
mifareclassic_AuthenticateBlock
-
uid
-
uidLen
-
blockNumber
-
keyNumber
-
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.
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
Uint8_t *Pointer to a byte array containing the card UID
-
uidLen
NumberThe length (in bytes) of the card's UID (Should be 4 for MIFARE Classic)
-
blockNumber
NumberThe block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards).
-
keyNumber
NumberWhich key type to use during authentication (0 = MIFARE_CMD_AUTH_A, 1 = MIFARE_CMD_AUTH_B)
-
keyData
Uint8_t *Pointer to a byte array containing the 6 byte key value
Returns:
true if everything executed properly, false for an error
mifareclassic_ReadDataBlock
-
blockNumber
-
data
tries to read an entire 16-byte data block at the specified block address.
Tries to read an entire 16-byte data block at the specified block address.
Parameters:
-
blockNumber
NumberThe block number to read (0..63 for 1KB cards, and 0..255 for 4KB cards).
-
data
Uint8_t *Pointer to the byte array that will hold the retrieved data (if any)
Returns:
true if everything executed properly, false for an error
mifareclassic_WriteDataBlock
-
blockNumber
-
data
tries to write an entire 16-byte data block at the specified block address.
Tries to write an entire 16-byte data block at the specified block address.
Parameters:
-
blockNumber
NumberThe block number to write. (0..63 for 1KB cards, and 0..255 for 4KB cards).
-
data
Uint8_t *The byte array that contains the data to write.
Returns:
true if everything executed properly, false for an error
mifareclassic_FormatNDEF
()
Boolean
formats a Mifare Classic card to store NDEF Records
Formats a Mifare Classic card to store NDEF Records
Returns:
true if everything executed properly, false for an error
mifareclassic_WriteNDEFURI
-
sectorNumber
-
uriIdentifier
-
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.
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
NumberThe sector that the URI record should be written to (can be 1..15 for a 1K card)
-
uriIdentifier
NDEF_URI_TThe uri identifier code (one of the NDEF_URI_T values
-
url
Stringthe uri text to write (max 38 characters).
Returns:
true if everything executed properly, false for an error
ntag2xx_ReadPage
-
page
-
buffer
read an entire 4-byte page at the specified address
Tries to read an entire 4-byte page at the specified address.
Parameters:
-
page
NumberThe page number (0..63 in most cases)
-
buffer
Uint8_t *Pointer to the byte array that will hold the retrieved data (if any)
Returns:
true if everything executed properly, false for an error
ntag2xx_WritePage
-
page
-
data
write an entire 4-byte page at the specified block address
Tries to write an entire 4-byte page at the specified block address.
Parameters:
-
page
NumberThe page number to write. (0..63 for most cases)
-
data
Uint8_t *The byte array that contains the data to write. Should be exactly 4 bytes long.
Returns:
true if everything executed properly, false for an error
ntag2xx_WriteNDEFURI
-
uriIdentifier
-
url
-
dataLen
writes an NDEF URI Record starting at the specified page (4..nn)
Note that this function assumes that the NTAG2xx card is already formatted to work as an "NFC Forum Tag".
Writes an NDEF URI Record starting at the specified page (4..nn)
Note that this function assumes that the NTAG2xx card is already formatted to work as an "NFC Forum Tag".
Parameters:
-
uriIdentifier
NDEF_URI_TThe uri identifier code (one of the NDEF_URI_T values
-
url
StringThe uri text to write (null-terminated string).
-
dataLen
NumberThe size of the data area for overflow checks.
Returns:
true if everything executed properly, false for an error
getATQA
()
Number
return the ATQA (Answer to Request Acknowledge) value. This value is only valid after a successful call to readPassiveTargetID()
Returns:
ATQA value
getSAK
()
Number
return the SAK (Select Acknowledge) value. This value is only valid after a successful call to readPassiveTargetID()
Returns:
SAK value
i2cContext
()
Mraa::I2c *
provide public access to the class's MRAA i2C context for direct user access
Returns:
a reference to the class i2c context
pn532Debug
-
enable
enable or disable debugging output for pn532 related operations
Parameters:
-
enable
Booleantrue to enabloe debug output, false to disable
mifareDebug
-
enable
enable or disable debugging output for mifare related operations
Parameters:
-
enable
Booleantrue to enabloe debug output, false to disable
tagType
()
TAG_TYPE_T
try to determine the tag type
Returns:
one of the TAG_TYPE_T values