Libelium's library
Last updated
Last updated
It is mandatory to include the RFID library when using this module. The following line must be introduced at the beginning of the code:
Waspmote's API RFID/NFC files:
WaspRFID13.cpp
WaspRFID13.h
API functions
Private functions:
The following functions are executed inside the API functions. In normal conditions, the user must NOT manage or use them.
*To avoid the hang of the module this function will wait for 5 seconds approximately. If no tag is detected, the program will continue after this time. The waiting time can be configured in the library.
It is the class constructor. It is only executed inside the API's function init().
Public functions:
The following functions are public and therefore they can be executed in the loop() or setup() functions. They provide the tools to perform all the features of the RFID/NFC module.
This function takes the RFID/NFC module out of the power-down mode by starting the wake up procedure.
If you connected the RFID/NFC module into the usual XBee socket, please use SOCKET0; if you connected the RFID/NFC module into the Expansion Board, you must use SOCKET1.
Example of use:
This function takes the RFID/NFC module to the software power-down mode.
Example of use:
This function initializes the necessary variables, requests if there is an ISO/IEC 14443-A card in the field, does the anti-collision loop and selects the card to operate.
This function is enough for those applications which just require to get the UID of cards, since most of the ISO/IEC 14443-A processes are executed inside.
It is highly advised to execute this function in the beginning of each loop, just as shown in any of the examples. Even if the module is already initialized, it is good to start from the same point every time.
This function initializes many internal registers and variables. All the settings are optimized for the best operation. Changing those settings may result in a defective operation.
Example of use:
This function authenticates a sector of the card thanks to the key or password. It is important to remark that before doing any read or write in a block, it is mandatory to authenticate us in it.
The only exception is the UID, which can be read without authentication; it is returned by the init()
function.
One authentication is enough to validate all the 4 blocks in a sector.
Example of use:
This function reads the 16 bytes stored in a block. This block must have been authenticated before reading.
Example of use:
This function authenticates a block of the card first, and then reads the 16 bytes stored in a block. This function is useful to do these 2 steps in just one.
Example of use:
This function writes 16 bytes in a block. This block must have been authenticated before writing.
Example of use:
This function authenticates a block of the card first, and then writes 16 bytes in the block. This function is useful to do these 2 steps in just one.
Example of use:
This function writes 16 bytes in a block, and then checks the correct data was written. This block must be authenticated before writing. This function is useful to do these 2 steps in just one.
Example of use:
This function authenticates a block of the card first, then writes 16 bytes in the block, and then checks the correct data was written. It is useful to do these 3 steps in just one.
Example of use:
This function authenticates a block of the card first, then sets the new keys A and B, and the access bits for a sector. After that, it authenticates again and reads the trailer block. This function is useful to do these 4 steps in just one.
This function should be executed with care because if any of the internal functions is not successfully executed, then the sector could be damaged or left unaccessible. That is why it is highly recommended to read the output status in order to check if all the process was completed. Please place the card still and close distance from the RFID/NFC module's antenna when setting new keys; if the whole process is not properly completed, the access to that sector might be lost forever.
There are many options for the configuration of the access bits. We suggest to use the same options that the card has by default: {0xFF, 0x07, 0x80, 0x69}. With this configuration:
data blocks must be authenticated with the key A, and then can be read/written
key A can only be changed (written) after an authentication with key A
access bits can be read or written after an authentication with key A
in the sector trailer, the key B has no use and can be read/written after an authentication with key A. It can be used as additional storage space, for instance.
With any configuration, the key A can never be read (the module returns 0's instead of the key) for security reasons. As we can see, the key A of each RFID/NFC card is the master key and we must avoid losing or sharing this information.
Any new card is delivered with the same A and B keys by default: 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF. That is to say, 48 logic 1's.
As shown, the key length is 6 bytes so there are more than 2.8·10¹⁴ different possible passwords.
Example of use:
This function puts the module into Power Down mode in order to save power consumption.
Example of use:
This function wakes up the module from power down mode.
Example of use:
This function is very useful for viewing data content in vectors when you are debugging the code.
Example of use:
This function compares 2 UIDs to check if they are equal. It is useful to check if the UID we have just detected is the same than a predetermined UID. One logic application could be access control for a single person.
Example of use:
This function tests if a certain UID is contained in a set or vector of UIDs. It is useful to check if the UID we have just detected is inside a predetermined set or group of UIDs. One logic application could be access control for a group of people.
Example of use:
This function converts from a string to a pointer to uint8_t's. When we want to write a word or phrase in an RFID card, this function is useful to convert from ASCII code to the format the RFID/NFC module can understand.
Example of use:
This function converts from a pointer to uint8_t's to an integer. When we want to read a number from an RFID card, this function is useful to convert from ASCII code to the format we can understand, an integer.
Example of use:
Function
Brief description
bool configureSAM(void);
set internal parameters of the PN532
sendTX(uint8_t *dataTX, uint8_t length, uint8_t outLength);
Send data stored in dataTX
getACK(void);
Wait for ACK response
waitResponse(void);*
Wait the response of the module
getData(uint8_t outLength);
Get data from the module
checkSum(uint8_t *dataTX);
Calculates the checksum
uint8_t lengthCheckSum(uint8_t *dataTX);
Calculates the length checksum
Function
Brief description
OFF()
switches the module off
ON(socket)
switches the module on, in one of the 2 sockets
init(
UID,
ATQ)
inits the module, configures it and searches for new cards
authenticate(UID, ad, key)
authenticates one card’s sector
bool getFirmware(void)
The PN532 sends back the version of the embedded firmware.
read(ad ,*data)
reads one card’s block
readWithAuth(UID, key, *data, ad)
authenticates one card's sector and reads one block
write(ad, *data)
writes one card’s block
writeWithAuth(UID, key, *data, ad)
authenticates one card's sector and writes one block
writeAndCheck(*data, ad)
writes one card's block and checks that
writeAndCheckWithAuth(UID, key, *data, ad)
authenticates one card's sector, writes one block and checks that
uint8_t powerDown(void)
put the module into Power Down mode
wakeUp(void)
wake up from power dowm mode.
print( *data, length)
print data stored in vectors
setKeys(UID, keyOld, keyA, keyB, cfg, data, ad
changes both keys and access conditions to one card's sector
equalUIDs(UID1, UID2)
compares 2 UIDs
searchUID(vCards, UID, nCards)
searches one UID inside one group of UIDs
string2vector(inp, outp)
converts from a string to a uint8_t vector
vector2int(*inp)
converts from a uint8_t vector to a integer