1

我正在尝试将 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 - 用于安装 libnfc
https://github.com/gunmetal313/mfocuino - 上传草图uartnfc.ino并导入库(mfocuino/mfocuino-read -only/nfcreader/arduino/libraries/PN532/ ) 进入 Arduino IDE。

我已经尝试解决问题的事情

为什么使用 libnfc 和 PN532 SHIELD PN532“找不到 NFC 设备”
无法打开 NFC 设备
https://github.com/nfc-tools/libnfc/issues/507
https://forums.adafruit.com/viewtopic.php?f =19&t=58188
https://superuser.com/questions/1409108/nfc-unable-to-open-nfc-device

4

1 回答 1

0

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

于 2020-11-02T21:02:09.240 回答