Adafruit PN532 NFC Shield library for reading and writing tags.
More...
|
struct | adafruit_pn532 |
| Information about the communication between the host and the Adafruit PN532 Shield. More...
|
|
|
void | print_hex (const uint8_t *p_data, const uint32_t len) |
| Function for printing data in hexadecimal format. More...
|
|
void | print_hex_char (const uint8_t *p_data, const uint32_t len) |
| Function for printing a character in hexadecimal format. More...
|
|
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 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. |
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_get_firmware_version |
( |
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. |
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_ntag2xx_read_page |
( |
uint8_t |
page, |
|
|
uint8_t * |
p_buffer |
|
) |
| |
Function for reading an entire 4-byte page at the specified address.
This function reads 4 bytes from the chosen page.
- Parameters
-
[in] | page | The page 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. |
ret_code_t adafruit_pn532_ntag2xx_write_ndef_uri |
( |
uint8_t |
uri_id, |
|
|
char * |
p_url, |
|
|
uint8_t |
data_len |
|
) |
| |
Function for writing an NDEF URI record starting at the specified page (4..nn).
This function assumes that the NTAG2xx card is already formatted to work as an NFC Forum Tag.
- 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. |
ret_code_t adafruit_pn532_ntag2xx_write_page |
( |
uint8_t |
page, |
|
|
uint8_t * |
p_data |
|
) |
| |
Function for writing an entire 4-byte page at the specified block address.
This function writes a 4-byte sequence to the specified page.
- Parameters
-
[in] | page | The page 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. |
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. |
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_read_data |
( |
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. |
ret_code_t adafruit_pn532_read_passive_target_id |
( |
uint8_t |
card_baudrate, |
|
|
uint8_t * |
p_uid, |
|
|
uint8_t * |
p_uid_len, |
|
|
uint16_t |
timeout |
|
) |
| |
Function for detecting an ISO14443A target presence in the RF field.
This function enables the RF field and scans for ISO14443A targets present in the field. The number of scan retries is set by the adafruit_pn532_set_passive_activation_retries 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 target is detected, the PN532 module initializes communication and reads the target's UID.
- Parameters
-
[in] | card_baudrate | Baud rate of the card. |
[out] | p_uid | Pointer to the array that will be populated with the card's UID (up to 7 bytes). |
[in,out] | p_uid_len | Pointer to the variable that stores the length of the p_uid buffer (as input) and the length of the target's UID that was read (as output). |
[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_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_send_cmd |
( |
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_set_passive_activation_retries |
( |
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. |
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. |
ret_code_t adafruit_pn532_write_command |
( |
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. |
void print_hex |
( |
const uint8_t * |
p_data, |
|
|
const uint32_t |
len |
|
) |
| |
Function for printing data in hexadecimal format.
- Parameters
-
[in] | p_data | Pointer to the first byte of data to be printed. |
[in] | len | Data length in bytes. |
void print_hex_char |
( |
const uint8_t * |
p_data, |
|
|
const uint32_t |
len |
|
) |
| |
Function for printing a character in hexadecimal format.
This function prints a hexadecimal value along with the char equivalents in the following format:
00 00 00 00 00 00 ......
- Parameters
-
[in] | p_data | Pointer to the first byte of data to be printed. |
[in] | len | Data length in bytes. |