1430|0

451

帖子

3

TA的资源

纯净的硅(高级)

楼主
 

基础任务一:完成主控板W5500初始化(静态IP配置),并能使用局域网电脑ping通 [复制链接]

 

这篇来测试基础任务一,使用Arduino IDE软件编译。

 

一、配置软件

 

1.1、添加开发板库文件

链接已隐藏,如需查看请登录或者注册

 

1.2、安装开发板库文件

 

1.3、下载软件包

链接已隐藏,如需查看请登录或者注册

 

1.4、添加库

手动添加库文件,将下载的文件复制到下面文件。

 

二、软件

 

测试代码:

  • #include <SPI.h>
  • #include <Ethernet.h>
  • #include <Dns.h>
  • #include <EthernetICMP.h>
  • // 网卡mac地址
  • byte mac[] = { 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF };
  • DNSClient dnClient;
  • IPAddress dstip;
  • SOCKET pingSocket = 0;
  • char buffer[256];
  • EthernetICMPPing ping(pingSocket, (uint16_t)random(0, 255));
  • // 静态ip地址、DNS服务、网关、子网掩码
  • IPAddress ip(192, 168, 1, 205);
  • IPAddress myDns(192, 168, 1, 1);
  • IPAddress gateway(192, 168, 1, 1);
  • IPAddress subnet(255, 255, 255, 0);
  • void setup() {
  • // 配置LED
  • pinMode(LED_BUILTIN, OUTPUT);
  • // 配置串口
  • Serial.begin(115200);
  • while (!Serial) {
  • ; // 等待串口连接
  • }
  • // 静态IP设置
  • Serial.println("Ethernet Begin");
  • Ethernet.init(17);
  • Ethernet.begin(mac, ip, myDns, gateway, subnet);
  • // 输出网卡mac地址、IP地址、子网掩码、DNS、网关
  • Serial.print("My Mac address: ");
  • byte macBuffer[6]; // 设置mac地址存储buff
  • Ethernet.MACAddress(macBuffer); // 读取mac地址
  • for (byte octet = 0; octet < 6; octet++) {
  • Serial.print(macBuffer[octet], HEX);
  • if (octet < 5) {
  • Serial.print('-');
  • }
  • }
  • Serial.println("");
  • Serial.print("My IP address: ");
  • Serial.println(Ethernet.localIP());
  • Serial.print("My subnet: ");
  • Serial.println(Ethernet.subnetMask());
  • Serial.print("My DNS address: ");
  • Serial.println(Ethernet.dnsServerIP());
  • Serial.print("My GateWay address: ");
  • Serial.println(Ethernet.gatewayIP());
  • dnClient.begin(Ethernet.dnsServerIP());
  • const char domains[] = "www.eeworld.com.cn";
  • if (dnClient.getHostByName(domains, dstip) == 1) {
  • Serial.print(domains);
  • Serial.print(" = ");
  • Serial.println(dstip);
  • }
  • else Serial.println(F("dns lookup failed"));
  • }
  • void loop() {
  • EthernetICMPEchoReply echoReply = ping(dstip, 4);
  • if (echoReply.status == SUCCESS)
  • {
  • sprintf(buffer,
  • "Reply[%d] from: %d.%d.%d.%d: bytes=%d time=%ldms TTL=%d",
  • echoReply.data.seq,
  • echoReply.addr[0],
  • echoReply.addr[1],
  • echoReply.addr[2],
  • echoReply.addr[3],
  • REQ_DATASIZE,
  • millis() - echoReply.data.time,
  • echoReply.ttl);
  • }
  • else
  • {
  • sprintf(buffer, "Echo request failed; %d", echoReply.status);
  • }
  • Serial.println(buffer);
  • digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  • delay(100); // wait for a second
  • digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  • delay(500); // wait for a second
  • }

 

三、运行

 

3.1、静态IP获取

下载程序后,串口输出配置的静态IP地址

 

3.2、ping网络

 

3.3、抓捕工具捕获

 

点赞 关注
 
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
报名最后一周!2025 英飞凌消费、计算与通讯创新大会-北京站
会议时间:3月18日(周二)09:30签到
参会奖励:电动螺丝刀套装、户外登山包、京东卡

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表