I am trying to use a PN532 (v3) board with an Arduino UNO and libnfc for my university project. One problem I have stumbled upon is that libnfc-1.7.1 gives me the following error when I invoke nfc-list:
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
I have no issues using the reader with Arduino, I can upload sketches and the reader interacts with tags. The reader is in SPI mode, and when I invoke nfc-list the LEDs blink, therefore the only thing I can think of is some sort of issue with libnfc.
I hope someone can help,any suggestions would be amazing! :) Thank you!
Connections
File Configurations
/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);
}
}
}
Used Resources
http://nfc-tools.org/index.php/Libnfc:Arduino - Used to install libnfc
https://github.com/gunmetal313/mfocuino - Uploaded the sketch uartnfc.ino and imported the libraries (mfocuino/mfocuino-read-only/nfcreader/arduino/libraries/PN532/) into the Arduino IDE.
Things I have already tried to fix the problem
Why "No NFC device found" with libnfc and PN532 SHIELD
PN532 Unable to open NFC device
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
I almost gave up having the same problem. For me it finally worked when using 9600 baud in the Arduino Sketch and libnfc config.