TA的每日心情 | 开心 2016-8-15 09:30 |
---|
签到天数: 162 天 连续签到: 1 天 [LV.7]常住居民III
|
ITEAD PN532 NFC模块上带了双排插针,可以通过连接线直接连接到树莓派上,然后使用我们提供的ITEAD PN532 NFC SPI Library来驱动模块进行无接触的近场通讯操作,比如读写13.56M的IC卡。
首先,在安装我们提供的库之前,我们要对树莓派的配置进行一些修改,使SPI模块可以开机自启动:
cd /etc/modprobe.d/
进入配置文件夹
sudo nano raspi-blacklist.conf
以超级用户打开配置文件
#blachlist sip-bcm2708
注释掉该行,实现SPI模块开机加载
然后,就可以解压我们提供的库,我们以放置到桌面为例:
cd /home/pi/Desktop/ITEAD_PN532_NFC
进入库文件夹
make install
安装ITEAD PN532 NFC库这样我们的库就已经编译安装完成了,之后如果需要使用到这个库,只要在工程文件中包含进nfc.h即可调用库里的各函数。编译时,在命令行中添加-lNFC就可以将这些调用的库函数编译处理了。
以我们库里提供的DEMO为例子:
gcc readID.c –o readID –lNFC
编译readID例程文件
sudo ./readID
运行编译完的例程文件 – 这样,只要将13.56M的IC卡靠近NFC模块,就会在显示器上显示出这张卡的ID号了。
下面这个库提供的一些功能函数的简单说明:
FUNCTIONS:
Begin(): Begin to communicate with the ITEAD NFC module
Parameters:NULL
Return:NULL
Usage:begin();
SAMConfig(): Configure RPI to read RFID tags and cards
Parameters:NULL
Return: false or true
Usage:SAMConfig();
getFirmwareVersion(): Get the firmware version of the NFC module
Parameters:NULL
Return: the number of the firmware version(fail will return 0);
Usage: I = getFirmwareVersion();
readPassiveTargetID(uint8_t cardbaudrate): Get the passive target card ID
Parameters: cardbaudrate;
Return: the ID of the card(fail will return 0);
Usage: I = readPassiveTargetID(PN532_MIFARE_ISO14443A);
authenticateBlock(cardnumber, cid, blockaddress, authtype, * keys): Authenticate the block
Authenticate the block
authenticateBlock(cardnumber, cid, blockaddress, authtype, * keys)
Parameters:
-uint8_t cardnumber: 1 or 2;
-uint32_t cid: Card NUID;
-uint8_t blockaddress:0 to 63;
-uint8_t authtype: Either KEY_A or KEY_B;
-uint8_t * keys
Return: true or false;
Usage: authenticateBlock(1,id,0x08,KEY_A,keys);
readMemoryBlock(cardnumber, blockaddress, block): Read a block(16 bytes) from the tag and stores in the parameter
Parameter:
-uint8_t cardnumber, can be 1 or 2;
-blockaddress, range from 0 to 63;
-uint8_t* block, will save 16bytes that read from tag.
Return: true or false
Usage: readMemoryBlock(1,0x08,block);
writeMemoryBlock( cardnumber, blockaddress, * block): Write a block(16 bytes) to the tag
Parameter:
-uint8_t cardnumber,can be 1 or 2;
-blockaddress,range from 0 to 63;
-uint8_t* block,saves 16bytes that will write to the tag.
Return: true or false
Usage: writeMemoryBlock(1,0x08,writeBuffer);
|
|