Adafruit PN532 NFC Shield library for reading and writing tags.
More...
|
#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 |
|
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 for reading the ACK frame.
- Return values
-
NRF_SUCCESS | If 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_cmd | Pointer to the command buffer. |
[in] | cmd_len | The length of the command (in bytes). |
[in] | timeout | Time-out (in ms) before giving up. |
- Return values
-
NRF_SUCCESS | If 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_cmd | Pointer to the command buffer. |
[in] | cmd_len | Command length in bytes. |
- Return values
-
NRF_SUCCESS | If 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_buff | Pointer to the buffer where the data will be written. |
[in] | n | Number of bytes to read. |
- Return values
-
NRF_SUCCESS | If the data was read successfully. Otherwise, an error code is returned. |
Function for disabling the PN532 RF field.
- Return values
-
NRF_SUCCESS | If the RF field was disabled successfully. Otherwise, an error code is returned. |
Function for enabling the PN532 RF field.
- Return values
-
NRF_SUCCESS | If 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_response | The chip's firmware version and ID. |
- Return values
-
NRF_SUCCESS | If the function completed successfully. Otherwise, an error code is returned. |
Function for creating a new PN532 object using I2C.
Before calling this function, PN532_IRQ and PN532_RESET must be configured.
- Return values
-
NRF_SUCCESS | If 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_send | Pointer to the data to send. |
[in] | send_len | Length of the data to send. |
[out] | p_response | Pointer to the buffer for response data. |
[in,out] | p_response_len | Pointer 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_SUCCESS | If the function completed successfully. Otherwise, an error code is returned. |
Function for initializing the communication with the Adafruit PN532 Shield.
- Note
- This library is not thread-safe, because it uses static buffers.
- Parameters
-
[in] | force | If true, reinitialization of the library will be forced. |
- Return values
-
NRF_SUCCESS | If 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
-
True | If the PN532 Shield is ready with a response. |
False | Otherwise. |
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_id | The URI identifier code (0 = none, 0x01 = "http://www.", and so on). |
[in] | p_url | The URI text to write (null-terminated string). |
[in] | data_len | The maximum number of bytes that can be stored in the target device. |
- Return values
-
NRF_SUCCESS | If the record was written successfully. Otherwise, an error code is returned. |
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_info | Pointer to the structure where NFC-A Tag basic initialization information will be stored. |
[in] | timeout | Time-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_SUCCESS | If 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_retries | 0xFF to wait forever. 0x00..0xFE to time out after the specified number of retries. |
- Return values
-
NRF_SUCCESS | If MxRtyPassiveActivation was set successfully. Otherwise, an error code is returned. |
Function for entering power-down mode with I2C as wake-up source.
- Return values
-
NRF_SUCCESS | If 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] | mode | Mode in which the PN532 Shield should work. |
- Return values
-
NRF_SUCCESS | If 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] | page | The page/block number to write (0..63 in most cases). |
[in] | p_data | The uint8_t array that contains the data to write. The data should be exactly 4 bytes long. |
- Return values
-
NRF_SUCCESS | If 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_page | The page/block number (0..63 in most cases). |
[out] | p_buffer | Pointer to the uint8_t array that will hold the retrieved data (if any). |
- Return values
-
NRF_SUCCESS | If 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_info | Pointer 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] | timeout | Time-out (in ms) before giving up. |
- Return values
-
True | If the PN532 Shield is ready. |
False | Otherwise. |
Function for waking up the PN532 Shield from power-down mode.
- Return values
-
NRF_SUCCESS | If the PN532 Shield woke up successfully. Otherwise, an error code is returned. |