小白求助 STM32和w5100通信的问题?
最近在学习STM32和w5100网络通信。
在mbed上面找了一个例程,编译完以后该不知道如何查看?PC端用的是友善串口调试助手里的以太网调试功能。不知道参数应该如何设置?IP地址和port应该如何填?点击开始一直提示SOCKET 没有连接成功。
以下是代码
#include "mbed.h"
#include "WIZ820ioInterface.h"
Serial pc(USBTX, USBRX);
/**
* D11 - MOSI pin
* D12 - MISO pin
* D13 - SCK pin
* D10 - SEL pin
* NC - Reset pin; use D5 otherwise the shield might get into reset loop
*/
WIZ820ioInterface eth(D11, D12, D13, D10, D5);
int main()
{
wait(3);
// Initialize the interface.
// If no param is passed to init() then DHCP will be used on connect()
int s = eth.init();
if (s != NULL) {
printf(">>> Could not initialise. Halting!\n");
exit(0);
}
printf(">>> Get IP address...\n");
while (1) {
s = eth.connect(); // Connect to network
if (s == false || s < 0) {
printf(">>> Could not connect to network! Retrying ...\n");
wait(3);
} else {
break;
}
}
printf(">>> Got IP address: %s\n", eth.getIPAddress());
// Prepare the http request to mbed.org
printf(">>> Open socket to mbed.org:80\n");
char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
TCPSocketConnection sock;
while (sock.connect("mbed.org", 80) == -1) {
printf(">>> Unable to open socket! Retrying ...\n");
};
printf(">>> Request %s\n", http_cmd);
sock.send_all(http_cmd, sizeof(http_cmd)-1);
// Read the response
char buffer[300];
int ret;
while (true) {
ret = sock.receive(buffer, sizeof(buffer)-1);
if (ret <= 0)
break;
buffer[ret] = '\0';
printf(">>> Received %d chars from mbed.org:\n%s\n", ret, buffer);
}
printf(">>> Close socket\n");
sock.close();
// Disconnect from network
printf(">>> Disconnect from network\n");
eth.disconnect();
return 0;
}
在mbed上面找了一个例程,编译完以后该不知道如何查看?PC端用的是友善串口调试助手里的以太网调试功能。不知道参数应该如何设置?IP地址和port应该如何填?点击开始一直提示SOCKET 没有连接成功。
以下是代码
#include "mbed.h"
#include "WIZ820ioInterface.h"
Serial pc(USBTX, USBRX);
/**
* D11 - MOSI pin
* D12 - MISO pin
* D13 - SCK pin
* D10 - SEL pin
* NC - Reset pin; use D5 otherwise the shield might get into reset loop
*/
WIZ820ioInterface eth(D11, D12, D13, D10, D5);
int main()
{
wait(3);
// Initialize the interface.
// If no param is passed to init() then DHCP will be used on connect()
int s = eth.init();
if (s != NULL) {
printf(">>> Could not initialise. Halting!\n");
exit(0);
}
printf(">>> Get IP address...\n");
while (1) {
s = eth.connect(); // Connect to network
if (s == false || s < 0) {
printf(">>> Could not connect to network! Retrying ...\n");
wait(3);
} else {
break;
}
}
printf(">>> Got IP address: %s\n", eth.getIPAddress());
// Prepare the http request to mbed.org
printf(">>> Open socket to mbed.org:80\n");
char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
TCPSocketConnection sock;
while (sock.connect("mbed.org", 80) == -1) {
printf(">>> Unable to open socket! Retrying ...\n");
};
printf(">>> Request %s\n", http_cmd);
sock.send_all(http_cmd, sizeof(http_cmd)-1);
// Read the response
char buffer[300];
int ret;
while (true) {
ret = sock.receive(buffer, sizeof(buffer)-1);
if (ret <= 0)
break;
buffer[ret] = '\0';
printf(">>> Received %d chars from mbed.org:\n%s\n", ret, buffer);
}
printf(">>> Close socket\n");
sock.close();
// Disconnect from network
printf(">>> Disconnect from network\n");
eth.disconnect();
return 0;
}
...全文
相关推荐
STM32驱动W5100实现http的网页浏览
STM32驱动W5100实现HTTP网页浏览是一个典型的嵌入式网络应用,涉及到的知识点包括STM32微控制器、W5100网络芯片、SPI通信协议以及HTTP协议的实现。
STM32+W5100_W5100在STM32上的应用_W5100_stm32w5100_
**固件更新**:W5100支持固件升级,可以通过STM32读写W5100的内部存储器来实现。这在调试或修复协议栈问题时非常有用。8.
STM32 W5100 UDP和TCP协议
通过阅读和分析这些代码,开发者可以了解如何在实际工程中应用STM32和W5100进行网络通信。
W5100 stm32 SPI 口程序
标题中的“W5100 STM32的SPI口程序”指的是使用STM32微控制器通过SPI(Serial Peripheral Interface)接口与W5100网络芯片进行通信的开发代码。
W5100 W5200 W5500平台使用DHCP功能 51STM32等平台
本项目实现了基于W5100/W5200/W5500网络芯片的DHCP客户端功能,适用于STM32等嵌入式平台。代码包含DHCP发现、请求、确认等完整状态机流程,结合定时器机制进行超时控制与周期处理,并


单片机/工控
