簡體   English   中英

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)

我正在嘗試將 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 “未找到 NFC 設備”
PN532 無法打開 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

我幾乎放棄了同樣的問題。 對我來說,在 Arduino Sketch 和 libnfc 配置中使用 9600 波特時,它終於奏效了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM