极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8256|回复: 2

各位大神,求助enc28j60

[复制链接]
发表于 2013-3-26 10:22:27 | 显示全部楼层 |阅读模式
之前用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,求大神指导

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 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[500];

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"
    "ragma: no-cache\r\n"
    "\r\n"
    "<meta http-equiv='refresh' content='1'/>"
    "<title>RBBB server</title>"
    "<h1>$D$DD$DD$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通,但是数据发不过去,有可能是没弄懂怎么显示,发过去的应该是字符串,不知道怎么转换,搞不懂啊,求大神指点
回复 支持 反对

使用道具 举报

发表于 2013-3-26 16:34:28 | 显示全部楼层
示例里的 server 应以啊
qq 365815350 应该能帮到你
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-9 13:22 , Processed in 0.040804 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表