PN532 NFC Card-Reading Demo
1 Demo overview
This demo shows how to use a PN532 NFC card over the 40-pin Raspberry Pi header to read a card ID.
2 Module overview
The PN532 NFC HAT is an NFC expansion board designed for the Raspberry Pi. It uses the PN532 controller and supports I2C, SPI, and serial communication, adding NFC communication capability to the Raspberry Pi.

3 Mode switching
3.1 Serial communication mode
Use jumper caps to set I0 = L and I1 = L. Use a jumper cap to connect RSTPDN -> D20. Set the DIP switches as shown:


3.2 SPI communication mode
Use jumper caps to set I0 = L and I1 = H. Use a jumper cap to connect RSTPDN -> D20. Set the DIP switches as shown:


3.3 I2C communication mode
Use jumper caps to set I0 = H and I1 = L. Use a jumper cap to connect RSTPDN -> D20, and connect INT0 -> D16 (to avoid clock stretching). Set the DIP switches as shown:


4 Procedure
4.1 Serial communication mode
Open a terminal and copy the executable smdt_nfc_demo from this demo's bin directory (05-Development Materials\Software Development Materials\linux_demo\smdt_nfc_demo\bin) to the board's filesystem (the source code is available under the src path).
In the terminal, run the following commands to switch to the directory containing the smdt_nfc_demo executable.
#切换到 smdt_nfc_demo 可执行程序所在目录
cd ‘可执行文件所在目录’
#查看 smdt_nfc_demo 是否在该目录下
lsIf the executable smdt_nfc_demo is in the current directory, change its permissions.
#添加可执行权限
chmod +x smdt_nfc_demo
#查询是否修改成功
ls -ld smdt_nfc_demoAfter confirming the permission change succeeded, run ./smdt_nfc_demo -h to view the program's help information. Some default parameters set in this test script are as follows:
- device: /dev/ttyS3 (i.e. UART3)
#查看帮助信息
./smdt_nfc_demo -hThe result is shown below:

Run the following commands to switch modes.
#PN532 NFC唤醒模式
./smdt_nfc_demo -w
#RPN532 读卡ID模式
./smdt_nfc_demo -rRunning ./smdt_nfc_demo -w enters the PN532 NFC module wake-up mode and returns the wake-up response frame. The result is shown below:
Press Ctrl+Z to force-exit this mode.

Running ./smdt_nfc_demo -r enters the PN532 NFC module card-ID reading mode; after a card ID is read, the corresponding response frame is displayed in the terminal. The result is shown below:
Press Ctrl+Z to force-exit this mode.

