NFC is becoming more and more popular. On the other hand it already has quite a legacy, so there are many different types of tags and standards. In order to simplify the hardware solutions, vendors come up with chips that support as many standards and type of cards possible. NXP's latest NFC chip is the PN7150
In the past, the microcontroller reading the NFC tags had to 'talk' relatively low level commands to the chip, and those commands were specific to the type of tag being polled. With all the different standards, this had to be simplified as well, and the NFC Forum standardized the communication between the NFC device (eg the PN7150) and the microcontroller : the FNC Controller Interface (NCI) was born.
The NCI allows the microcontroller to talk at a 'higher' level of abstraction, and delegates the low-level stuff to the NFC chip.
The HardwareAs an NFC device requires an antenna, it's not something you can easily do on a breadboard. Fortunately, NXP provides a demo-board, with the PN7150 on it.
I developed the SW using a Teensy3.2 as MCU (because it is convenient and fast for development) but in the end it was going to be run on an ESP32. The SW works on both, and probably on any microcontroller that has a decent I2C implementation. The demo board has no pullups on the I2C, so don't forget to add these.
The SoftwareNXP provides demo software, but to be honest, this was a large bunch of hard to read code. I try to write clean, easy-to-read C++ code. I am using OO but I stick to the basics of it, so the code is robust but still compact and fast.
The code is well documented with a Wiki on github, so I will not repeat everything here. Only the basics :
- the lowest layer is PN7150Interface : this is basically I2C with a few add-ons.
- on top of that is the NCI : this is where the hard work is done, implementing the NCI state machine.
- finally there is an application, in this case a simple reader/writer which will detect tags and then print their unique ID.
Here is a short video of the demo in action :
Comments