【发布时间】:2016-11-17 21:19:55
【问题描述】:
我有这样的 arduino micro(原始):https://www.arduino.cc/en/Main/ArduinoBoardMicro 和带有 ENC28J66 芯片组的以太网端口的克隆。
以太网板上的针脚配置:
- 关闭
- /INT
- /WOL
- 所以
- SI
- SCK
- /CS
- /重置
- VCC(5V)(焊接一处后也可以使用3.3V)
- 接地
我尝试为 EtherCard 库运行示例 BackSoon,但连接组合很少,但这给了我“无法访问以太网控制器”
然后我这样设置: 微 | ENC28J60
- SCK - SCK
- 味噌 - 所以
- MOSI - SI
- SS - CS
- 5V - VCC
- 接地 - 接地
- 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 库?
【问题讨论】: