树莓派使用libnfc驱动ITEAD NFC PN532模块-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 21683|回复: 6

树莓派使用libnfc驱动ITEAD NFC PN532模块

[复制链接]
发表于 2014-6-7 15:36 | 显示全部楼层 |阅读模式
libnfc是首个遵循GNU(自由工程项目)通用公共许可证针对所有人都完全免费的低级别NFC软件开发包和编程应用程序接口。它提供了完整的透明度且免费供大家使用。该库目前支持调制ISO / IEC14443 A和B,FeliCa,Jewel/Topaz标签及数据交换协议(P2P)作为目标和启动程序。想了解更多关于libnfc的信息,可参考http://nfc-tools.org/
ITEAD PN532 NFC模块配有双排引脚,可直接通过排线连接到树莓派,然后树莓派将驱动模块进行非接触式近场通信操作,如读写13.56M IC卡。
1.jpg


以下教程,演示如何在树莓派上使用libnfc通过SPI总线来驱动ITEAD PN532 模块。
1, 硬件链接
Itead PN532 Module是专门为树莓派量身定制的,仅需要排线直接连接就行,如下图
2.jpeg

按照上图的连接方式,Itead PN532 模块是通过SPI总线与树莓派连接的,所以需要把NFC模块的工作模式设置为SPI模式,如下图:
                                                            即 :  SET0-->L   SET1-->H

3.jpg
2,安装依赖的软件包
    sudo apt-get update
    sudo apt-get install libusb-dev libpcsclite-dev

3,下载并解压缩libnfc源码包
    cd ~
    tar -xf libnfc-1.7.1.tar.bz2
   
4,编译与安装
    cd libnfc-1.7.1
    ./configure --prefix=/usr --sysconfdir=/etc
    make
    sudo make install
   
5, 修改配置文件
    cd /etc
    sudo mkdir nfc
    sudo nano /etc/nfc/libnfc.conf
将如下内容复制到/etc/nfc/libnfc.conf文件中:

    # 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"
6,树莓派系统默认是将SPI模块的驱动关闭的,我们需要将其打开;

    sudo nano /etc/modprobe.d/raspi-blacklist.conf
在 “blacklist spi-bcm2708”前添加“#”,变为 “#blacklist spi-bcm2708”,如下图:

Rpi_pn532_3.gif

重启后能在/dev下看到两个spi设备:

Rpi_pn532_4.gif

7, 至此,准备工作已经做完,我们可以用“nfc-list”命令查看是否安装成功。

Rpi_pn532_5.gif

现在,刷个卡试下。。

Rpi_pn532_6.gif
测试OK!
下面再顺便介绍下第二个方法:
如何采用树莓派I2C总线连接的配置方式:
1. 软件配置
树莓派开启I2C总线,将/etc/modprobe.d/raspi-blacklist.conf中“blacklist i2c-bcm2708”变为“#blacklist i2c-bcm2708”
在/etc/modules末尾添加一行 “i2c-dev”
将/etc/nfc/libnfc.conf 文件最后一行改为:“pn532_i2c:/dev/i2c-1”
Rpi_pn532_7.gif

2. 硬件连接,如下图所示:
rpi_pn532_9.gif

刷卡测试,运行效果如图:

rpi_pn532_8.gif

-----------------------------------------------------------------------------------------------
参考资料附录&相关链接:
A6. Iteadstudio PN532 Module 网址 http://imall.iteadstudio.com/im130625002.html
A7. Disable R-Pi/RASPBIAN serial console for using UART0 http://learn.adafruit.com/adafru ... eing-uart-on-the-pi
-------------------------------------------------------------------------------------------------
教程到此结束,谢谢大家!有问题请留言或微博@ITEAD创易工作室

发表于 2014-6-7 18:25 | 显示全部楼层
赞赞赞………………赞赞赞………………赞赞赞………………
发表于 2014-6-8 08:15 | 显示全部楼层
谢谢楼主的精华帖子 爱唯侦察http://www.e2398.com
 楼主| 发表于 2014-6-9 09:13 | 显示全部楼层
智能创客 发表于 2014-6-7 18:25
赞赞赞………………赞赞赞………………赞赞赞………………

谢谢谢.................谢谢谢.................谢谢谢.................
 楼主| 发表于 2014-6-9 09:15 | 显示全部楼层
阳光下→睡意 发表于 2014-6-8 08:15
谢谢楼主的精华帖子 爱唯侦察http://www.e2398.com

分享、学习、进步!
 楼主| 发表于 2014-6-9 12:32 | 显示全部楼层
新鲜出炉,一款开源的可配置的13.56MHz模块:http://www.arduino.cn/thread-5979-1-1.html
发表于 2017-9-8 14:44 | 显示全部楼层
Arduino SPI接线 上传源码后 打开串口监视器 没有数据
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-7-4 11:22 , Processed in 0.086843 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表