libnfc is the first libre low level NFC SDK and Programmers API released under the GNU Lesser General Public License. It provides complete transparency and royalty-free use for everyone. The library currently supports modulations for ISO/IEC 14443 A and B, FeliCa, Jewel/Topaz tags and Data Exchange Protocol (P2P) as target and as initiator. For more information, you can refer to http://nfc-tools.org/
The following tutorial demonstrates how to use libnfc on Raspberry Pi to drive ITEAD PN532 module with the SPI bus.
1, Hardware connection
As Itead PN532 Module is customized for Raspberry Pi, it can be connected directly to Raspberry Pi via the adapter cable as shown in picture below

According to the connection in the picture above, Itead PN532 Module is connected via the SPI bus with raspberry pie, therefore, operating mode of PN532 Module should be set to SPI mode, as shown below:
Code: Select all
SET0-->L
SET1-->H
2, Install the software pack needed
Code: Select all
sudo apt-get update
sudo apt-get install libusb-dev libpcsclite-devCode: Select all
cd ~
wget http://dl.bintray.com/nfc-tools/sources/libnfc-1.7.1.tar.bz2
tar -xf libnfc-1.7.1.tar.bz2 Code: Select all
cd libnfc-1.7.1
./configure --prefix=/usr --sysconfdir=/etc
make
sudo make install Code: Select all
cd /etc
sudo mkdir nfc
sudo nano /etc/nfc/libnfc.confCode: Select all
# Allow device auto-detection (default: true)
# Note: if this auto-detection is disabled, user has to set manually a device
# configuration using file or environment variable
allow_autoscan = true
# Allow intrusive auto-detection (default: false)
# Warning: intrusive auto-detection can seriously disturb other devices
# This option is not recommended, user should prefer to add manually his device.
allow_intrusive_scan = false
# Set log level (default: error)
# Valid log levels are (in order of verbosity): 0 (none), 1 (error), 2 (info), 3 (debug)
# Note: if you compiled with --enable-debug option, the default log level is "debug"
log_level = 1
# Manually set default device (no default)
# To set a default device, you must set both name and connstring for your device
# Note: if autoscan is enabled, default device will be the first device available in device list.
device.name = "Itead_PN532_SPI"
device.connstring = "pn532_spi:/dev/spidev0.0:500000"Code: Select all
sudo nano /etc/modprobe.d/raspi-blacklist.confAs shown in the picture below

You can see two spi devices under /dev after rebooting.

7, Up to now, preparations are done. And then we can use command nfc-list to check if it is successfully installed.

Let's try swiping the card.

8, Configurations for connection via I2C bus
8.1 Software configuration
Enable I2C bus on Raspberry Pi, and change blacklist i2c-bcm2708 in /etc/modprobe.d/raspi-blacklist.conf to #blacklist i2c-bcm2708
Add i2c-dev at the end of /etc/modules
Modify last line of /etc/nfc/libnfc.conf to pn532_i2c:/dev/i2c-1 as shown in the picture below

8.2 Hardware connection
Connection is as shown in the picture below:

Running result is as shown in the picture below:

Appendix: related links
A1. libnfc configuration method: http://nfc-tools.org/index.php?title=Li ... figuration
A2. libnfc installation tutorial: http://nfc-tools.org/index.php?title=Libnfc
A3. libnfc user API: http://nfc-tools.org/index.php?title=Libnfc:API
A4. libnfc main page: http://nfc-tools.org/index.php?title=Main_Page
A5. libnfc tutorial: http://nfc-tools.org/index.php?title=Ca ... c:Examples
A6. Iteadstudio PN532 Module website: http://imall.iteadstudio.com/im130625002.html
A7. Disable R-Pi/RASPBIAN serial console for using UART0: http://learn.adafruit.com/adafruit-nfc- ... -on-the-pi
Note: this post is reprinted from http://blog.iteadstudio.com/raspberry-p ... th-libnfc/
