UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

PN532 Class

Module: pn532

pn532.jpg Identify a card and print out basic info Add a URI to an already NDEF formatted ultralight or NTAG2XX tag

Item Index

Properties

Methods

PN532

(
  • irq
  • reset
  • bus
  • address
)
Number

pn532 constructor

Parameters:

  • irq Number

    pin to use for IRQ

  • reset Number

    reset pin

  • bus Number

    i2c bus to use

  • address Number

    the address for this device

Returns:

Number:

init

() Boolean

set up initial values and start operation

Returns:

Boolean:

true if successful

getFirmwareVersion

() Number

Checks the firmware version of the PN5xx chip

Returns:

Number:

the chip's firmware version and ID

sendCommandCheckAck

(
  • cmd
  • cmdlen
  • timeout
)
Boolean

sends a command and waits a specified period for the ACK

Parameters:

  • cmd Uint8_t *

    Pointer to the command buffer

  • cmdlen Number

    the size of the command in bytes

  • timeout Number

    timeout before giving up (in ms)

Returns:

Boolean:

true if everything is OK, false if timeout occurred before an ACK was received

SAMConfig

() Boolean

configures the SAM (Secure Access Module)

Returns:

Boolean:

true if successfully configured

setPassiveActivationRetries

(
  • maxRetries
)
Boolean

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 Number

    0xFF to wait forever, 0x00..0xFE to timeout after maxRetries. 0x00 means try once, with no retries on failure.

Returns:

Boolean:

true if everything executed properly, false for an error

readPassiveTargetID

(
  • cardbaudrate
  • uid
  • uidLength
  • timeout
)
Boolean

waits for an ISO14443A target to enter the field
Waits for an ISO14443A target to enter the field

Parameters:

  • cardbaudrate BAUD_T

    baud 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 Number

    the number of milliseconds to wait

Returns:

Boolean:

true if everything executed properly, false for an error

inDataExchange

(
  • send
  • sendLength
  • response
  • responseLength
)
Boolean

exchanges an APDU (Application Protocol Data Unit) with the currently inlisted peer

Parameters:

  • send Uint8_t *

    Pointer to data to send

  • sendLength Number

    Length of the data to send

  • response Uint8_t *

    Pointer to response data

  • responseLength Uint8_t *

    Pointer to the response data length

Returns:

Boolean:

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:

Boolean:

true if everything executed properly, false for an error

mifareclassic_IsFirstBlock

(
  • uiBlock
)
Boolean

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 Number

    undefined

Returns:

Boolean:

true if it's the first block, false otherwise

mifareclassic_IsTrailerBlock

(
  • uiBlock
)
Boolean

indicates whether the specified block number is the sector trailer
Indicates whether the specified block number is the sector trailer

Parameters:

  • uiBlock Number

    undefined

Returns:

Boolean:

true if it's the trailer block, false otherwise

mifareclassic_AuthenticateBlock

(
  • uid
  • uidLen
  • blockNumber
  • keyNumber
  • keyData
)
Boolean

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 Number

    The length (in bytes) of the card's UID (Should be 4 for MIFARE Classic)

  • blockNumber Number

    The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards).

  • keyNumber Number

    Which 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:

Boolean:

true if everything executed properly, false for an error

mifareclassic_ReadDataBlock

(
  • blockNumber
  • data
)
Boolean

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 Number

    The 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:

Boolean:

true if everything executed properly, false for an error

mifareclassic_WriteDataBlock

(
  • blockNumber
  • data
)
Boolean

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 Number

    The 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:

Boolean:

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:

Boolean:

true if everything executed properly, false for an error

mifareclassic_WriteNDEFURI

(
  • sectorNumber
  • uriIdentifier
  • url
)
Boolean

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 Number

    The sector that the URI record should be written to (can be 1..15 for a 1K card)

  • uriIdentifier NDEF_URI_T

    The uri identifier code (one of the NDEF_URI_T values

  • url String

    the uri text to write (max 38 characters).

Returns:

Boolean:

true if everything executed properly, false for an error

ntag2xx_ReadPage

(
  • page
  • buffer
)
Boolean

read an entire 4-byte page at the specified address
Tries to read an entire 4-byte page at the specified address.

Parameters:

  • page Number

    The page number (0..63 in most cases)

  • buffer Uint8_t *

    Pointer to the byte array that will hold the retrieved data (if any)

Returns:

Boolean:

true if everything executed properly, false for an error

ntag2xx_WritePage

(
  • page
  • data
)
Boolean

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 Number

    The 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:

Boolean:

true if everything executed properly, false for an error

ntag2xx_WriteNDEFURI

(
  • uriIdentifier
  • url
  • dataLen
)
Boolean

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_T

    The uri identifier code (one of the NDEF_URI_T values

  • url String

    The uri text to write (null-terminated string).

  • dataLen Number

    The size of the data area for overflow checks.

Returns:

Boolean:

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:

Number:

ATQA value

getSAK

() Number

return the SAK (Select Acknowledge) value. This value is only valid after a successful call to readPassiveTargetID()

Returns:

Number:

SAK value

i2cContext

() Mraa::I2c *

provide public access to the class's MRAA i2C context for direct user access

Returns:

Mraa::I2c *:

a reference to the class i2c context

pn532Debug

(
  • enable
)

enable or disable debugging output for pn532 related operations

Parameters:

  • enable Boolean

    true to enabloe debug output, false to disable

mifareDebug

(
  • enable
)

enable or disable debugging output for mifare related operations

Parameters:

  • enable Boolean

    true to enabloe debug output, false to disable

tagType

() TAG_TYPE_T

try to determine the tag type

Returns:

TAG_TYPE_T:

one of the TAG_TYPE_T values

Properties

CMD_DIAGNOSE

Enum PN532_CMD_T

CMD_GETFIRMWAREVERSION

Enum PN532_CMD_T

CMD_GETGENERALSTATUS

Enum PN532_CMD_T

CMD_READREGISTER

Enum PN532_CMD_T

CMD_WRITEREGISTER

Enum PN532_CMD_T

CMD_READGPIO

Enum PN532_CMD_T

CMD_WRITEGPIO

Enum PN532_CMD_T

CMD_SETSERIALBAUDRATE

Enum PN532_CMD_T

CMD_SETPARAMETERS

Enum PN532_CMD_T

CMD_SAMCONFIGURATION

Enum PN532_CMD_T

CMD_POWERDOWN

Enum PN532_CMD_T

CMD_RFCONFIGURATION

Enum PN532_CMD_T

CMD_RFREGULATIONTEST

Enum PN532_CMD_T

CMD_INJUMPFORDEP

Enum PN532_CMD_T

CMD_INJUMPFORPSL

Enum PN532_CMD_T

CMD_INLISTPASSIVETARGET

Enum PN532_CMD_T

CMD_INATR

Enum PN532_CMD_T

CMD_INPSL

Enum PN532_CMD_T

CMD_INDATAEXCHANGE

Enum PN532_CMD_T

CMD_INCOMMUNICATETHRU

Enum PN532_CMD_T

CMD_INDESELECT

Enum PN532_CMD_T

CMD_INRELEASE

Enum PN532_CMD_T

CMD_INSELECT

Enum PN532_CMD_T

CMD_INAUTOPOLL

Enum PN532_CMD_T

CMD_TGINITASTARGET

Enum PN532_CMD_T

CMD_TGSETGENERALBYTES

Enum PN532_CMD_T

CMD_TGGETDATA

Enum PN532_CMD_T

CMD_TGSETDATA

Enum PN532_CMD_T

CMD_TGSETMETADATA

Enum PN532_CMD_T

CMD_TGGETINITIATORCOMMAND

Enum PN532_CMD_T

CMD_TGRESPONSETOINITIATOR

Enum PN532_CMD_T

CMD_TGGETTARGETSTATUS

Enum PN532_CMD_T

RSP_INDATAEXCHANGE

Enum PN532_RSP_T

RSP_INLISTPASSIVETARGET

Enum PN532_RSP_T

MIFARE_CMD_AUTH_A

Enum MIFARE_CMD_T

MIFARE_CMD_AUTH_B

Enum MIFARE_CMD_T

MIFARE_CMD_READ

Enum MIFARE_CMD_T

MIFARE_CMD_WRITE

Enum MIFARE_CMD_T

MIFARE_CMD_TRANSFER

Enum MIFARE_CMD_T

MIFARE_CMD_DECREMENT

Enum MIFARE_CMD_T

MIFARE_CMD_INCREMENT

Enum MIFARE_CMD_T

MIFARE_CMD_STORE

Enum MIFARE_CMD_T

MIFARE_ULTRALIGHT_CMD_WRITE

Enum MIFARE_CMD_T

NDEF_URIPREFIX_NONE

Enum NDEF_URI_T

NDEF_URIPREFIX_HTTP_WWWDOT

Enum NDEF_URI_T

NDEF_URIPREFIX_HTTPS_WWWDOT

Enum NDEF_URI_T

NDEF_URIPREFIX_HTTP

Enum NDEF_URI_T

NDEF_URIPREFIX_HTTPS

Enum NDEF_URI_T

NDEF_URIPREFIX_TEL

Enum NDEF_URI_T

NDEF_URIPREFIX_MAILTO

Enum NDEF_URI_T

NDEF_URIPREFIX_FTP_ANONAT

Enum NDEF_URI_T

NDEF_URIPREFIX_FTP_FTPDOT

Enum NDEF_URI_T

NDEF_URIPREFIX_FTPS

Enum NDEF_URI_T

NDEF_URIPREFIX_SFTP

Enum NDEF_URI_T

NDEF_URIPREFIX_SMB

Enum NDEF_URI_T

NDEF_URIPREFIX_NFS

Enum NDEF_URI_T

NDEF_URIPREFIX_FTP

Enum NDEF_URI_T

NDEF_URIPREFIX_DAV

Enum NDEF_URI_T

NDEF_URIPREFIX_NEWS

Enum NDEF_URI_T

NDEF_URIPREFIX_TELNET

Enum NDEF_URI_T

NDEF_URIPREFIX_IMAP

Enum NDEF_URI_T

NDEF_URIPREFIX_RTSP

Enum NDEF_URI_T

NDEF_URIPREFIX_URN

Enum NDEF_URI_T

NDEF_URIPREFIX_POP

Enum NDEF_URI_T

NDEF_URIPREFIX_SIP

Enum NDEF_URI_T

NDEF_URIPREFIX_SIPS

Enum NDEF_URI_T

NDEF_URIPREFIX_TFTP

Enum NDEF_URI_T

NDEF_URIPREFIX_BTSPP

Enum NDEF_URI_T

NDEF_URIPREFIX_BTL2CAP

Enum NDEF_URI_T

NDEF_URIPREFIX_BTGOEP

Enum NDEF_URI_T

NDEF_URIPREFIX_TCPOBEX

Enum NDEF_URI_T

NDEF_URIPREFIX_IRDAOBEX

Enum NDEF_URI_T

NDEF_URIPREFIX_FILE

Enum NDEF_URI_T

NDEF_URIPREFIX_URN_EPC_ID

Enum NDEF_URI_T

NDEF_URIPREFIX_URN_EPC_TAG

Enum NDEF_URI_T

NDEF_URIPREFIX_URN_EPC_PAT

Enum NDEF_URI_T

NDEF_URIPREFIX_URN_EPC_RAW

Enum NDEF_URI_T

NDEF_URIPREFIX_URN_EPC

Enum NDEF_URI_T

NDEF_URIPREFIX_URN_NFC

Enum NDEF_URI_T

BAUD_MIFARE_ISO14443A

Enum BAUD_T

TAG_TYPE_UNKNOWN

Enum TAG_TYPE_T

TAG_TYPE_MIFARE_CLASSIC

Enum TAG_TYPE_T

TAG_TYPE_NFC2

Enum TAG_TYPE_T