nRF5 SDK v13.0.0
Modules | Data Structures | Macros
Adafruit PN532 NFC Shield library

Adafruit PN532 NFC Shield library for reading and writing tags. More...

Modules

 Frame header
 Macros related to the frame header and checksum parts.
 
 Frame tokens and offsets
 Macros related to frame tokens and offsets.
 
 Frame direction identifiers
 Macro codes identifying the communication direction.
 
 Command codes
 Macros for the available command codes.
 
 Mifare command codes
 Macros for the available Mifare command codes.
 
 Type 2 Tag specific parameters
 Macros for Type 2 Tag specific parameters.
 
 NFC-A initialisation response parameters.
 Macros for NFC-A initialisation response parameters.
 
 Adafruit PN532 implementation for nRF5x configuration
 

Data Structures

struct  nfc_a_tag_info
 Basic information about detected NFC-A tag. More...
 

Macros

#define PN532_MIFARE_ISO14443A_BAUD   (0x00)
 Code identifying the baud rate for the ISO14443A (NFC-A) card type.
 
#define PN532_I2C_ADDRESS   (0x48 >> 1)
 Address of the I2C peripheral of the Adafruit PN532 Shield.
 
#define PN532_PACKBUFF_SIZE   64
 

Functions used for initialization

ret_code_t adafruit_pn532_init (bool force)
 Function for initializing the communication with the Adafruit PN532 Shield. More...
 
ret_code_t adafruit_pn532_i2c_create (void)
 Function for creating a new PN532 object using I2C. More...
 

Generic functions for the Adafruit PN532 Shield

ret_code_t adafruit_pn532_sam_config (uint8_t mode)
 Function for configuring the Secure Access Module (SAM). More...
 
ret_code_t adafruit_pn532_power_down (void)
 Function for entering power-down mode with I2C as wake-up source. More...
 
ret_code_t adafruit_pn532_wake_up (void)
 Function for waking up the PN532 Shield from power-down mode. More...
 
ret_code_t adafruit_pn532_firmware_version_get (uint32_t *p_response)
 Function for checking the firmware version of the PN532 chip. More...
 
ret_code_t adafruit_pn532_cmd_send (uint8_t *p_cmd, uint8_t cmd_len, uint16_t timeout)
 Function for sending a command and waiting a specified period for the ACK. More...
 
ret_code_t adafruit_pn532_field_on (void)
 Function for enabling the PN532 RF field. More...
 
ret_code_t adafruit_pn532_field_off (void)
 Function for disabling the PN532 RF field. More...
 

Functions for ISO14443A tags

ret_code_t adafruit_pn532_nfc_a_target_init (nfc_a_tag_info *p_tag_info, uint16_t timeout)
 Function for detecting an ISO14443A (NFC-A) target presence in the RF field. More...
 
ret_code_t adafruit_pn532_in_data_exchange (uint8_t *p_send, uint8_t send_len, uint8_t *p_response, uint8_t *p_response_len)
 Function for exchanging an Application Protocol Data Unit (APDU) with the currently enlisted peer. More...
 
ret_code_t adafruit_pn532_passive_activation_retries_set (uint8_t max_retries)
 Function for setting the MxRtyPassiveActivation parameter of the RFConfiguration register. More...
 

Type 2 Tag related functions

ret_code_t adafruit_pn532_tag2_read (uint8_t start_page, uint8_t *p_buffer)
 Function for reading 4 pages/blocks within Type 2 Tag, starting with the specified page/block number. More...
 
ret_code_t adafruit_pn532_tag2_page_write (uint8_t page, uint8_t *p_data)
 Function for writing an entire 4-byte page/block to the Type 2 Tag at the specified page/block address. More...
 
ret_code_t adafruit_pn532_ndef_uri_tag2_write (uint8_t uri_id, char *p_url, uint8_t data_len)
 Function for writing an NDEF URI record to Type 2 Tag at the specified page (4..nn). More...
 

Printing functions.

void adafruit_pn532_tag_info_printout (nfc_a_tag_info const *const p_tag_info)
 Function for printing NFC-A Tag Info descriptor. More...
 

Low-level communication functions that utilize I2C and GPIO

bool adafruit_pn532_is_ready (void)
 Function for checking PN532 Shield readiness. More...
 
bool adafruit_pn532_waitready_ms (uint16_t timeout)
 Function for waiting until the PN532 Shield is ready. More...
 
ret_code_t adafruit_pn532_ack_read (void)
 Function for reading the ACK frame. More...
 
ret_code_t adafruit_pn532_data_read (uint8_t *p_buff, uint8_t n)
 Function for reading n bytes of data from the PN532 Shield via I2C. More...
 
ret_code_t adafruit_pn532_command_write (uint8_t *p_cmd, uint8_t cmd_len)
 Function for writing a command to the PN532 Shield. More...
 

Detailed Description

Adafruit PN532 NFC Shield library for reading and writing tags.

This library is an nRF51 and nRF52 port of the Adafruit PN532 library, which is available on GitHub, with some improvements and bugfixes. The library is responsible for communicating with the Adafruit PN532 NFC Shield and using its main functions.

This library can be used with an Adafruit PN532 NFC/RFID Controller Shield.

Function Documentation

ret_code_t adafruit_pn532_ack_read ( void  )

Function for reading the ACK frame.

Return values
NRF_SUCCESSIf the ACK frame was read. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_cmd_send ( uint8_t *  p_cmd,
uint8_t  cmd_len,
uint16_t  timeout 
)

Function for sending a command and waiting a specified period for the ACK.

Parameters
[in]p_cmdPointer to the command buffer.
[in]cmd_lenThe length of the command (in bytes).
[in]timeoutTime-out (in ms) before giving up.
Return values
NRF_SUCCESSIf the command was sent successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_command_write ( uint8_t *  p_cmd,
uint8_t  cmd_len 
)

Function for writing a command to the PN532 Shield.

This function writes a command to the PN532 Shield and automatically inserts the preamble and required frame details (such as checksum, length, ...)

Parameters
[in]p_cmdPointer to the command buffer.
[in]cmd_lenCommand length in bytes.
Return values
NRF_SUCCESSIf the command was written successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_data_read ( uint8_t *  p_buff,
uint8_t  n 
)

Function for reading n bytes of data from the PN532 Shield via I2C.

Parameters
[out]p_buffPointer to the buffer where the data will be written.
[in]nNumber of bytes to read.
Return values
NRF_SUCCESSIf the data was read successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_field_off ( void  )

Function for disabling the PN532 RF field.

Return values
NRF_SUCCESSIf the RF field was disabled successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_field_on ( void  )

Function for enabling the PN532 RF field.

Return values
NRF_SUCCESSIf the RF field was enabled successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_firmware_version_get ( uint32_t *  p_response)

Function for checking the firmware version of the PN532 chip.

Parameters
[out]p_responseThe chip's firmware version and ID.
Return values
NRF_SUCCESSIf the function completed successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_i2c_create ( void  )

Function for creating a new PN532 object using I2C.

Before calling this function, PN532_IRQ and PN532_RESET must be configured.

Return values
NRF_SUCCESSIf the object was created successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_in_data_exchange ( uint8_t *  p_send,
uint8_t  send_len,
uint8_t *  p_response,
uint8_t *  p_response_len 
)

Function for exchanging an Application Protocol Data Unit (APDU) with the currently enlisted peer.

Parameters
[in]p_sendPointer to the data to send.
[in]send_lenLength of the data to send.
[out]p_responsePointer to the buffer for response data.
[in,out]p_response_lenPointer to the variable that stores the length of the p_response buffer (as input) and the length of the response data (as output).
Return values
NRF_SUCCESSIf the function completed successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_init ( bool  force)

Function for initializing the communication with the Adafruit PN532 Shield.

Note
This library is not thread-safe, because it uses static buffers.
Parameters
[in]forceIf true, reinitialization of the library will be forced.
Return values
NRF_SUCCESSIf the communication was initialized successfully. Otherwise, an error code is returned.
bool adafruit_pn532_is_ready ( void  )

Function for checking PN532 Shield readiness.

Return values
TrueIf the PN532 Shield is ready with a response.
FalseOtherwise.
ret_code_t adafruit_pn532_ndef_uri_tag2_write ( uint8_t  uri_id,
char *  p_url,
uint8_t  data_len 
)

Function for writing an NDEF URI record to Type 2 Tag at the specified page (4..nn).

This function writes an NDEF URI record to Type 2 Tag at the specified page (4..nn). It uses adafruit_pn532_tag2_page_write to perform atomic writes.

Parameters
[in]uri_idThe URI identifier code (0 = none, 0x01 = "http://www.", and so on).
[in]p_urlThe URI text to write (null-terminated string).
[in]data_lenThe maximum number of bytes that can be stored in the target device.
Return values
NRF_SUCCESSIf the record was written successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_nfc_a_target_init ( nfc_a_tag_info p_tag_info,
uint16_t  timeout 
)

Function for detecting an ISO14443A (NFC-A) target presence in the RF field.

This function enables the RF field and scans for ISO14443A (NFC-A) targets present in the field. The number of scan retries is set by the adafruit_pn532_passive_activation_retries_set function. By default, the maximum number of retries is set to unlimited, which means that the PN532 Shield scans for targets until it finds one or the scan is canceled. The timeout parameter specifies the time-out of the scan. If it is set to a value greater than 0, the function exits with a failure if either the maximum number of retries or the time-out has been reached. If the timeout parameter is set to 0, a single scan is performed. When the ISO14443A (NFC-A) target is detected, the PN532 module initializes communication and reads the basic initialization information about NFC-A tag including SENS_RES, SEL_RES and UID. This information is retrieved by NFC reader during Technology Detection and Collision Resolution Activities.

Parameters
[in,out]p_tag_infoPointer to the structure where NFC-A Tag basic initialization information will be stored.
[in]timeoutTime-out (in ms). 0 means that only a single scan is performed. If no tag is presented before the time-out, the function returns NRF_ERROR_INTERNAL.
Return values
NRF_SUCCESSIf the function completed successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_passive_activation_retries_set ( uint8_t  max_retries)

Function for setting the MxRtyPassiveActivation parameter of the RFConfiguration register.

This function sets the maximum number of retries when scanning for a tag. The default is an unlimited number of retries.

Parameters
[in]max_retries0xFF to wait forever. 0x00..0xFE to time out after the specified number of retries.
Return values
NRF_SUCCESSIf MxRtyPassiveActivation was set successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_power_down ( void  )

Function for entering power-down mode with I2C as wake-up source.

Return values
NRF_SUCCESSIf power-down mode was entered successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_sam_config ( uint8_t  mode)

Function for configuring the Secure Access Module (SAM).

This function configures the SAM to work in a mode specified in the mode parameter. For a reader operation, use SAMCONFIGURATION_MODE_NORMAL.

Parameters
[in]modeMode in which the PN532 Shield should work.
Return values
NRF_SUCCESSIf the SAM was configured successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_tag2_page_write ( uint8_t  page,
uint8_t *  p_data 
)

Function for writing an entire 4-byte page/block to the Type 2 Tag at the specified page/block address.

This function writes a 4-byte sequence to the Type 2 Tag at the specified page/block, using Type 2 Tag WRITE command.

Parameters
[in]pageThe page/block number to write (0..63 in most cases).
[in]p_dataThe uint8_t array that contains the data to write. The data should be exactly 4 bytes long.
Return values
NRF_SUCCESSIf the data was written successfully. Otherwise, an error code is returned.
ret_code_t adafruit_pn532_tag2_read ( uint8_t  start_page,
uint8_t *  p_buffer 
)

Function for reading 4 pages/blocks within Type 2 Tag, starting with the specified page/block number.

This function reads 4 pages/blocks within Type 2 Tag at the specified page/block number, using Type 2 Tag READ command.

Parameters
[in]start_pageThe page/block number (0..63 in most cases).
[out]p_bufferPointer to the uint8_t array that will hold the retrieved data (if any).
Return values
NRF_SUCCESSIf the data was read successfully. Otherwise, an error code is returned.
void adafruit_pn532_tag_info_printout ( nfc_a_tag_info const *const  p_tag_info)

Function for printing NFC-A Tag Info descriptor.

This function prints NFC-A Tag Info descriptor.

Parameters
[in]p_tag_infoPointer to the NFC-A Tag Info descriptor.
bool adafruit_pn532_waitready_ms ( uint16_t  timeout)

Function for waiting until the PN532 Shield is ready.

Parameters
[in]timeoutTime-out (in ms) before giving up.
Return values
TrueIf the PN532 Shield is ready.
FalseOtherwise.
ret_code_t adafruit_pn532_wake_up ( void  )

Function for waking up the PN532 Shield from power-down mode.

Return values
NRF_SUCCESSIf the PN532 Shield woke up successfully. Otherwise, an error code is returned.

Documentation feedback | Developer Zone | Subscribe | Updated