Let me be more clear .
this is the simple code :
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//libraries for NFC
#include <Arduino.h>
#include <NfcAdapter.h>
#include <PN532/PN532/PN532.h>
#include <PN532/PN532/emulatetag.h>
#include <PN532/PN532_HSU/PN532_HSU.h>
#include "NdefMessage.h"
PN532_HSU pn532hsu ( Serial2 ) ;
EmulateTag nfc ( pn532hsu ) ;
NfcAdapter nfc_adapter = NfcAdapter ( pn532hsu ) ;
uint8_t ndefBuf [ 120 ] ;
NdefMessage message ;
int messageSize ;
uint8_t uid[3] = { 0x12, 0x34, 0x56 };
void setup()
{
Serial.begin(115200);
Serial.println("------- Emulate Tag --------") ;
message = NdefMessage() ;
message.addUriRecord("http://www.seeedstudio.com");
messageSize = message.getEncodedSize();
if (messageSize > sizeof(ndefBuf)) {
Serial.println("ndefBuf is too small");
while (1) { }
}
Serial.print("Ndef encoded message size: ");
Serial.println(messageSize);
message.encode(ndefBuf);
// comment out this command for no ndef message
nfc.setNdefFile(ndefBuf, messageSize);
// uid must be 3 bytes!
nfc.setUid(uid);
nfc.init();
}
// the loop function runs over and over again until power down or reset
void loop()
{
Serial.println("Begin emulation.");
if (!nfc.emulate(10000))//timeout 10 seconds
Serial.println("timed out");
else
Serial.println("mobile device found!");
if (nfc.writeOccured()) {
Serial.println("\nWrite occured !");
uint8_t *tag_buf;
uint16_t length;
nfc.getContent(&tag_buf, &length);
NdefMessage msg = NdefMessage(tag_buf, length);
msg.print();
}
delay(1000);
}
when I use this code I expect that if I keep my android phone , near to the pn532 module , the URL comes up . but nothing happen . after using NFC reader application I found that the pn532 is emulating to Felica card , not Mifare classic .
this is the issue .
after changing this code of emulate() in emulate.cpp from this
uint8_t command[] = {
PN532_COMMAND_TGINITASTARGET,
5, // MODE: PICC only, Passive only
0x04, 0x00, // SENS_RES
0x00, 0x00, 0x00, // NFCID1
0x20, // SEL_RES
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, // FeliCaParams
0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // NFCID3t
0, // length of general bytes
0 // length of historical bytes
};
to this
uint8_t command[] = {
PN532_COMMAND_TGINITASTARGET,
0x05, // MODE: 0x04 = PICC only, 0x01 = Passive only (0x02 = DEP only)
// MIFARE PARAMS
0x04, 0x00, // SENS_RES (seeeds studio set it to 0x04, nxp to 0x08)
0x00, 0x00, 0x00, // NFCID1t (is set over sketch with setUID())
0x20, // SEL_RES (0x20=Mifare DelFire, 0x60=custom)
// FELICA PARAMS
0x01, 0xFE, // NFCID2t (8 bytes) https://github.com/adafruit/Adafruit-PN532/blob/master/Adafruit_PN532.cpp FeliCa NEEDS TO BEGIN WITH 0x01 0xFE!
0x05, 0x01, 0x86,
0x04, 0x02, 0x02,
0x03, 0x00, // PAD (8 bytes)
0x4B, 0x02, 0x4F,
0x49, 0x8A, 0x00,
0xFF, 0xFF, // System code (2 bytes)
0x01, 0x01, 0x66, // NFCID3t (10 bytes)
0x6D, 0x01, 0x01, 0x10,
0x02, 0x00, 0x00,
0x00, // length of general bytes
0x00 // length of historical bytes
};
my android phone can get nothing .