你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【求助】mbed上如何实现串口监视?

[复制链接]
snowy_luoluo 提问时间:2016-5-4 16:03 /
本帖最后由 snowy_luoluo 于 2016-5-4 16:10 编辑

我使用的是 STM32F103RB 和Ethernet Shield W5100

在mbed上找到相关的例程,这个实例会由mbed.org 伺服器收取一个档案叫hello.txt

我看到代码中有很多printf语句,但是编译运行后不知道该如何操作和查看?而mbed上面又没有像Arduino那样的串口监视?
还有对于本地电脑的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. }
复制代码




收藏 评论3 发布时间:2016-5-4 16:03

举报

3个回答
snowy_luoluo 回答时间:2016-5-4 16:41:13
本帖最后由 snowy_luoluo 于 2016-5-4 16:45 编辑

问题解决了
打开串口助手波特率9600 就可以显示
但是又出现了新的问题 一直显示
DHCP Started, waiting for IP...
Timeout.
>>> Could not connect to network! Retrying ...
mbed Eth 串口助手_连接失败2.png
不知道该怎么解决??
suoma 回答时间:2016-5-4 22:11:59
不经过路由器试一下,直接连网线
jinglixixi 回答时间:2016-5-5 08:41:53
IP地址是否必须设置在同一网段才可以!

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版