小白求助 STM32和w5100通信的问题?

u010269902 2016-04-29 06:08:08
最近在学习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;
}
...全文
288 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
上升沿有效 2019-05-08
  • 打赏
  • 举报
回复
https://download.csdn.net/download/qq_26400365/11147707
qq_43278700 2019-05-06
  • 打赏
  • 举报
回复
引用 楼主 u010269902的回复:
最近在学习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;
}
你的32驱动w5100通讯成功了吗
qq_43278700 2019-05-06
  • 打赏
  • 举报
回复
引用 楼主 u010269902的回复:
最近在学习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;
}
你好,你的成功了吗?可以分享给我吗

27,373

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧