W5100 on STM8S105C6 (STM8S-Discovery)
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Share projects and connect with makers.
Joined before the site update? first.
New to WIZnet Makers?
We sent a verification link to your address. Open it to activate your account, then log in.
Accounts from this email provider are reviewed by an administrator after verification. Approval usually takes one business day.
Already have an account?
Enter your email address. If it belongs to an account, we'll send a link to set a new password. Members who joined before the site update use this to set their password.
If an account uses that address, we sent a link to set a new password. The link works once and expires in 30 minutes.
Know your password?
Need an account?
RE: W5100 on STM8S105C6 (STM8S-Discovery)
by Edward ·
Hello
How to Environment Configuration Configuration ?
Look your code,
your mixed TCP Server and TCP Client code.
basically be devided TCP Server/Client.
So, Code is…
one socket creation.
remove connect function → connect function is client
remove sendto function → it is UDP…
you need know TCP/IP communication.
Thank you
RE: W5100 on STM8S105C6 (STM8S-Discovery)
by Deusex25 ·
Thanks for the reply.
However, as far as I remember W5100 can have up to four independent sockets, working simultaneously.
In my case:
Socket 0 - UDP - 3000;
Socket 1 - TCP Client - 4000;
Socket 2 - TCP Server - 80.
I used to completely remove code for UDP and TCP Client, but the problem with TCP Server remains the same: In TCP Server mode I can not connect to microcontroller more than once. If I close the first (succesfull) connection to TCP Server, it refuses all further connections to this socket until MCU reset!
RE: W5100 on STM8S105C6 (STM8S-Discovery)
by Coccoliso ·
Hi,
nobody forbids you to do what you say, but needs some order.
Transmission is not blocking but the reception yes so you after setting sockets you must put yourself in listening on the socket watching their status.
For each open socket waiting a TCP must use this logic (in macro language):
if you need to send on socket in “client mode” (so not listening ) need to do it before or after the main select.
Or use interrupts but you have to keep in mind that in any case you have to read what is the socket that has generated the interrupt and then read the reason ie the state so if you do not have to do anything else ( very dispersive ) you can wait in a loop.
Keep in mind that even the TCP endpoint takes part to delays … tx socket pendant and its port are unusable for the duration of the timeout then it would be the case that you change transmission port before using it again if the connection is broken by one of the parties.
For the moment I think I’ve solved the blocking problem and clarified some issues… if you need anything else let me know.
RE: W5100 on STM8S105C6 (STM8S-Discovery)
by Eugeny ·
I think Michele nailed it - you probably do not set W5100 back into listening mode after connection closes.
RE: W5100 on STM8S105C6 (STM8S-Discovery)
by tuanken92 ·
Could you show me the code example or the guide to use multiple socket? I don’t know how to do it
I want to use
socket 0: DNS → read IPWAN
socket 1: Client → send IPWAN to server
socket 2: Server → control device via ethernet?
Thanks for help!
RE: W5100 on STM8S105C6 (STM8S-Discovery)
by Coccoliso ·
Hi,
DNS/DHCP examples (Multicast also) are here [url]http://www.wiznet.co.kr/wp-content/uploads/wiznethome/Chip/W5100/Application%20Note/W5100_Application_Note.zip[/url]
All function needed for client/server application are here [url]http://www.wiznet.co.kr/wp-content/uploads/wiznethome/Chip/W5100/Software/W5100_Driver_V180(0).zip[/url]
Your application by steps may be :
Sockets are bidirectional!
The only difference is for TCP mode is “stay in listen for a connection” in server mode or “I start a new comunication by a connection” in client mode so :
In TCP server mode:
a) open one or more socket
b) listen as mention for a connection state “by macro” here [url]W5100 on STM8S105C6 (STM8S-Discovery)]
c) send some data in response (until it is connected)
d) wait for a connection close state or close the connection yourself when you’re done
In TCP client mode:
a) make a connection to remote server
b) wait for connection state OPEN for that socket
c) send some packets
d) read incoming data (until it is connected)
e) wait for a connection close state or close the connection yourself when you’re done
In UDP mode the connection does not exist so :
in UDP server mode:
a) open one or more socket
b) listen for incoming data
c) send a response … nothing else
in UDP client mode:
a) send bytes to remote
b) read incoming data … nothing else
As you can well understand with UDP you do not know when you have finished transmitting then you have to make do some sort of protocol in your data flow (by CR/LF , EOF pad chars or fixed length)
Each step must verify any timeouts if you expect an answer (for TCP should check the connection status before).
All functions to do these steps are into “W5100_Driver_V180” library and open UDP socket in client mode it can be found in DHCP/DNS examples because communications with DHCP server is UDP.
Your MPU is an STM8 also?
For Arduino libraries are already made and you can find examples too ([url]https://github.com/Wiznet/WIZ_Ethernet_Library[/url]) also for W5500.
RE: W5100 on STM8S105C6 (STM8S-Discovery)
by tuanken92 ·
[quote=“Coccoliso”][/quote]
I’ll try to complete follow your guide
Thank you so much! Have a nice day !
RE: W5100 on STM8S105C6 (STM8S-Discovery)
by tuanken92 ·
Hi Coccoliso, I have a trouble while using multi packet.
I just transceiver data in socket 0,1. Socket 2,3 can’t receiver data, although Terminal debug it receiver the length of data buffer.
RE: W5100 on STM8S105C6 (STM8S-Discovery)
by Coccoliso ·
Hi,
…
tries to explain better.
Sockets are all managed in the same way so I think the problem is in the logic you are trying to use especially if you’re trying to do a loopback.
You should tell me with “macros” what are you trying to do
RE: W5100 on STM8S105C6 (STM8S-Discovery)
by tuanken92 ·
Hi Coccoliso, thanks for reply!
Like the picture i posted:
when i try to use 4 sockets simultaneously
With socket 0-1: send and receiver data ok.
With socket 2-3: send ok but can’t receiver data.
My project use W5100 ioLibrary (Driver) [url]http://www.wiznet.co.kr/wp-content/uploads/wiznethome/Chip/W5100/Software/W5100_Driver_V180(0).zip[/url] and programing by CodevisionAVR
After setting register of MCU, socket, w5100…
*In main loop:
while(1) { for(i=0;i<4;i++) { loopback_tcps(i, gDATABUF, 80) ; } } // end of Main loop*The code of tcps loopback:
[code]int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port)
{
int32_t ret; char *p;
uint16_t size = 0, sentsize=0;
uint8_t destip[4];
uint16_t destport;
switch(getSn_SR(sn))
{
case SOCK_ESTABLISHED :
if(getSn_IR(sn) & Sn_IR_CON)
{
getSn_DIPR(sn, destip);
destport = getSn_DPORT(sn);
printf(“%d:Connected %d.%d.%d.%d : %d\r\n”,sn, destip[0], destip[1], destip[2], destip[3], destport);
setSn_IR(sn,Sn_IR_CON);
}
}
return 1;
}[/code]
*Source code: