Adafruit PN532 RFID/NFC Breakout and Shield Created by lady ada Last updated on 2018-08-22 03:32:52 PM UTC
Guide Contents Guide Contents Overview Breakout Wiring 2 4 5 Wiring the Breakout for SPI 5 Shield Wiring 9 Solder the Headers Using the Adafruit NFC Shield with I2C Using with the Arduino Leonardo and Yun Arduino Library Which Library? Library Installation Testing MiFare 10 12 12 12 13 About NFC 14 NFC (Near Field Communication) Passive Communication: ISO14443A Cards (Mifare, etc.
Smart Poster Records Example NDEF Records Using Mifare Classic Cards as an NDEF Tag Mifare Application Directory (MAD) Mifare Application Directory 1 (MAD1) Mifare Application Directory 2 (MAD2) MAD Sector Access Storing NDEF Messages in Mifare Sectors TLV Blocks Memory Dump of a Mifare Classic 1K Card with an NDEF Record NDEF Records 26 26 27 27 27 28 28 28 28 29 31 Using with LibNFC 33 Using the PN532 Breakout Boards with libnfc 33 libnfc In Linux (Ubuntu 10.
Overview Hey! So this is not a full tutorial, its just a quickstart guide while we do more research into RFID/NFC. There's a lot of info here but not everything is explained in detail. We hope to fill out the tutorial but there's not a lot of good information about NFC so it's taking a bit of time! © Adafruit Industries https://learn.adafruit.
Breakout Wiring This part of the tutorial is specifically for the Breakout board. We show how to use it with SPI. The breakout also supports TTL serial and I2C but we don't have a tutorial for using it that way as SPI is the most cross-platform method to communicate If you're using the shield, check the next page Wiring the Breakout for SPI The PN532 chip and breakout is designed to be used by 3.3V systems.
© Adafruit Industries https://learn.adafruit.
Solder the two small pieces to the SEL0 and SEL1 pads. These are interface selectors for the chip. Depending on how the jumpers are inserted the chip will talk in TTL serial, i2c or SPI. Also solder a strip to the end so you can plug it into a breadboard. Wire up the 4050 level shifter chip to the Arduino as shown. The notch in the 4050 is at the 'top' in this image.
MOSI is connected to 4050 pin 12 (yellow wire) SSEL is connected to 4050 pin 15& (green wire) GND connects to Arduino ground (black wire) Also connect 4050 pin #1 to 3.3V and pin #8 to ground. Click to see a larger image. The red power wire should be connected to the 3.3v pin on the Arduino! Also, we need to select SPI as the interface so on SEL1 place the jumper in the ON position. for SEL0 place the jumper in the OFF position.
Shield Wiring Solder the Headers The first step is to solder the headers to the shield. Cut the header strip to length and insert the sections (long pins down) into an Arduino. Then place the shield on top and solder each pin. Using the Adafruit NFC Shield with I2C © Adafruit Industries https://learn.adafruit.
Using the Adafruit NFC Shield with I2C The Adafruit NFC shield is designed to be used using the I2C by default. I2C only uses two pins (Analog 4 and 5 which are fixed in hardware and cannot be changed) to communicate and one pin as an 'interrupt' pin (Digital 2 - can be changed however). What is nice about I2C is that it is a 'shared' bus - unlike SPI and TTL serial - so you can put as many sensors as you'd like all on the same two pins, as long as their addresses don't collide/conflict.
© Adafruit Industries https://learn.adafruit.
Arduino Library Which Library? In the past there were two separate Arduino libraries for using the Adafruit NFC boards. One library supported the breakout over a SPI connection, and the other library supported the breakout or shield over an I2C connection. However both of these libraries have been merged into a single Arduino library, Adafruit-PN532 (https://adafru.it/eHi).
// Uncomment just _one_ line below depending on how your breakout or shield // is connected to the Arduino: // Use this line for a breakout with a SPI connection: //Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS); // Use this line for a breakout with a hardware SPI connection. Note that // the PN532 SCK, MOSI, and MISO pins need to be connected to the Arduino's // hardware SPI SCK, MOSI, and MISO pins. On an Arduino Uno these are // SCK = 13, MOSI = 11, MISO = 12.
About NFC NFC (Near Field Communication) NFC (Near Field Communication) is a set of short-range (typically up to 10cm) wireless communication technologies designed to offer light-weight and secure communication between two devices. While NFC was invented by NXP (Phillips at the time), Nokia and Sony, the main body behind the NFC 'standard' today is the NFC Forum (https://adafru.it/aSy), who are responsible for publishing and maintaining a variety of standards relating to NFC technology. NFC operates at 13.
accepting a license agreement to download (https://adafru.it/aSA). The NDEF format is used to store and exchange information like URIs, plain text, etc., using a commonly understood format. NFC tags like Mifare Classic cards can be configured as NDEF tags, and data written to them by one NFC device (NDEF Records) can be understood and accessed by any other NDEF compatible device. NDEF messages can also be used to exchange data between two active NFC devices in "peer-to-peer" mode.
MiFare Cards & Tags MiFare is one of the four 13.56MHz card 'protocols' (FeliCa is another well known one) All of the cards and tags sold at the Adafruit shop use the inexpensive and popular MiFare Classic chipset MiFare Classic Cards MIFARE Classic cards come in 1K and 4K varieties. While several varieties of chips exist, the two main chipsets used are described in the following publicly accessible documents: MF1S503x Mifare Classic 1K data sheet (https://adafru.
Sector Trailer (Block 3) The sector trailer block contains the two secret keys (Key A and Key B), as well as the access conditions for the four blocks. It has the following structure: Sector Trailer Bytes -------------------------------------------------------------0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [ Key A ] [Access Bits] [ Key B ] For more information in using Keys to access the clock contents, see Accessing Data Blocks further below. Data Blocks (Blocks 0..
32 15 14 13 ... 2 1 0 [-------KEY A-------] [ [ [Access Bits] Data Data [ [ [ [-------KEY B-------] ] ] Data Data Data ] ] ] Sector Trailer 32 Data Data Data Data Data Accessing EEPROM Memory To access the EEPROM on the cards, you need to perform the following steps: 1. You must retrieve the 4-byte NUID of the card (this can sometimes be 7-bytes long as well, though rarely for Mifare Classic cards). This is required for the subsequent authentication process. 2.
Block 8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 9 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 11 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF ......ÿ.?iÿÿÿÿÿÿ ------------------------Sector 3------------------------Block 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
------------------------Sector 14------------------------Block 56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 58 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 59 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF ......ÿ.?iÿÿÿÿÿÿ ------------------------Sector 15------------------------Block 60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Page ----0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Block 0 Block 1 Block 2 Block 3 --------------------------------------[ Serial Number ] [ Serial Number ] [Serial] - [Intern] - [ Lock Bytes ] [ One Time Programmable Memory ] [ User Data ] [ User Data ] [ User Data ] [ User Data ] [ User Data ] [ User Data ] [ User Data ] [ User Data ] [ User Data ] [ User Data ] [ User Data ] [ User Data ] Lock Bytes (Page 2) Bytes 2 and 3 of page 2 are referred to as "Lock Bytes".
corresponds to block size of a Mifare Classic card). For example, if you specify that you want to read page 3, in reality pages 3, 4, 5 and 6 will be read and returned, and you can simply discard the last 12 bytes if they aren't needed. If you select a higher page, the 16 byte read will wrap over to page 0. For example, reading page 14 will actually return page 14, 15, 0 and 1. "Write" requests occur in pages (4 bytes), so there is no problem with overwriting data on subsequent pages.
About the NDEF Format NDEF (NFC Data Exchange Format) The NFC Data Exchange Format (NDEF) is a standardised data format that can be used to exchange information between any compatible NFC device and another NFC device or tag. The data format consists of NDEF Messages and NDEF Records. The standard is maintained by the NFC Forum and is freely available for consultation but requires accepting a license agreement to download (https://adafru.it/aSA).
TNF: Type Name Format Field The Type Name Format or TNF Field of an NDEF record is a 3-bit value that describes the record type, and sets the expectation for the structure and content of the rest of the record. Possible record type names include: TNF Value --------0x00 Record Type ----------------------------------------Empty Record Indicates no type, id, or payload is associated with this NDEF Record.
Payload Length Indicates the length (in bytes) of the record payload. If the SR field (described above) is set to 1 in the record header, this value will be one byte long (for a payload length from 0-255 bytes). If the SR field is set to 0, this value will be a 32bit value occupying 4 bytes. ID Length Indicates the length in bytes of the ID field. This field is present only if the IL flag (described above) is set to 1 in the record header.
Value ----0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1A 0x1B 0x1C 0x1D 0x1E 0x1F 0x20 0x21 0x22 0x23 Protocol -------No prepending is done ... the entire URI is contained in the URI Field http://www. https://www. http:// https:// tel: mailto: ftp://anonymous:anonymous@ ftp://ftp.
URI Record An example of a URI record is shown in "Memory Dump of a Mifare Classic 1K Card with an NDEF Record" below. Text Record To Do Smartposter Record To Do Absolute URI Record To Do Using Mifare Classic Cards as an NDEF Tag Mifare Classic 1K and 4K cards can be configured as NFC Forum compatible NDEF tags, but they must be organised in a certain manner to do so.
The MAD1 is stored in the Manufacturer Sector (Sector 0x00) on the Mifare Classic card. Mifare Application Directory 2 (MAD2) MAD2 can only be used on Mifare Classic cards with more than 1KB of storage (Mifare Classic 4K cards, etc.). It is NOT compatible with cards containing only 1KB of memory! The MAD2 is stored in sectors 0x00 (the Manufacturer Sector) and 0x10.
TLV Block Types Block Type ------------NULL NDEF Message Proprietary Terminator Value ----0x00 0x03 0xFD 0xFE Description -------------------------------------These blocks should be ignored Block contains an NDEF message Block contains proprietary information Last TLV block in the data area Length Field The Length Field (or L Field) contains the size (in bytes) of the value field. The Length Field can be organised in two different ways, using either one or three bytes.
Block 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 15 00 00 00 00 00 00 7F 07 88 40 00 00 00 00 00 00 .......?@...... ------------------------Sector 4------------------------Block 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 17 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ Block 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Block 61 00 00 00 00 00 00 00 00 00 00 Block 62 00 00 00 00 00 00 00 00 00 00 Block 63 00 00 00 00 00 00 7F 07 88 40 [ End of Memory 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Dump ................ ................ .......?@...... ] NDEF Records The above example contains two records, both located in sector 1 (sector 0 contains the MAD). Record 1 The first record on the card can be identified by looking at the first byte of block 4 in sector 1.
Byte(s) ------04:04 Value ----0xD1 04:05 0x01 04:06 04:07 04:08 0x0D 0x55 0x01 04:09..05:04 ... Description ----------This byte is the **NDEF Record Header**, and indicates that this is an NFC Forum Well Known Record (0x01 in the first 3 bits), and that this is the first and last record (MB=1, ME=1), and that this is a short record (SR = 1) meaning the payload length is less than or equal to 255 chars (len=one byte).
Using with LibNFC libnfc is a constantly moving target, and due to the frequent changes from one version to the next we aren't able to offer libnfc support ourselves for the PN532. We can only guarantee support and working code for the Arduino codebase that we maintain ourselves.
Step Three: Build and install libnfc You can build and install libnfc with the following three commands, also run from the folder where the original archive was unzipped: $ make clean $ make $ make install Step Four: Check for installed devices Now that libnfc is (hopefully) built and installed, you can run the 'nfc-list' example to try to detect an attached NFC board.
libnfc With Mac OSX Lion scott-42 was kind of enough to post some tips on getting libnfc working on a Mac using an FTDI adapter. A couple simple changes to the code were required (as of v1.6.0-rc1), with the details here (https://adafru.it/aP1). Keeping in mind the code changes mentionned above, the following steps should get libnfc compiling and working via an FTDI type adapter and UART on Lion (using libnfc 1.6.
There are some dependencies to get libnfc running, but since it isn't an Adafruit project and we can't really support it directly ourselves, you will probably have better luck looking at the libnfc forums (https://adafru.it/aST) for Mac support. There are a few active users developping on the Mac. © Adafruit Industries https://learn.adafruit.
FAQ Some of the more common questions on the forums related to the PN532 NFC/RFID Breakout (http://adafru.it/364) and NFC Shield (http://adafru.it/789).
implementation is non trivial and would require us to charge a significant premium for these boards if we implemented this. We've focused our energy on providing a reliable, proven, properly-tuned HW reference, and enough of a SW building block to get everyone started, but there are too many holes to fill in to cover everything NFC can do with a development board at this price point.
void setup(void) { Serial.begin(115200); Serial.println("Hello!"); nfc.begin(); uint32_t versiondata = nfc.getFirmwareVersion(); if (! versiondata) { Serial.print("Didn't find PN53x board"); while (1); // halt } // Got ok data, print it out! Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); Serial.print('.'); Serial.
Hey wait ... isn't there something funny with the SVDD pin? Indeed, good eye! Unfortunately, both v1.0 and v1.3 of the breakout boards have a problem on the schematic. SVDD is connected directly to VDD, but should be left floating since it is used to power secure modules. This has no effect on the functionality of the boards, but does cause some extra current to be drawn.
Downloads Files SPI and I2C library is available from github (https://adafru.it/aSX) Deprecated I2C-only library is available from github (don't recommend) (https://adafru.it/aSW) Fritzing objects available in the Adafruit Fritzing library (https://adafru.it/aP3) EagleCAD PCB files for the Shield at https://github.com/adafruit/Adafruit-PN532-RFID-NFC-Shield (https://adafru.it/dik) EagleCAD PCB files for the Breakout at https://github.com/adafruit/Adafruit-PN532-RFID-NFCBreakout (https://adafru.
Version 1.3 schematic (click to enlarge) https://adafru.it/d7l https://adafru.