issue with nfcpy initialization of pn532 on Raspberry PI

Asked by Karl Asha

I've been using a breakout board from adafruit for the pn532 via the UART interface on a Raspberry PI.

I found that nfcpy tools in general would not work until I had run something from nfc-tools first.

I verified the difference in initializations that took place in nfcpy vs. nfc-tools and my own code and found that the lack of the SAMConfiguration call (command 0x14) appears to be the culprit.

Adding a call to this during the device initialization for normal card, default timeout, and disabling IRQ is working for me.

Just thought I'd share since I believe I saw a similar post about this on the forum or on google regarding ncfpy.

Thanks,
Karl

Question information

Language:
English Edit question
Status:
Answered
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#1

Thank you Karl, great help. I've added SAM initialisation for PN531/PN532 as you suggested (trunk revision 180). I can't test if it's working with the breakout board but least on my PN532 reader that connects through USB FTDI it's not having any negative effects. Should you be able to verify with your setup I'd appreciate a short notice.
/Stephen

Revision history for this message
Karl Asha (karl-asha) said :
#2

Works like a charm, thank you. Incidentally, any interest in contributed
mifare classic support for your library? I understand it's very focused on
the NFC forum standards, but these types of tags are quite popular.

On Tue, Oct 15, 2013 at 10:16 AM, Stephen Tiedemann <
<email address hidden>> wrote:

> Your question #237349 on nfcpy changed:
> https://answers.launchpad.net/nfcpy/+question/237349
>
> Status: Open => Answered
>
> Stephen Tiedemann proposed the following answer:
> Thank you Karl, great help. I've added SAM initialisation for PN531/PN532
> as you suggested (trunk revision 180). I can't test if it's working with
> the breakout board but least on my PN532 reader that connects through USB
> FTDI it's not having any negative effects. Should you be able to verify
> with your setup I'd appreciate a short notice.
> /Stephen
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/nfcpy/+question/237349/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/nfcpy/+question/237349
>
> You received this question notification because you asked the question.
>

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#3

Thanks for the offer. If it would be mostly a matter of merging then very welcome. I just don't have much time available to work on mifare classic support.

Revision history for this message
klomp (henri-l) said :
#4

Karl

I'm using the same setup. How did you initialize the nfcpy library to use the uart? If you have an example script that would be greatly appreciated

Thanks.

Revision history for this message
Karl Asha (karl-asha) said :
#5

You'll need to use --device tty:AMA0:pn53x if using the sample command line tools.

Revision history for this message
chaos (chaos-master) said :
#6

Hi,

I do have the exact same issue.
I am currently using revision 198 and I still have to run nfc-poll or something similar first
to get my adafruit breakout-board working with nfcpy, although this is supposed to have been fixed in rev 180.
Any Idea what could be wrong?

Chaos

Revision history for this message
Karl Asha (karl-asha) said :
#7

What is your command line, and what error are you encountering?

Revision history for this message
chaos (chaos-master) said :
#8

Hi,

this is what I get when no nfc-device (android-phone) is present,
note that I have to run nfcpy twice even after initializing with nfc-poll:

[code]
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ ./beam.py -d nfc.dev --device tty:USB0:pn53x --mode i send text foobar
[main] enable debug output for module 'nfc.dev'
[nfc.clf] searching for reader with path 'tty:USB0:pn53x'
[nfc.dev] trying pn53x on 'tty:USB0:pn53x'
[nfc.dev] import nfc.dev.pn53x
[nfc.dev.transport] >>> 0000ff00ff00
[nfc.dev.pn53x] GetFirmwareVersion command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff02fed4022a00
[nfc.dev.pn53x] timeout while waiting for ack
[nfc.clf] no reader found at 'tty:USB0:pn53x'
[main] no contactless reader found
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ nfc-poll
nfc-poll uses libnfc 1.7.0
debug libnfc.config key: [allow_intrusive_scan], value: [true]
debug libnfc.config key: [log_level], value: [1]
debug libnfc.config key: [device.connstring], value: [pn532_uart:/dev/ttyUSB0]
unknown libnfc.general log_level is set to 1
NFC reader: pn532_uart:/dev/ttyUSB0 opened
NFC device will poll during 30000 ms (20 pollings of 300 ms for 5 modulations)
^Cnfc_initiator_poll_target: Operation Aborted
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ ./beam.py -d nfc.dev --device tty:USB0:pn53x --mode i send text foobar
[main] enable debug output for module 'nfc.dev'
[nfc.clf] searching for reader with path 'tty:USB0:pn53x'
[nfc.dev] trying pn53x on 'tty:USB0:pn53x'
[nfc.dev] import nfc.dev.pn53x
[nfc.dev.transport] >>> 0000ff00ff00
[nfc.dev.pn53x] GetFirmwareVersion command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff02fed4022a00
[nfc.dev.pn53x] timeout while waiting for ack
[nfc.clf] no reader found at 'tty:USB0:pn53x'
[main] no contactless reader found
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ ./beam.py -d nfc.dev --device tty:USB0:pn53x --mode i send text foobar
[main] enable debug output for module 'nfc.dev'
[nfc.clf] searching for reader with path 'tty:USB0:pn53x'
[nfc.dev] trying pn53x on 'tty:USB0:pn53x'
[nfc.dev] import nfc.dev.pn53x
[nfc.dev.transport] >>> 0000ff00ff00
[nfc.dev.pn53x] GetFirmwareVersion command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff02fed4022a00
[nfc.dev.transport] <<< 0000ff06fad50332010607e800
[nfc.dev.pn53x] chipset is a PN532 version 1.6
[nfc.dev.pn53x] SAMConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff05fbd4140100001700
[nfc.dev.transport] <<< 0000ff02fed5151600
[nfc.dev.pn53x] Diagnose command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff08f8d400006e666370790c00
[nfc.dev.transport] <<< 0000ff08f8d501006e666370790a00
[nfc.dev.pn53x] ATR_RES timeout: 102.4 ms
[nfc.dev.pn53x] non-DEP timeout: 51.2 ms
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad432020b0b0ad800
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] set retries: ATR_REQ=2 PSL_REQ=1 PassiveTarget=3
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad43205020103ef00
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.clf] using NXP PN532 at /dev/ttyUSB0
[nfc.snep.server] snep server bound to port 4 (MIU=1984, RW=15), will accept up to 1048576 byte NDEF messages
[nfc.dev.pn53x] polling for a p2p target
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320100f900
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] nfcid3 not used in passive mode
[nfc.dev.pn53x] InJumpForDEP command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff1ee2d45600020500ffff000346666d010111020207ff030200130401320701033e00
[nfc.dev.transport] <<< 0000ff03fdd55701d300
[nfc.dev.pn53x] polling for a p2p target
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320100f900
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] nfcid3 not used in passive mode
[nfc.dev.pn53x] InJumpForDEP command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff1ee2d45600020500ffff000346666d010111020207ff030200130401320701033e00
[nfc.dev.transport] <<< 0000ff03fdd55701d300
[nfc.dev.pn53x] polling for a p2p target
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320100f900
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] nfcid3 not used in passive mode
[nfc.dev.pn53x] InJumpForDEP command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff1ee2d45600020500ffff000346666d010111020207ff030200130401320701033e00
[nfc.dev.transport] <<< 0000ff03fdd55701d300
[nfc.dev.pn53x] polling for a p2p target
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320100f900
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] nfcid3 not used in passive mode
[nfc.dev.pn53x] InJumpForDEP command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff1ee2d45600020500ffff000346666d010111020207ff030200130401320701033e00
[nfc.dev.transport] <<< 0000ff03fdd55701d300
[nfc.dev.pn53x] polling for a p2p target
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320100f900
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] nfcid3 not used in passive mode
[nfc.dev.pn53x] InJumpForDEP command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff1ee2d45600020500ffff000346666d010111020207ff030200130401320701033e00
[nfc.dev.transport] <<< 0000ff03fdd55701d300
[nfc.dev.pn53x] polling for a p2p target
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320100f900
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] nfcid3 not used in passive mode
[nfc.dev.pn53x] InJumpForDEP command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff1ee2d45600020500ffff000346666d010111020207ff030200130401320701033e00
[nfc.dev.transport] <<< 0000ff03fdd55701d300
[nfc.dev.pn53x] polling for a p2p target
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320100f900
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] nfcid3 not used in passive mode
[nfc.dev.pn53x] InJumpForDEP command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff1ee2d45600020500ffff000346666d010111020207ff030200130401320701033e00
[nfc.dev.transport] <<< 0000ff03fdd55701d300
[nfc.dev.pn53x] polling for a p2p target
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320100f900
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] nfcid3 not used in passive mode
[nfc.dev.pn53x] InJumpForDEP command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff1ee2d45600020500ffff000346666d010111020207ff030200130401320701033e00
^C[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320100f900
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.transport] >>> 0000ff00ff00
[/code]

And this is what happens, when the device is present,
I still have to use nfc-poll first, but nfcpy then works on the first try:

[code]
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ ./beam.py -d nfc.dev --device tty:USB0:pn53x --mode i send text foobar
[main] enable debug output for module 'nfc.dev'
[nfc.clf] searching for reader with path 'tty:USB0:pn53x'
[nfc.dev] trying pn53x on 'tty:USB0:pn53x'
[nfc.dev] import nfc.dev.pn53x
[nfc.dev.transport] >>> 0000ff00ff00
[nfc.dev.pn53x] GetFirmwareVersion command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff02fed4022a00
[nfc.dev.pn53x] timeout while waiting for ack
[nfc.clf] no reader found at 'tty:USB0:pn53x'
[main] no contactless reader found
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ nfc-poll
nfc-poll uses libnfc 1.7.0
debug libnfc.config key: [allow_intrusive_scan], value: [true]
debug libnfc.config key: [log_level], value: [1]
debug libnfc.config key: [device.connstring], value: [pn532_uart:/dev/ttyUSB0]
unknown libnfc.general log_level is set to 1
NFC reader: pn532_uart:/dev/ttyUSB0 opened
NFC device will poll during 30000 ms (20 pollings of 300 ms for 5 modulations)
^Cnfc_initiator_poll_target: Operation Aborted
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ ./beam.py -d nfc.dev --device tty:USB0:pn53x --mode i send text foobar
[main] enable debug output for module 'nfc.dev'
[nfc.clf] searching for reader with path 'tty:USB0:pn53x'
[nfc.dev] trying pn53x on 'tty:USB0:pn53x'
[nfc.dev] import nfc.dev.pn53x
[nfc.dev.transport] >>> 0000ff00ff00
[nfc.dev.pn53x] GetFirmwareVersion command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff02fed4022a00
[nfc.dev.transport] <<< 0000ff06fad50332010607e800
[nfc.dev.pn53x] chipset is a PN532 version 1.6
[nfc.dev.pn53x] SAMConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff05fbd4140100001700
[nfc.dev.transport] <<< 0000ff02fed5151600
[nfc.dev.pn53x] Diagnose command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff08f8d400006e666370790c00
[nfc.dev.transport] <<< 0000ff08f8d501006e666370790a00
[nfc.dev.pn53x] ATR_RES timeout: 102.4 ms
[nfc.dev.pn53x] non-DEP timeout: 51.2 ms
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad432020b0b0ad800
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] set retries: ATR_REQ=2 PSL_REQ=1 PassiveTarget=3
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad43205020103ef00
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.clf] using NXP PN532 at /dev/ttyUSB0
[nfc.snep.server] snep server bound to port 4 (MIU=1984, RW=15), will accept up to 1048576 byte NDEF messages
[nfc.dev.pn53x] polling for a p2p target
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320100f900
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] nfcid3 not used in passive mode
[nfc.dev.pn53x] InJumpForDEP command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff1ee2d45600020500ffff000346666d010111020207ff030200130401320701033e00
[nfc.dev.transport] <<< 0000ff20e0d557000101fea913702ab145031a0000000e3246666d010111030200130401964c00
[nfc.dev.pn53x] activated a p2p target in 424 kbps passive mode
[nfc.dev.pn53x] ATR_RES(nfcid3=01fea913702ab145031a did=00 bs=00 br=00 to=0e pp=32 gb=46666d01011103020013040196)
[nfc.llcp.llc] LLCP Link established as NFC-DEP Initiator
Local LLCP Settings
  LLCP Version: 1.1
  Link Timeout: 500 ms
  Max Inf Unit: 2175 octet
  Service List: 0000000000010011
Remote LLCP Settings
  LLCP Version: 1.1
  Link Timeout: 1500 ms
  Max Inf Unit: 128 octet
  Service List: 0000000000010011
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad432020b0b0fd300
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320403f300
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] InDataExchange command with timeout 2550 ms
[nfc.dev.transport] >>> 0000ff16ead440010520060f75726e3a6e66633a736e3a736e6570e000
[nfc.dev.transport] <<< 0000ff05fbd541000000ea00
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad432020b0b0fd300
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320403f300
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] InDataExchange command with timeout 2550 ms
[nfc.dev.transport] >>> 0000ff05fbd440010000eb00
[nfc.dev.transport] <<< 0000ff05fbd541008184e500
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad432020b0b0fd300
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320403f300
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] InDataExchange command with timeout 2550 ms
[nfc.dev.transport] >>> 0000ff19e7d4400113200010020000000dd101095402656e666f6f6261721c00
[nfc.dev.transport] <<< 0000ff06fad541008344012200
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad432020b0b0fd300
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320403f300
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] InDataExchange command with timeout 2550 ms
[nfc.dev.transport] >>> 0000ff05fbd440010000eb00
[nfc.dev.transport] <<< 0000ff0cf4d54100830401108100000000d100
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad432020b0b0fd300
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff04fcd4320403f300
[nfc.dev.transport] <<< 0000ff02fed533f800
[/code]

Revision history for this message
Karl Asha (karl-asha) said :
#9

Try it without the -d nfc the very first time you run it. I think this might be causing an issue with the initialization code path.

Revision history for this message
chaos (chaos-master) said :
#10

I had this problem without the "-d nfc.dev", I just added it here because I thought it may contain some usefull information.
Here is the same scenario without debug-information (again once without device and once with):

without:
[code]
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ ./beam.py --device tty:USB0:pn53x --mode i send text foobar
[nfc.clf] searching for reader with path 'tty:USB0:pn53x'
[nfc.dev.pn53x] timeout while waiting for ack
[nfc.clf] no reader found at 'tty:USB0:pn53x'
[main] no contactless reader found
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ nfc-poll
nfc-poll uses libnfc 1.7.0
debug libnfc.config key: [allow_intrusive_scan], value: [true]
debug libnfc.config key: [log_level], value: [1]
debug libnfc.config key: [device.connstring], value: [pn532_uart:/dev/ttyUSB0]
unknown libnfc.general log_level is set to 1
NFC reader: pn532_uart:/dev/ttyUSB0 opened
NFC device will poll during 30000 ms (20 pollings of 300 ms for 5 modulations)
^Cnfc_initiator_poll_target: Operation Aborted
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ ./beam.py --device tty:USB0:pn53x --mode i send text foobar
[nfc.clf] searching for reader with path 'tty:USB0:pn53x'
[nfc.dev.pn53x] timeout while waiting for ack
[nfc.clf] no reader found at 'tty:USB0:pn53x'
[main] no contactless reader found
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ ./beam.py --device tty:USB0:pn53x --mode i send text foobar
[nfc.clf] searching for reader with path 'tty:USB0:pn53x'
[nfc.clf] using NXP PN532 at /dev/ttyUSB0
[nfc.snep.server] snep server bound to port 4 (MIU=1984, RW=15), will accept up to 1048576 byte NDEF messages
[/code]

with:
[code]
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ ./beam.py --device tty:USB0:pn53x --mode i send text foobar
[nfc.clf] searching for reader with path 'tty:USB0:pn53x'
[nfc.dev.pn53x] timeout while waiting for ack
[nfc.clf] no reader found at 'tty:USB0:pn53x'
[main] no contactless reader found
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ nfc-poll
nfc-poll uses libnfc 1.7.0
debug libnfc.config key: [allow_intrusive_scan], value: [true]
debug libnfc.config key: [log_level], value: [1]
debug libnfc.config key: [device.connstring], value: [pn532_uart:/dev/ttyUSB0]
unknown libnfc.general log_level is set to 1
NFC reader: pn532_uart:/dev/ttyUSB0 opened
NFC device will poll during 30000 ms (20 pollings of 300 ms for 5 modulations)
^Cnfc_initiator_poll_target: Operation Aborted
chaosmaster@chaos64:~/uni/projekt/nfc/nfcpy/nfcpy/examples$ ./beam.py --device tty:USB0:pn53x --mode i send text foobar
[nfc.clf] searching for reader with path 'tty:USB0:pn53x'
[nfc.clf] using NXP PN532 at /dev/ttyUSB0
[nfc.snep.server] snep server bound to port 4 (MIU=1984, RW=15), will accept up to 1048576 byte NDEF messages
[nfc.dev.pn53x] activated a p2p target in 424 kbps passive mode
[nfc.llcp.llc] LLCP Link established as NFC-DEP Initiator
Local LLCP Settings
  LLCP Version: 1.1
  Link Timeout: 500 ms
  Max Inf Unit: 2175 octet
  Service List: 0000000000010011
Remote LLCP Settings
  LLCP Version: 1.1
  Link Timeout: 1500 ms
  Max Inf Unit: 128 octet
  Service List: 0000000000010011
[/code]

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#11

I have once tested with a USB connected reader (native, not through a USB/Serial bridge) and found the USB implementation on RPi pretty unreliable. This was backed by other USB problem reports. If you have chance to directly use a serial connection, like the ttyAMA0 port, I'd strongly recommend to change.

Revision history for this message
chaos (chaos-master) said :
#12

Oh, I should have mentioned that I am currently not working on a Pi.
It's just the adafruit breakout-board connected to my desktop using an ftdi-adapter.

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#13

Guess I've found it. Your board uses the PN532 V1.6 while I have a PN532 V1.4 based reader for testing. Since V1.6 the chip starts in low power mode and requires an additional wakeup sequence. Could you please try the following insert at line 624 in nfc/dev/pn53x.py and let me know if that solves the problem.

transport.write(bytearray([0x55, 0x55] + 14 * [0x00]))

NB: The insert becomes the first command after "def init(transport):"

Revision history for this message
chaos (chaos-master) said :
#14

Yes, that fixes the problem, thank you very much

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#15

Great. Trunk revision 199 now contains the fix.

Revision history for this message
Florian (7-kontakt) said :
#16

It seems like this problem is back in 0.10.0
With 0.9.2 I am able to read from my PN532 using tagtool.py --device tty:AMA0:pn53x
This is not true for 0.10.0 (unless I read a tag previously with 0.9.2)

I searched 0.10.0 for anything closely related to "transport.write(bytearray([0x55, 0x55] + 14 * [0x00]))". But have not been able to find anything. Am I missing something or does it need to be put back in place somewhere?

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#17

The issue is related not to initialization but deactivation of the hardware. Since 0.10 the nfcpy driver for PN532 increases the UART speed to 921 kbps (if supported by local hardware) and sets it back to 115 kbps when closing. It turned out that the chip needs an additional delay after the baud rate changed back. Versions trunk and 0.10.1 no longer show the problem with my Adafruit board PN532v1.6.

Revision history for this message
Florian (7-kontakt) said :
#18

Hi Stephen,

Thank you for your reply. I just checked out 0.10.1 and unfortunately it does not resolve the problem. Calling "tagtool.py --device tty:AMA0:pn532" in 0.10.0 and 0.10.1 results in:

[nfc.clf] searching for reader on path tty:AMA0:pn532
[nfc.clf.pn532] input/output error while waiting for ack
[main] no contactless reader available

However "activating" the reader with 0.9.2's tagtool.py prior to using tagtool.py in 0.10.0/1 works.

Regards,
Florian

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#19

Can you please run "tagtool.py --device tty:AMA0:pn532 -d nfc -v" and post the output.

Revision history for this message
Florian (7-kontakt) said :
#20

Output with 0.10.1:

[main] enable debug output for 'nfc'
[nfc.clf] searching for reader on path tty:AMA0:pn532
[nfc.clf.transport] trying /dev/ttyAMA0
[nfc.clf.transport] avail: /dev/ttyAMA0
[nfc.clf.device] trying pn532 on /dev/ttyAMA0
[nfc.clf.transport] >>> 000000000000000000000000ff02fed4022a00
[nfc.clf.transport] <<< 0000ff00ff00
[nfc.clf.transport] <<< 0000ff06fad50332010607e800
[nfc.clf.pn532] trying to set 921600 baud
[nfc.clf.pn532] trying to set 460800 baud
[nfc.clf.pn532] trying to set 230400 baud
[nfc.clf.pn532] trying to set 115200 baud
[nfc.clf.pn532] Diagnose 00000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405 1.000s
[nfc.clf.transport] >>> 0000ffffff0109f6d40000000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff0001020304059d00
[nfc.clf.pn532] input/output error while waiting for ack
[nfc.clf.device] [Errno 5] Input/output error
[main] no contactless reader available

--------------------------------

Output with 0.9.2: (using tty:AMA0:pn53x)

[main] enable debug output for module 'nfc'
[nfc.clf] searching for reader with path 'tty:AMA0:pn53x'
[nfc.dev] trying pn53x on 'tty:AMA0:pn53x'
[nfc.dev] import nfc.dev.pn53x
[nfc.dev.transport] >>> 55550000000000000000000000000000
[nfc.dev.transport] >>> 0000ff00ff00
[nfc.dev.pn53x] GetFirmwareVersion command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff02fed4022a00
[nfc.dev.transport] <<< 0000ff06fad50332010607e800
[nfc.dev.pn53x] chipset is a PN532 version 1.6
[nfc.dev.pn53x] SAMConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff05fbd4140100001700
[nfc.dev.transport] <<< 0000ff02fed5151600
[nfc.dev.pn53x] Diagnose command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff08f8d400006e666370790c00
[nfc.dev.transport] <<< 0000ff08f8d501006e666370790a00
[nfc.dev.pn53x] ATR_RES timeout: 102.4 ms
[nfc.dev.pn53x] non-DEP timeout: 51.2 ms
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad432020b0b0ad800
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.dev.pn53x] set retries: ATR_REQ=2 PSL_REQ=1 PassiveTarget=3
[nfc.dev.pn53x] RFConfiguration command with timeout 100 ms
[nfc.dev.transport] >>> 0000ff06fad43205020103ef00
[nfc.dev.transport] <<< 0000ff02fed533f800
[nfc.clf] using NXP PN532 at /dev/ttyAMA0
[nfc.clf] connect({'llcp': None, 'card': {'on-release': <bound method TagTool.on_card_release of <__main__.TagTool object at 0x766b5610>>, 'on-connect': <bound method TagTool.on_card_connect of <__main__.TagTool object at 0x766b5610>>, 'on-startup': <bound method TagTool.on_card_startup of <__main__.TagTool object at 0x766b5610>>, 'targets': []}, 'rdwr': {'on-connect': <bound method TagTool.on_rdwr_connect of <__main__.TagTool object at 0x766b5610>>, 'on-startup': <bound method TagTool.on_rdwr_startup of <__main__.TagTool object at 0x766b5610>>}})
[main] touch a tag
[nfc.dev.pn53x] polling for NFC-A technology
[nfc.dev.pn53x] InListPassiveTarget command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff04fcd44a0100e100
[nfc.dev.transport] <<< 0000ff03fdd54b00e000
[nfc.dev.pn53x] InListPassiveTarget command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff04fcd44a0104dd00
[nfc.dev.transport] <<< 0000ff03fdd54b00e000
[nfc.dev.pn53x] poll NFC-F 00ffff0103
[nfc.dev.pn53x] InListPassiveTarget command with timeout 1000 ms
[nfc.dev.transport] >>> 0000ff09f7d44a010200ffff0103dd00
[nfc.dev.transport] <<< 0000ff03fdd54b00e000
[nfc.dev.pn53x] poll NFC-F 00ffff0103
… and so on

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#21

Can you please try two further things separately and provide the result:

1) Increment the timeout for chip acknowledgement in line 181 file nfc/clf/pn53x from 100 to 1000.

2) Decrease the number of bytes send for host-controller communication test in line 265 of file nfc/clf/pn53x.py by subtracting 200 instead of 3.

Revision history for this message
Florian (7-kontakt) said :
#22

1)
[main] enable debug output for 'nfc'
[nfc.clf] searching for reader on path tty:AMA0:pn532
[nfc.clf.transport] trying /dev/ttyAMA0
[nfc.clf.transport] avail: /dev/ttyAMA0
[nfc.clf.device] trying pn532 on /dev/ttyAMA0
[nfc.clf.transport] >>> 000000000000000000000000ff02fed4022a00
[nfc.clf.transport] <<< 0000ff00ff00
[nfc.clf.transport] <<< 0000ff06fad50332010607e800
[nfc.clf.pn532] trying to set 921600 baud
[nfc.clf.pn532] trying to set 460800 baud
[nfc.clf.pn532] trying to set 230400 baud
[nfc.clf.pn532] trying to set 115200 baud
[nfc.clf.pn532] Diagnose 00000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405 1.000s
[nfc.clf.transport] >>> 0000ffffff0109f6d40000000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff0001020304059d00
[nfc.clf.pn532] input/output error while waiting for ack
[nfc.clf.device] [Errno 5] Input/output error
[main] no contactless reader available

2)
[main] enable debug output for 'nfc'
[nfc.clf] searching for reader on path tty:AMA0:pn532
[nfc.clf.transport] trying /dev/ttyAMA0
[nfc.clf.transport] avail: /dev/ttyAMA0
[nfc.clf.device] trying pn532 on /dev/ttyAMA0
[nfc.clf.transport] >>> 000000000000000000000000ff02fed4022a00
[nfc.clf.transport] <<< 0000ff00ff00
[nfc.clf.transport] <<< 0000ff06fad50332010607e800
[nfc.clf.pn532] trying to set 921600 baud
[nfc.clf.pn532] trying to set 460800 baud
[nfc.clf.pn532] trying to set 230400 baud
[nfc.clf.pn532] trying to set 115200 baud
[nfc.clf.pn532] Diagnose 00000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40 1.000s
[nfc.clf.transport] >>> 0000ff44bcd40000000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f400c00
[nfc.clf.pn532] input/output error while waiting for ack
[nfc.clf.device] [Errno 5] Input/output error
[main] no contactless reader available

Does not seem to solve the issue.

NFC-Reader: http://www.itead.cc/itead-pn532-nfc-module.html
If you happen to be around Stuttgart, Germany I'd be happy to provide you with the relevant NFC board, since I have two ;)

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#23

Thanks for trying it out. I happen to live in Stuttgart but could meanwhile reproduce the problem on a RasPi 2 with the Adafruit board. So most likely I won't need your board but thanks anyway.

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#24

Now it should really be fixed. Turned out that the PN532 must be moved into normal power mode much earlier and with a long preamble when running on Raspberry Pi serial line. Did never happen when the same board is used with FTDI on a faster machine (but then it's also running at ~900 kbaud). The fix is released with 0.10.2 and tested with Adafruit PN532v1.6 breakout board on RasPi and Desktop.

Revision history for this message
Florian (7-kontakt) said :
#25

Yes Stephen, 0.10.2 fixed the problem for me.
You were right I am running this on a Raspberry Pi 2, I could have mentioned that before I guess ;)

Thank you very much. I really appreciate your work!

Can you help with this problem?

Provide an answer of your own, or ask Karl Asha for more information if necessary.

To post a message you must log in.