forked from sabas1080/PN7150
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ElectronicCats/P2P
Add support P2P and NDEF NFC
- Loading branch information
Showing
24 changed files
with
3,659 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Example to detect P2P device | ||
* Authors: | ||
* Salvador Mendoza - @Netxing - salmg.net | ||
* For Electronic Cats - electroniccats.com | ||
* | ||
* 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" | ||
#define PN7150_IRQ (15) | ||
#define PN7150_VEN (14) | ||
#define PN7150_ADDR (0x28) | ||
|
||
Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR); // creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28 | ||
RfIntf_t RfInterface; //Intarface to save data for multiple tags | ||
|
||
uint8_t mode = 3; // modes: 1 = Reader/ Writer, 2 = Emulation, 3 = Peer to peer P2P | ||
|
||
int ResetMode(){ //Reset the configuration mode after each reading | ||
Serial.println("Re-initializing..."); | ||
nfc.ConfigMode(mode); | ||
nfc.StartDiscovery(mode); | ||
} | ||
|
||
|
||
void setup(){ | ||
Serial.begin(9600); | ||
while(!Serial); | ||
Serial.println("Detect P2P devices 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 failed!"); | ||
while (1); | ||
} | ||
|
||
if(nfc.ConfigMode(mode)){ //Set up the configuration mode | ||
Serial.println("The Configure Mode failed!!"); | ||
while (1); | ||
} | ||
nfc.StartDiscovery(mode); //NCI Discovery mode | ||
Serial.println("Waiting for a P2P device..."); | ||
} | ||
|
||
void loop(){ | ||
if(!nfc.WaitForDiscoveryNotification(&RfInterface)){ // Waiting to detect | ||
if (RfInterface.Interface == INTF_NFCDEP) { | ||
if ((RfInterface.ModeTech & MODE_LISTEN) == MODE_LISTEN) | ||
Serial.println(" - P2P TARGET MODE: Activated from remote Initiator"); | ||
else | ||
Serial.println(" - P2P INITIATOR MODE: Remote Target activated"); | ||
|
||
/* Process with SNEP for NDEF exchange */ | ||
nfc.ProcessP2pMode(RfInterface); | ||
Serial.println("Peer lost!"); | ||
} | ||
ResetMode(); | ||
} | ||
delay(500); | ||
} |
Oops, something went wrong.