1 (edited by torfun 2014-02-15 18:57:16)

Topic: How to connect a PN532 NFC Modul to an Arduino to use libnfc with it?

Hi all,

i searched, but i can't find the answer to my question.

I buyed a cheap pn532 modul from ebay and i can connect it to my arduino via i2c and read from a mifare card.
But now i want to use it with libnfc.. so which pins must i connect to my arduino?

Here is a photo of the modul:
abload.de/img/img_20140209_200539slodp.jpg

Thanks for help,
Torfun


EDIT:

found the answer in the .ino file (code.google.com/p/mfocuino/source/brows … artnfc.ino):

arduino - pn532

13 <--> SCK
12 <--> MISO
11 <--> MOSI
10 <--> SS (NSS)
GND <--> GND
3,3V <--> 3,3V (VCC)

EDIT:

perhaps you must solder something on the board, if you want spi get to work..

Re: How to connect a PN532 NFC Modul to an Arduino to use libnfc with it?

Hey,

i still trying to get my pn532 board working.. this is the output of 'nfc-list -v':

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: "NFC Reader", connstring: "pn532_uart:/dev/ttyACM0:921600"
/root/Desktop/nfc/libnfc/utils/.libs/lt-nfc-list uses libnfc libnfc-1.7.0-90-g415ad7c
debug    libnfc.general    0 device(s) found using acr122_usb driver
debug    libnfc.general    0 device(s) found using pn53x_usb driver
debug    libnfc.driver.pn532_uart    Attempt to open: /dev/ttyACM0 at 921600 bauds.
debug    libnfc.bus.uart    Serial port speed requested to be set to 921600 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/ttyACM0:921600".
lt-nfc-list: ERROR: Unable to open NFC device: pn532_uart:/dev/ttyACM0:921600

i don't know the problem, why i get a timeout, so i used some python code to send the TX manully:

#!/opt/bin/python

import serial, time, binascii

try:
    ser = serial.Serial('/dev/ttyACM0', 921600, timeout=1)
    ser.close()
    ser.open()

    print "wake up chip.."
    ser.write("\x55\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
    time.sleep(3)

    print "SAMConfig.."
    ser.write("\x00\x00\xff\x03\xfd\xd4\x14\x01\x17\x00")
    time.sleep(1)

    read_val = ser.read(size=64)
    print binascii.hexlify(bytearray(read_val))
    print len(read_val)
except serial.SerialException, e:
    print str(e)

after testing the perfect timeout value, what a wonder, i get this output:

wake up chip..
SAMConfig..
0000ff00ff000000ff02fed5151600
15

my conclusion: you must wait 3 sec after the wakeup data was send, then you get data from the samconfig command back... when you wait only 2 sec, you get no data back.

So what next? check if 0000ff00ff000000ff02fed5151600 is the correct answer!

0000ff00ff00 (ack)
0000ff02fe[d515]1600 (the right output of samconfig [\x14\x01])

the answer is right. perhaps i should set another timeout... i will reply, if i get some news smile

3 (edited by torfun 2014-02-15 20:30:53)

Re: How to connect a PN532 NFC Modul to an Arduino to use libnfc with it?

good news!!! it works!!!

don't use the patch in this tutorial: code.google.com/p/mfocuino/wiki/buildingLibNfc !!
it's obsolete...

if you want to use a nfc board with arduino an libnfc, add "sleep(4);" to /libnfc/libnfc/drivers/pn532_uart.c .
it should look like:

int
pn532_uart_wakeup(nfc_device *pnd)
{
  /* High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */
  const uint8_t pn532_wakeup_preamble[] = { 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  int res = uart_send(DRIVER_DATA(pnd)->port, pn532_wakeup_preamble, sizeof(pn532_wakeup_preamble), 0);
  CHIP_DATA(pnd)->power_mode = NORMAL; // PN532 should now be awake
  sleep(4); // add
  return res;
}

now the output of "./nfc-list" is:

...
NFC device: pn532_uart:/dev/ttyACM0 opened
1 ISO14443A passive target(s) found:
ISO/IEC 14443A (106 kbps) target:
...

yeah, maybe i will write a tut for that, but first i want to play with my nfc reader and some card big_smile

Torfun

Re: How to connect a PN532 NFC Modul to an Arduino to use libnfc with it?

You can create an account on the wiki and write your tuto there:
http://nfc-tools.org/index.php?title=Libnfc:Arduino

Thanks!
Phil

Re: How to connect a PN532 NFC Modul to an Arduino to use libnfc with it?

hi phil,

the wiki is a nice idea. But first i need a solution for "make install".

Torfun