1 (edited by deu439 2016-07-21 12:50:58)

Topic: Tag emulation with pn532, I2C, RaspberryPi

Hello,
I am trying to get card emulation running with PN532 chip connected to RaspberryPi through I2C bus.
Any time I run one of the emulation examples (nfc-emulate-tag, nfc-emulate-forum-tag2, nfc-emulate-forum-tag4)
and put my android phone close to the chip the example programs fail with this error:

error   libnfc.bus.i2c  Error: wrote only -1 bytes (10 expected).

After this error any attempt to communicate with the chip fails with the same error. The only resolution from this state is to disconnect and reconnect the chip to power supply.

The i2c communication seems to be working fine as pn53x-diagnose displays:

pi@raspberrypi:~ $ pn53x-diagnose 
pn53x-diagnose uses libnfc 1.7.1
NFC device [pn532_i2c:/dev/i2c-1] opened.
 Communication line test: OK
 ROM test: OK
 RAM test: OK

Some related information:

pi@raspberrypi:~ $ nfc-scan-device -v
nfc-scan-device uses libnfc 1.7.1
1 NFC device(s) found:
- pn532_i2c:/dev/i2c-1:
    pn532_i2c:/dev/i2c-1
chip: PN532 v1.6
initator mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), ISO/IEC 14443-4B (106 kbps), Innovision Jewel (106 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
target mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
pi@raspberrypi:~ $ nfc-emulate-forum-tag4
debug   libnfc.config   key: [device.name], value: [pn532]
debug   libnfc.config   key: [device.connstring], value: [pn532_i2c:/dev/i2c-1]
debug   libnfc.config   Unable to open directory: /usr/local/etc/nfc/devices.d
debug   libnfc.general  log_level is set to 3
debug   libnfc.general  allow_autoscan is set to true
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", connstring: "pn532_i2c:/dev/i2c-1"
debug   libnfc.chip.pn53x       Diagnose
debug   libnfc.chip.pn53x       Timeout value: 500
debug   libnfc.chip.pn53x       SAMConfiguration
debug   libnfc.chip.pn53x       Timeout value: 1000
debug   libnfc.bus.i2c  TX: 00 00 ff 03 fd d4 14 01 17 00 
debug   libnfc.bus.i2c  wrote 10 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.bus.i2c  TX: 00 00 ff 09 f7 d4 00 00 6c 69 62 6e 66 63 be 00 
debug   libnfc.bus.i2c  wrote 16 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.chip.pn53x       GetFirmwareVersion
debug   libnfc.bus.i2c  TX: 00 00 ff 02 fe d4 02 2a 00 
debug   libnfc.bus.i2c  wrote 9 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.chip.pn53x       SetParameters
debug   libnfc.bus.i2c  TX: 00 00 ff 03 fd d4 12 14 06 00 
debug   libnfc.bus.i2c  wrote 10 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.general  "pn532_i2c:/dev/i2c-1" (pn532_i2c:/dev/i2c-1) has been claimed.
NFC device: pn532_i2c:/dev/i2c-1 opened
Emulating NDEF tag now, please touch it with a second NFC device
debug   libnfc.chip.pn53x       ReadRegister
debug   libnfc.bus.i2c  TX: 00 00 ff 0c f4 d4 06 63 02 63 03 63 0d 63 38 63 3d b0 00 
debug   libnfc.bus.i2c  wrote 19 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.chip.pn53x       PN53X_REG_CIU_TxMode (Defines the transmission data rate and framing during transmission)
debug   libnfc.chip.pn53x       PN53X_REG_CIU_RxMode (Defines the transmission data rate and framing during receiving)
debug   libnfc.chip.pn53x       WriteRegister
debug   libnfc.bus.i2c  TX: 00 00 ff 08 f8 d4 08 63 02 80 63 03 80 59 00 
debug   libnfc.bus.i2c  wrote 15 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.chip.pn53x       RFConfiguration
debug   libnfc.bus.i2c  TX: 00 00 ff 04 fc d4 32 01 00 f9 00 
debug   libnfc.bus.i2c  wrote 11 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.chip.pn53x       ReadRegister
debug   libnfc.bus.i2c  TX: 00 00 ff 06 fa d4 06 63 38 63 3d eb 00 
debug   libnfc.bus.i2c  wrote 13 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.chip.pn53x       SetParameters
debug   libnfc.bus.i2c  TX: 00 00 ff 03 fd d4 12 10 0a 00 
debug   libnfc.bus.i2c  wrote 10 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.chip.pn53x       SetParameters
debug   libnfc.bus.i2c  TX: 00 00 ff 03 fd d4 12 30 ea 00 
debug   libnfc.bus.i2c  wrote 10 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.chip.pn53x       ReadRegister
debug   libnfc.bus.i2c  TX: 00 00 ff 04 fc d4 06 63 05 be 00 
debug   libnfc.bus.i2c  wrote 11 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.chip.pn53x       PN53X_REG_CIU_TxAuto (Controls the settings of the antenna driver)
debug   libnfc.chip.pn53x       WriteRegister
debug   libnfc.bus.i2c  TX: 00 00 ff 05 fb d4 08 63 05 04 b8 00 
debug   libnfc.bus.i2c  wrote 12 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.chip.pn53x       TgInitAsTarget
debug   libnfc.chip.pn53x       No timeout
debug   libnfc.bus.i2c  TX: 00 00 ff 27 d9 d4 8c 05 04 00 00 b0 0b 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 bc 00 
debug   libnfc.bus.i2c  wrote 46 bytes successfully.
debug   libnfc.chip.pn53x       PN53x ACKed
nfc_emulate_target: Success
debug   libnfc.chip.pn53x       InRelease
debug   libnfc.bus.i2c  TX: 00 00 ff 03 fd d4 52 00 da 00 
error   libnfc.bus.i2c  Error: wrote only -1 bytes (10 expected).
error   libnfc.driver.pn532_i2c Unable to transmit data. (TX)

Thank you for any response.