PN532 NFC Library [PORTED]


Basically the SPI bus is puking all over the place in HW and SW mode. -_-

So much for logic analyzers… time to break out the scope and see what the heck is going on.


Wow I love looking at such cool art piece :smiley:

@BDub, email me if you open the guts :wink:


That’s a strange diagram! Are you sure clock and MOSI aren’t swapped on the core pins or in the diagram? MOSI looks like more like SPI clock to me! Undersampled so the period looks off, but more clock-like than CLOCK.


@BDub, I would focus on hardware SPI to start with. Second, I noticed that I forgot to include any hardware SPI setup code like SPI.begin!!! DOH!! I added the code in the constructor and set the clock to DIV16 by default. You could change that later if you wish. I made the changes to the code on my github.


Thanks @peekay123, but I did all of that already, and put the HW init in the begin() method instead of the constructor :slight_smile: Also the datasheet says LSBFIRST… lot’s of tweaks to other parts of the code too. I’ll Fork it and get it up somewhere so we can bounce things off of each other more effectively.

EDIT: Ok here’s what I’m working with so far: some stuff is good, some is hacky cuz I’m debugging.


@BDub, it’s always a challenge doing a port without actual hardware! I see what your doing and it looks good to me. I’m going to have to get me one of the units. :smile:


Ok, scopes are nice to have. Basically all of the lines were oscillating at 50MHz or so. Seems messed up right? Well I had the Core in a Shield Shield, and then jumpers from the Shield Shield to the PN532 Shield. The PN532 Shield antenna is kind of pointing the wrong way and interferes with the spark core, which is why I just put it on jumper wires. I’ve seen this before with the Shield Shield. The 3.3V to 5V bi-directional level translators love to freaking oscillate if you have a little inductance and not much impedance at each end of the “transmission” line. It’s that or the reflections…

I’ve lost a lot of time now screwing with this problem on the Shield Shield with NeoPixels, nRF24L01+, and now this. We need to fix it and it might just need something simple on the shield shield itself to keep the signals from oscillating. It might also not be fixable without using a different level translator, assuming we want to be able to use a 6" wire to a project from the Shield Shield. I was reading some app notes on how these TI level converters work, and they basically say due to the architecture of the chip, a short trace length is necessary to avoid reflections that will cause oscillations.

If I wire it directly to the Spark Core like the following picture, I have the hardware SPI mode working great. I think the idle levels were flipped in the Soft SPI mode, easy enough to fix. Needs to be LSB first, MODE0… can’t be too hard :wink:


Ok HW and SW SPI modes are working with the readMifareClassic example. Pull request submitted @peekay123


@BDub, nice job! I merged the pull request so everything is up to date. :smile:


I’ll work on adding I2C support now. Hopefully that goes smoother :wink:


I2C Support was actually kind of fun to add, slightly complex… had to break everything down into generalized code, and then make the low level stuff optional depending on some #defines. So if you configure one #define it will build only I2C code or SPI code, even all the way up into the examples.

So I2C and SPI modes are both working. Now I want to make a nice example of a simple entry card system. Right now it just reads the card and spits out a crap load of data very very fast and repeatedly. Also I haven’t tried all of the examples yet, and programming a card should be fun.

To see a snapshot of the state of things, check here:

After I update the examples I’ll submit a pull request @peekay123


I just got the PN532 breakout board from Adafruit today. I couldn’t get @peekay123’s SPI version of the library working, but I was able to get I2C working with @BDub’s library. However, I’m not getting any output when I attempt to “swipe” one of my RFID tags. I’ve tried the card that comes with the breakout board as well as each of the tags from the MiFare Classic (13.56 MHz) tag assortment. All I get is:

Found chip PN53
Firmware ver. 50.1
Waiting for an ISO14443A Card ...```

I'm using the [`readMifareClassic.cpp` example](  I only modified the `setup()` a little with a `delay(7000)` instead of the `while(!Serial.available())`.  I also commented out the `#include "spark_disable_wlan.h"` line.

If I enable `MIFAREDEBUG`, I get `Found 128 tags` repeated over and over again.  Nothing changes when I try to swipe a tag.

If I enable `PN532DEBUG`, I get the following over and over again.  Nothing changes when I try to swipe a tag.

Sending: 0x0 0x0 0xFF 0x4 0xFFFFFFFC 0xD4 0x4A 0x1 0x0 0xFFFFFFE1 0x0
Reading: 0x0 0x0 0xFF 0x0 0xFF 0x0
Reading: 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80```

Any ideas?

[EDIT] In the product description, It says “you can use 3.3V TTL UART at any baud rate”. Will it not work with Serial1? I tried echoing Serial1 to Serial, but didn’t get anything, so I decided to try the other modes instead.


To use SPI or I2C you need to configure one jumper for each that’s not stuffed by default. Did you do that?

If you get communication to the board, you almost for sure should get something from it when you swipe. The SPI reads a register to know if the card has been swiped, so that might be the easiest one to get working. The I2C has to poll an extra output from the chip (i.e., needs an extra digital input hooked up or it won’t know there’s a card present). I haven’t messed with UART yet… I would stay away from that, it’s slow anyway.

Show us your nasty? wiring :slight_smile:

@peekay123 I submitted a pull request to keep you and I in sync… I still need to work on those examples…


@BDub, thanks! I merged the PR. It would be a lot easier to work with if I had one of those boards. I’ll be ordering some as soon as I find them on eBay :smile:


I know how you feel, I want one of everything on a shelf… in my basement!


I moved a post to an existing topic: Adafruit SSD1306 Library [Ported]


Is this library working for SPI already? :smiley:

I received mine and would need to get it working with the spark core :wink:

gonna ping @BDub and @peekay123!


Weird stuff going on with my Adafruit PN532…

The IRQ seems to be lighted up forever… Did anyone had the same issue?


Awesome port
I am trying to run it on a spark core using a seedstudio v1 NFC reader…
I am not sure how to connect (I have 4 pin … 1tx 1rx 1vcc and 1GND)

It am not sure if those map with TX RX on my board or not

Any help or schema to get it to work would be awesome