enc28j60 + nfc pn532
- Войдите на сайт для отправки комментариев
Пт, 06/11/2015 - 00:29
Помогите, пожалуйста, разобраться со скетчем.
Пытаюсь завести вместе ethernet enc28j60 и adafruit pn532. NFC секция работает нормально, ID карточек читается, а вот сеть становится доступна только, когда карточку прикладываю.
#include <EtherCard.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
#define PN532_IRQ (2)
#define PN532_RESET (3)
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
static byte myip[] = { 192, 168, 2, 15 };
static byte gwip[] = { 192, 168, 2, 1 };
static byte mymac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
int ledPin = 6;
byte Ethernet::buffer[300];
BufferFiller bfill;
const char page[] PROGMEM =
"\r\n"
"Main page"
;
const char cmd_on[] PROGMEM =
"\r\n"
"Received ON command"
;
const char cmd_off[] PROGMEM =
"\r\n"
"Received OFF command"
;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
Serial.println("Hola caracola!");
if (!ether.begin(sizeof Ethernet::buffer, mymac, 10))
{
Serial.println( "Failed to access Ethernet controller");
while(1);
}
else
Serial.println("Ethernet controller initialized");
ether.staticSetup(myip, gwip);
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1);
}
Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A Card ...");
}
void loop() {
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
uint8_t uidLength;
word pos = ether.packetLoop(ether.packetReceive());
if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength)) {
Serial.print(" UID Value: ");
nfc.PrintHex(uid, uidLength);
}
if (pos) {
bfill = ether.tcpOffset();
char* data = (char *) Ethernet::buffer + pos;
Serial.println(data);
if (strstr((char *)Ethernet::buffer + pos, "GET /?on") != 0) {
Serial.println("Received ON command");
digitalWrite(ledPin, HIGH);
bfill.emit_p(cmd_on);
}
else if (strstr((char *)Ethernet::buffer + pos, "GET /?off") != 0) {
Serial.println("Received OFF command");
digitalWrite(ledPin, LOW);
bfill.emit_p(cmd_off);
}
else
bfill.emit_p(page);
ether.httpServerReply(bfill.position());
}
}