The Challenger RP2040 NFC board is an Adafruit Feather sized microcontroller board based on the RP2040 micro controller from the Raspberry Pi foundation combined with the PN7150 NFC communications controller from NXP. The PN7150 communications controller combined with our high performance NFC antenna supports most NFC tags available and is fully compatible with the NCI protocol standard.
PN7150 integrated firmware provides an easy integration and validation cycle as all the NFC real-time constraints, protocols and device discovery (polling loop) are being taken care internally. In few NCI commands, host SW can configure the PN7150 to notify for card or peer detection and start communicating with them.
The PN7150 supports the following RF protocols:
- NFCIP-1, NFCIP-2 protocol
- ISO/IEC 14443A, ISO/IEC 14443B PICC, NFC Forum T4T modes via host interface
- NFC Forum T3T via host interface
- ISO/IEC 14443A, ISO/IEC 14443B PCD designed according to NFC Forum digital protocol T4T platform and ISO-DEP
- FeliCa PCD mode
- MIFARE Classic PCD encryption mechanism (MIFARE Classic 1K/4K)
- NFC Forum tag 1 to 5 (MIFARE Ultralight, Jewel, Open FeliCa tag, MIFARE DESFire)
- ISO/IEC 15693/ICODE VCD mode
To use this board you need to either download an existing driver for the NFC controller or write your own driver to communicate with the NFC controller. We suggest that you use “Electronic Cats PN7150” driver that is available for download through the Arduino IDE.
The example code below uses this library to create a simple card reader using the built in LED’s to indicate the tag state.
/**
* Example detect tags and show their unique ID
* Authors:
* Salvador Mendoza - @Netxing - salmg.net
* For Electronic Cats - electroniccats.com
* Modified for the Challenger RP2040:
* Pontus Oldberg - pontus(@)iabs.se (2023)
*
* March 2020
*
* This code is beerware; if you see me (or any other collaborator
* member) at the local, and you've found our code helpful,
* please buy us a round!
* Distributed as-is; no warranty is given.
*/
#include "Electroniccats_PN7150.h"
#include <Adafruit_NeoPixel.h>
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals.
Adafruit_NeoPixel pixels(1, NEOPIXEL, NEO_GRB + NEO_KHZ800);
uint8_t colors[3][3] ={ { 15, 0, 0 }, { 0, 10, 0 }, { 0, 0, 20 }};
#define RGB_RED 0
#define RGB_GREEN 1
#define RGB_BLUE 2
#define BUZZER_PIN D13
// creates a global NFC device interface object
Electroniccats_PN7150 nfc(PIN_PN7150_IRQ_B, PIN_PN7150_RST_B, PN7150_I2C_ADDR, &Wire1);
//Interface to save data for multiple tags
RfIntf_t RfInterface;
uint8_t mode = 1; // modes: 1 = Reader/ Writer, 2 = Emulation
void set_rgb_led(int color) {
pixels.setPixelColor(0, pixels.Color(colors[color][0], colors[color][1], colors[color][2]));
pixels.show(); // Send the updated pixel colors to the hardware.
}
void ResetMode() { // Reset the configuration mode after each reading
Serial.println("Re-initializing...");
nfc.ConfigMode(mode);
nfc.StartDiscovery(mode);
}
void PrintBuf(const byte * data, const uint32_t numBytes){ //Print hex data buffer in format
uint32_t szPos;
for (szPos=0; szPos < numBytes; szPos++)
{
Serial.print(F("0x"));
// Append leading 0 for small values
if (data[szPos] <= 0xF)
Serial.print(F("0"));
Serial.print(data[szPos]&0xff, HEX);
if ((numBytes > 1) && (szPos != numBytes - 1))
{
Serial.print(F(" "));
}
}
Serial.println();
}
void displayCardInfo(RfIntf_t RfIntf){ //Funtion in charge to show the card/s in te field
char tmp[16];
while (1){
switch(RfIntf.Protocol){ //Indetify card protocol
case PROT_T1T:
case PROT_T2T:
case PROT_T3T:
case PROT_ISODEP:
Serial.print(" - POLL MODE: Remote activated tag type: ");
Serial.println(RfIntf.Protocol);
break;
case PROT_ISO15693:
Serial.println(" - POLL MODE: Remote ISO15693 card activated");
break;
case PROT_MIFARE:
Serial.println(" - POLL MODE: Remote MIFARE card activated");
break;
default:
Serial.println(" - POLL MODE: Undetermined target");
return;
}
switch(RfIntf.ModeTech) { //Indetify card technology
case (MODE_POLL | TECH_PASSIVE_NFCA):
Serial.print("\tSENS_RES = ");
sprintf(tmp, "0x%.2X",RfIntf.Info.NFC_APP.SensRes[0]);
Serial.print(tmp); Serial.print(" ");
sprintf(tmp, "0x%.2X",RfIntf.Info.NFC_APP.SensRes[1]);
Serial.print(tmp); Serial.println(" ");
Serial.print("\tNFCID = ");
PrintBuf(RfIntf.Info.NFC_APP.NfcId, RfIntf.Info.NFC_APP.NfcIdLen);
if(RfIntf.Info.NFC_APP.SelResLen != 0) {
Serial.print("\tSEL_RES = ");
sprintf(tmp, "0x%.2X",RfIntf.Info.NFC_APP.SelRes[0]);
Serial.print(tmp); Serial.println(" ");
}
break;
case (MODE_POLL | TECH_PASSIVE_NFCB):
if(RfIntf.Info.NFC_BPP.SensResLen != 0) {
Serial.print("\tSENS_RES = ");
PrintBuf(RfIntf.Info.NFC_BPP.SensRes,RfIntf.Info.NFC_BPP.SensResLen);
}
break;
case (MODE_POLL | TECH_PASSIVE_NFCF):
Serial.print("\tBitrate = ");
Serial.println((RfIntf.Info.NFC_FPP.BitRate == 1) ? "212" : "424");
if(RfIntf.Info.NFC_FPP.SensResLen != 0) {
Serial.print("\tSENS_RES = ");
PrintBuf(RfIntf.Info.NFC_FPP.SensRes,RfIntf.Info.NFC_FPP.SensResLen);
}
break;
case (MODE_POLL | TECH_PASSIVE_15693):
Serial.print("\tID = ");
PrintBuf(RfIntf.Info.NFC_VPP.ID,sizeof(RfIntf.Info.NFC_VPP.ID));
Serial.print("\ntAFI = ");
Serial.println(RfIntf.Info.NFC_VPP.AFI);
Serial.print("\tDSFID = ");
Serial.println(RfIntf.Info.NFC_VPP.DSFID,HEX);
break;
default:
break;
}
if(RfIntf.MoreTags) { // It will try to identify more NFC cards if they are the same technology
if(nfc.ReaderActivateNext(&RfIntf) == NFC_ERROR) break;
}
else break;
}
}
void setup(){
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
pinMode(BUZZER_PIN, OUTPUT);
//while(!Serial)
delay(10);
Serial.begin(115200);
pixels.begin();
pixels.clear(); // Set all pixel colors to 'off'
set_rgb_led(RGB_RED);
Serial.println("Detect NFC tags with PN7150");
Serial.println("Initializing...");
if (nfc.connectNCI()) { //Wake up the board
Serial.println("Error while setting up the mode, check connections!");
while (1);
}
if (nfc.ConfigureSettings()) {
Serial.println("The Configure Settings is failed!");
while (1);
}
if(nfc.ConfigMode(mode)){ //Set up the configuration mode
Serial.println("The Configure Mode is failed!!");
while (1);
}
Serial.println("Initialization succeeded !");
if (nfc.StartDiscovery(mode) == SUCCESS) {
Serial.println("Successfully started discovery mode !");
} else {
Serial.println("Failed to start discovery mode !");
while(1);
}
Serial.println("Waiting for a Card ...");
set_rgb_led(RGB_GREEN);
}
void loop(){
if(!nfc.WaitForDiscoveryNotification(&RfInterface)){ // Waiting to detect cards
set_rgb_led(RGB_BLUE);
digitalWrite(LED_BUILTIN, HIGH);
displayCardInfo(RfInterface);
switch(RfInterface.Protocol) {
case PROT_T1T:
case PROT_T2T:
case PROT_T3T:
case PROT_ISODEP:
nfc.ProcessReaderMode(RfInterface, READ_NDEF);
break;
case PROT_ISO15693:
break;
case PROT_MIFARE:
nfc.ProcessReaderMode(RfInterface, READ_NDEF);
break;
default:
break;
}
tone(BUZZER_PIN, 2000, 100);
//* It can detect multiple cards at the same time if they use the same protocol
if(RfInterface.MoreTags) {
nfc.ReaderActivateNext(&RfInterface);
}
//* Wait for card removal
nfc.ProcessReaderMode(RfInterface, PRESENCE_CHECK);
Serial.println("CARD REMOVED!");
set_rgb_led(RGB_GREEN);
digitalWrite(LED_BUILTIN, LOW);
nfc.StopDiscovery();
nfc.StartDiscovery(mode);
}
ResetMode();
delay(50);
}
0 Comments for “Quick start example for the Challenger RP2040 NFC board”