【求助】mbed上如何实现串口监视?
本帖最后由 snowy_luoluo 于 2016-5-4 16:10 编辑我使用的是 STM32F103RB 和Ethernet Shield W5100
在mbed上找到相关的例程,这个实例会由mbed.org 伺服器收取一个档案叫hello.txt
我看到代码中有很多printf语句,但是编译运行后不知道该如何操作和查看?而mbed上面又没有像Arduino那样的串口监视?
还有对于本地电脑的IP设置有没有什么需要注意的?请教一下各位,谢谢了!
#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;
int ret;
while (true) {
ret = sock.receive(buffer, sizeof(buffer)-1);
if (ret <= 0)
break;
buffer = '\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;
}
本帖最后由 snowy_luoluo 于 2016-5-4 16:45 编辑
问题解决了
打开串口助手波特率9600 就可以显示
但是又出现了新的问题 一直显示
DHCP Started, waiting for IP...
Timeout.
>>> Could not connect to network! Retrying ...
不知道该怎么解决??
不经过路由器试一下,直接连网线 IP地址是否必须设置在同一网段才可以!
页:
[1]