PN532 V3 + Arduino UNO + libnfc 错误(错误:无法打开 NFC 设备:pn532_uart:/dev/ttyUSB0:115200)

Posted

技术标签:

【中文标题】PN532 V3 + Arduino UNO + libnfc 错误(错误:无法打开 NFC 设备:pn532_uart:/dev/ttyUSB0:115200)【英文标题】:PN532 V3 + Arduino UNO + libnfc error (ERROR: Unable to open NFC device: pn532_uart:/dev/ttyUSB0:115200) 【发布时间】:2020-03-20 20:58:56 【问题描述】:

我正在尝试将 PN532 (v3) 板与 Arduino UNO 和 libnfc 一起用于我的大学项目。我偶然发现的一个问题是,当我调用 nfc-list 时,libnfc-1.7.1 给了我以下错误:

debug   libnfc.general  log_level is set to 3
    debug   libnfc.general  allow_autoscan is set to false
    debug   libnfc.general  allow_intrusive_scan is set to false
    debug   libnfc.general  1 device(s) defined by user
    debug   libnfc.general    #0 name: "PN532 NFC Board on Arduino", connstring: "pn532_uart:/dev/ttyUSB0:115200"
    nfc-list uses libnfc 1.7.1
    debug   libnfc.driver.pn532_uart    Attempt to open: /dev/ttyUSB0 at 115200 bauds.
    debug   libnfc.bus.uart Serial port speed requested to be set to 115200 bauds.
    debug   libnfc.chip.pn53x   Diagnose
    debug   libnfc.chip.pn53x   Timeout value: 500
    debug   libnfc.bus.uart TX: 55 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    debug   libnfc.chip.pn53x   SAMConfiguration
    debug   libnfc.chip.pn53x   Timeout value: 1000
    debug   libnfc.bus.uart TX: 00 00 ff 03 fd d4 14 01 17 00 
    debug   libnfc.bus.uart Timeout!
    debug   libnfc.driver.pn532_uart    Unable to read ACK
    error   libnfc.driver.pn532_uart    pn53x_check_communication error
    debug   libnfc.chip.pn53x   InRelease
    debug   libnfc.bus.uart TX: 00 00 ff 03 fd d4 52 00 da 00 
    debug   libnfc.bus.uart Timeout!
    debug   libnfc.driver.pn532_uart    Unable to read ACK
    debug   libnfc.general  Unable to open "pn532_uart:/dev/ttyUSB0:115200".
    nfc-list: ERROR: Unable to open NFC device: pn532_uart:/dev/ttyUSB0:115200

我在使用带有 Arduino 的阅读器时没有任何问题,我可以上传草图并且阅读器与标签进行交互。阅读器处于 SPI 模式,当我调用 nfc-list 时,LED 会闪烁,因此我唯一能想到的就是 libnfc 的某种问题。

我希望有人可以提供帮助,任何建议都会很棒! :) 谢谢!

连接

PN532 V3

Arduino.1

Arduino.2

文件配置

/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 = false

    # 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 = 3

    # 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 = "PN532 NFC Board on Arduino"
    device.connstring = "pn532_uart:/dev/ttyUSB0:115200"

uartnfc.info

#include <PN532.h>

          #define SCK 13
          #define MOSI 11
          #define SS 10
          #define MISO 12

          PN532 nfc(SCK, MISO, MOSI, SS);

          uint8_t buffer[32];



          void setup(void) 
              Serial.begin(115200); //460800, 115200
              Serial.flush();
              nfc.begin();
          

          void loop(void) 

              int b = Serial.available();
              if (b >= 5)
                  Serial.readBytes((char*)buffer, 5);
                  if(buffer[0] == 0x55)
                      //handle wake up case
                      while(Serial.available() < 5); //wait the command
                      b = Serial.readBytes((char*)buffer+5, 5);
                      //send raw command to pn532
                      //get length of package : 
                      // (PREAMBLE + START + LEN + LCS) + (TFI + DATA[0...n]) + (DCS + POSTAMBLE)
                      uint8_t l = buffer[8] + 2;
                      while(Serial.available() < l); //wait the command
                      //read command from uart
                      Serial.readBytes((char*)buffer+10, l);
                      //send raw command to pn532
                      nfc.sendRawCommandCheckAck(buffer, l+10);
                      //read pn532 answer
                      nfc.readRawCommandAnswer(buffer, l+10);
                  else
                      //normal case
                      //get length of package : 
                      // (PREAMBLE + START + LEN + LCS) + (TFI + DATA[0...n]) + (DCS + POSTAMBLE)
                      uint8_t l = buffer[3] + 2;
                      //read command from uart

                      //while(Serial.available() < l); //wait the command
                      //Serial.readBytes((char*)buffer+5, l);

                      uint8_t br = l;
                      uint8_t* bufptr = buffer + 5;
                      while(br)
                          if(Serial.available())
                              *bufptr++ = Serial.read();
                              --br;
                          
                     

                      //send raw command to pn532
                      nfc.sendRawCommandCheckAck(buffer, l+5);
                      //read pn532 answer
                      nfc.readRawCommandAnswer(buffer, l+5);
                  
              

          

使用的资源

http://nfc-tools.org/index.php/Libnfc:Arduino - 用于安装 libnfchttps://github.com/gunmetal313/mfocuino - 上传草图 uartnfc.ino 并导入库 (mfocuino/mfocuino-read-only/nfcreader/arduino /libraries/PN532/) 进入 Arduino IDE。

我已经尝试解决的问题

Why "No NFC device found" with libnfc and PN532 SHIELD PN532 Unable to open NFC devicehttps://github.com/nfc-tools/libnfc/issues/507https://forums.adafruit.com/viewtopic.php?f=19&t=58188https://superuser.com/questions/1409108/nfc-unable-to-open-nfc-device

【问题讨论】:

【参考方案1】:

我几乎放弃了同样的问题。对我来说,在 Arduino Sketch 和 libnfc 配置中使用 9600 波特时,它终于奏效了。

【讨论】:

以上是关于PN532 V3 + Arduino UNO + libnfc 错误(错误:无法打开 NFC 设备:pn532_uart:/dev/ttyUSB0:115200)的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Python 中从 PN532 读取标签?

ESP32 无法检测到 PN532 NFC 模块

IC卡解密工具 PN532工具XP 爆破版 By:lookyour

IC卡解密从零开始学1 (也许会有2) 解密工具V2 V3大放送 By:lookyour

PN532 卡模拟模式

求助:Arduino UNO(如下图)有三种供电方式:USB供电,5v(供给芯片,下面一排接口中“