worm13 发表于 2013-3-26 10:22:27

各位大神,求助enc28j60

之前用enc28j60+arduino+yeelink做了个小系统,现在想让pc和arduino通信,怎么也调不通啊,我原来是用的
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet");

Serial.println("Setting up DHCP");
if (!ether.dhcpSetup())
    Serial.println( "DHCP failed");

ether.printIp("My IP: ", ether.myip);
   ether.printIp("Netmask: ", ether.mymask);
ether.printIp("GW IP: ", ether.gwip);
ether.printIp("DNS IP: ", ether.dnsip);

这个局域网里可以ping通,外网也可以ping通,现在想调局域网内的通讯却怎么也搞不通,用的是
Ethernet.begin(mac, ip);
加上网关和掩码也不行,局域网内ping都ping不通,搞不明白啊,是库用的不对还是怎么回事
ide 1.01,求大神指导

worm13 发表于 2013-3-26 10:25:55

还有另外一个库,程序是
#include <EtherCard.h>

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 172,20,10,203 };
char website[] PROGMEM = "api.yeelink.net";
byte Ethernet::buffer;

static BufferFiller bfill;// used as cursor while filling the buffer
void setup () {
Serial.begin(9600);
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
Serial.println("Setting up DHCP");
if (!ether.dhcpSetup())
    Serial.println( "DHCP failed");

ether.printIp("My IP: ", ether.myip);
   ether.printIp("Netmask: ", ether.mymask);
ether.printIp("GW IP: ", ether.gwip);
ether.printIp("DNS IP: ", ether.dnsip);

if (!ether.dnsLookup(website))
    Serial.println("DNS failed");
ether.printIp("Server: ", ether.hisip);

   Ethernet.begin(mac,ether.myip);
   server.begin();
}

static word homePage() {
long t = millis() / 1000;
word h = t / 3600;
byte m = (t / 60) % 60;
byte s = t % 60;
bfill = ether.tcpOffset();
bfill.emit_p(PSTR(
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Pragma: no-cache\r\n"
    "\r\n"
    "<meta http-equiv='refresh' content='1'/>"
    "<title>RBBB server</title>"
    "<h1>$D$D:$D$D:$D$D</h1>"),
      h/10, h%10, m/10, m%10, s/10, s%10);
   
return bfill.position();
}

void loop () {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
Serial.println(len);
Serial.println(pos);
if (pos)// check if valid tcp data is received
{
    bfill = ether.tcpOffset();
    Serial.println("data=");

    char* data = (char *) Ethernet::buffer + pos;
// Serial.println(data,DEC);
    ether.tcpSend();
delay(200);
}
//ether.httpServerReply(homePage()); // send web page data
}
这个可以ping通,但是数据发不过去,有可能是没弄懂怎么显示,发过去的应该是字符串,不知道怎么转换,搞不懂啊,求大神指点

ChunYong 发表于 2013-3-26 16:34:28

示例里的 server 应以啊
qq 365815350 应该能帮到你
页: [1]
查看完整版本: 各位大神,求助enc28j60