极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11989|回复: 0

请教一个关于STM32F103和Ethernet Shield W5100的问题

[复制链接]
发表于 2016-5-4 15:25:08 | 显示全部楼层 |阅读模式
我最近在使用STM32F103和Ethernet Shield W5100模块进行测试,在mbed官网的在线平台上有一个相关例程,
https://developer.mbed.org/teams/shields/code/Seeed_Ethernet_Shield/

我连接上两个模块,并编译成功了这个例程。在例程中有很多printf的语句,如
printf(">>> Could not initialise. Halting!\n");
printf(">>> Get IP address...\n");
printf(">>> Got IP address: %s\n", eth.getIPAddress());

但是我不知道该如何查看测试的结果??我看到一些资料说要在浏览器里输入IP地址查看,但是我该输入什么呢?例程中并没有设定是哪个地址?想请教下我该如何查看或者设置?谢谢!

以下是全部例程代码
  1. #include "mbed.h"
  2. #include "WIZ820ioInterface.h"

  3. Serial pc(USBTX, USBRX);

  4. /**
  5. * D11 - MOSI pin
  6. * D12 - MISO pin
  7. * D13 - SCK pin
  8. * D10 - SEL pin
  9. * NC - Reset pin; use D5 otherwise the shield might get into reset loop
  10. */
  11. WIZ820ioInterface eth(D11, D12, D13, D10, D5);

  12. int main()
  13. {
  14.     wait(3);
  15.    
  16.     // Initialize the interface.
  17.     // If no param is passed to init() then DHCP will be used on connect()
  18.     int s = eth.init();
  19.     if (s != NULL) {
  20.         printf(">>> Could not initialise. Halting!\n");
  21.         exit(0);
  22.     }

  23.     printf(">>> Get IP address...\n");
  24.     while (1) {
  25.         s = eth.connect(); // Connect to network

  26.         if (s == false || s < 0) {
  27.             printf(">>> Could not connect to network! Retrying ...\n");
  28.             wait(3);
  29.         } else {
  30.             break;
  31.         }
  32.     }
  33.     printf(">>> Got IP address: %s\n", eth.getIPAddress());

  34.     // Prepare the http request to mbed.org
  35.     printf(">>> Open socket to mbed.org:80\n");
  36.     char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
  37.     TCPSocketConnection sock;
  38.    
  39.     while (sock.connect("mbed.org", 80) == -1) {
  40.         printf(">>> Unable to open socket! Retrying ...\n");
  41.     };
  42.    
  43.     printf(">>> Request %s\n", http_cmd);
  44.     sock.send_all(http_cmd, sizeof(http_cmd)-1);

  45.     // Read the response
  46.     char buffer[300];
  47.     int ret;
  48.     while (true) {
  49.         ret = sock.receive(buffer, sizeof(buffer)-1);
  50.         if (ret <= 0)
  51.             break;
  52.         buffer[ret] = '\0';
  53.         printf(">>> Received %d chars from mbed.org:\n%s\n", ret, buffer);
  54.     }

  55.     printf(">>> Close socket\n");
  56.     sock.close();
  57.    
  58.     // Disconnect from network
  59.     printf(">>> Disconnect from network\n");
  60.     eth.disconnect();

  61.     return 0;
  62. }
复制代码
回复

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-17 01:24 , Processed in 0.039443 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表