Home > other >  Small white help STM32 and w5100 communication problems?
Small white help STM32 and w5100 communication problems?

Time:10-14

Recently in learning STM32 and w5100 network communication,
Above the mbed found a routine, compiled after the don't know how to view? PC with friendly Ethernet debugging serial debugging assistant, don't know how to set parameters should be? IP address and port should be how to fill in? Click start always prompt the SOCKET connection is successful,

The following is a code

# 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 shields took the get into reset loop
*/
WIZ820ioInterface eth (D11, D12, D13, D10, D5);

Int main ()
{
Wait (3);

//Initialize the interface.
//If no param is passed to the init () then the DHCP will be 2 on the connect ()
Int=s eth. The init ();
If (s!=NULL) {
Printf (" & gt;> Could not initialise Halting! \n");
The exit (0);
}

Printf (" & gt;> Get the IP address... \n");
While (1) {
S=the eth. The connect ();//Connect to the network

If (s==false | | s & lt; 0 {
Printf (" & gt;> Could not connect to the network! Retrying... \n");
Wait (3);
} else {
break;
}
}
Printf (" & gt;> Got an IP address: % s \ n ", eth. GetIPAddress ());

//Prepare the HTTP request to mbed.org
Printf (" & gt;> Open a socket to mbed.org: 80 \ n ");
Char http_cmd []="the GET/media/uploads/mbed_official/hello. TXT HTTP/1.0 \ n \ n";
TCPSocketConnection sock.

While (the sock. Connect (" mbed.org ", 80)==1) {
Printf (" & gt;> Unable to open the socket! Retrying... \n");
};

Printf (" & gt;> Request % s \ n ", http_cmd);
The sock. Send_all (http_cmd, sizeof (http_cmd) - 1);

//Read the response
Char buffer [300].
int ret;
While (true) {
Ret=the sock. The receive (buffer, sizeof (buffer) - 1);
If (ret & lt;=0)
break;
Buffer (ret)='\ 0';
Printf (" & gt;> A Received % d chars from mbed.org: \ n \ n % s ", ret, buffer);
}

Printf (" & gt;> Close the socket \ n ");
The sock. The close ();

//Disconnect from the network
Printf (" & gt;> Disconnect from the network \ n ");
The eth. Disconnect ();

return 0;
}

CodePudding user response:

refer to the original poster u010269902 response:
recently in learning STM32 and w5100 network communication,
Above the mbed found a routine, compiled after the don't know how to view? PC with friendly Ethernet debugging serial debugging assistant, don't know how to set parameters should be? IP address and port should be how to fill in? Click start always prompt the SOCKET connection is successful,

The following is a code

# 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 shields took the get into reset loop
*/
WIZ820ioInterface eth (D11, D12, D13, D10, D5);

Int main ()
{
Wait (3);

//Initialize the interface.
//If no param is passed to the init () then the DHCP will be 2 on the connect ()
Int=s eth. The init ();
If (s!=NULL) {
Printf (" & gt;> Could not initialise Halting! \n");
The exit (0);
}

Printf (" & gt;> Get the IP address... \n");
While (1) {
S=the eth. The connect ();//Connect to the network

If (s==false | | s & lt; 0 {
Printf (" & gt;> Could not connect to the network! Retrying... \n");
Wait (3);
} else {
break;
}
}
Printf (" & gt;> Got an IP address: % s \ n ", eth. GetIPAddress ());

//Prepare the HTTP request to mbed.org
Printf (" & gt;> Open a socket to mbed.org: 80 \ n ");
Char http_cmd []="the GET/media/uploads/mbed_official/hello. TXT HTTP/1.0 \ n \ n";
TCPSocketConnection sock.

While (the sock. Connect (" mbed.org ", 80)==1) {
Printf (" & gt;> Unable to open the socket! Retrying... \n");
};

Printf (" & gt;> Request % s \ n ", http_cmd);
The sock. Send_all (http_cmd, sizeof (http_cmd) - 1);

//Read the response
Char buffer [300].
int ret;
While (true) {
Ret=the sock. The receive (buffer, sizeof (buffer) - 1);
If (ret & lt;=0)
break;
Buffer (ret)='\ 0';
Printf (" & gt;> A Received % d chars from mbed.org: \ n \ n % s ", ret, buffer);
}

Printf (" & gt;> Close the socket \ n ");
The sock. The close ();

//Disconnect from the network
Printf (" & gt;> Disconnect from the network \ n ");
The eth. Disconnect ();

return 0;
}

Hello, your success? Can share for me

CodePudding user response:

refer to the original poster u010269902 response:
recently in learning STM32 and w5100 network communication,
Above the mbed found a routine, compiled after the don't know how to view? PC with friendly Ethernet debugging serial debugging assistant, don't know how to set parameters should be? IP address and port should be how to fill in? Click start always prompt the SOCKET connection is successful,

The following is a code

# 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 shields took the get into reset loop
*/
WIZ820ioInterface eth (D11, D12, D13, D10, D5);

Int main ()
{
Wait (3);

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related