如何将Arduino Micro连接到以太网模块ENC28J66并运行EtherCard BackSoon示例?

时间:2016-11-17 21:19:56

标签: arduino ethernet

我有这样的arduino micro(oryginal):https://www.arduino.cc/en/Main/ArduinoBoardMicro和ENC28J66芯片组的以太网bord克隆。

以太网板上的引脚配置:

  1. CKOUT
  2. / INT
  3. / WOL
  4. SO
  5. SI
  6. SCK
  7. / CS
  8. / RESET
  9. VCC(5V)(焊接一个地方后也可以使用3.3V)
  10. GND
  11. 我尝试使用几个连接组合运行示例BackSoon for EtherCard库,但这让我“无法访问以太网控制器”

    然后我这样设置: 微| ENC28J60

    • SCK - SCK
    • MISO - SO
    • MOSI - SI
    • SS - CS
    • 5V - VCC
    • GND - GND
    • 10 PIN - INT

    此配置不会生成访问错误,但DHCP失败。 DHCP服务器配置肯定是好的。 即使我设置静态IP地址,也不会像http那样对此IP进行响应。

    我尝试使用dhcp的完整代码:

    #include <EtherCard.h>
    #define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)
    
    #if STATIC
    // ethernet interface ip address
    static byte myip[] = { 172,16,10,222 };
    // gateway ip address
    static byte gwip[] = { 172,16,10,1 };
    #endif
    
    // ethernet mac address - must be unique on your network
    static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
    
    byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
    
    const char page[] PROGMEM =
    "HTTP/1.0 503 Service Unavailable\r\n"
    "Content-Type: text/html\r\n"
    "Retry-After: 600\r\n"
    "\r\n"
    "<html>"
      "<head><title>"
        "Service Temporarily Unavailable"
      "</title></head>"
      "<body>"
        "<h3>This service is currently unavailable</h3>"
        "<p><em>"
          "The main server is currently off-line.<br />"
          "Please try again later."
        "</em></p>"
      "</body>"
    "</html>"
    ;
    
    void setup(){
      Serial.begin(57600);
      while (!Serial) ;
      Serial.println("\n[backSoon]");
    
      if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0) 
        Serial.println( "Failed to access Ethernet controller");
    #if STATIC
      ether.staticSetup(myip, gwip);
    #else
      if (!ether.dhcpSetup())
        Serial.println("DHCP failed");
    #endif
    
      ether.printIp("IP:  ", ether.myip);
      ether.printIp("GW:  ", ether.gwip);  
      ether.printIp("DNS: ", ether.dnsip);  
    }
    
    void loop(){
      // wait for an incoming TCP packet, but ignore its contents
      if (ether.packetLoop(ether.packetReceive())) {
        Serial.println("got one!");
        memcpy_P(ether.tcpOffset(), page, sizeof page);
        ether.httpServerReply(sizeof page - 1);
      }
    }
    

    串行回复:

    [backSoon]
    DHCP failed
    IP:  0.0.0.0
    GW:  0.0.0.0
    DNS: 0.0.0.0
    

    有人可以帮助我推动连接并运行任何样本(如BackSoon)吗?

    是否可以一起使用Micro和ENC28J60? 是否有可能为他们使用EtherCard库?

1 个答案:

答案 0 :(得分:0)

你的问题已经过了很长时间,但我希望这可以帮助别人。

  • 微型以太网
  • SCK - SCK
  • MISO - SO
  • MOSI - SI
  • PIN 8 - CS(8是以太网卡的默认值,代码中为10)
  • 5V - VCC
  • GND - GND