TCP connection only possible with a 2-4 sec delay between init and socket programming

Hi all,

I am busy programming the wiz550io as a TCP client to communicate with a server. Unfortunately i ran into some problems connecting to the server. Every time it runs the ‘connect()’ function it returns a time out error. While debugging the code i learned that establishing a connection with the server succesfully was only possible if a 3 - 4 sec delay was inserted before any of the socket programming commands. without this delay it goes straight to the time-out.

In other topics i saw that it was due to the status of link of the PHY that the module wasn’t ready to set-up a connection yet. I tried implementing that by polling bit 0 of the PHYCFGR register, but without any luck…

I’ll post my code here:

retVal = init_spi();
if (STATUS_FAIL == retVal){
    while(1);
}

init_w5500();

init_network(&pnetinfo);

//    __delay_cycles(2000000);   <-- This is where i inserted the delay to make the connect() function work.

while(getPHYCFGR() & PHYCFGR_LNK_ON); // PHYCFGR_LNK_ON (1<<0)

mysock = socket(socketNum, Sn_MR_TCP, 5000, 0x00);
if(mysock != socketNum)
{
    while(1);
}


retVal = connect(mysock, addr, PORT_TCPC);
if(retVal < 0)
{
    while(1);
}

retVal = send(mysock, GREETING_MSG, strlen(GREETING_MSG));
if(retVal < 0)
{
    while(1);
}

retVal = close(mysock);
if(retVal < 0)
{
    while(1);
}

while(1);

As you can see it’s just a very simple code to open a socket, connect, send a message and lastly close the connection.

What i also checked for were the packets send over the network through wireshark. The first picture posted is the code without the delay, where the connect() returns time out. The second shows a succesfull connection.

For clarification, the BelkinIn is the USB-C to ethernet adapter i use to connect to the module. This device has been given the IP address where the Wiz550io module is looking for.

The ARP message does get send out, but doesn’t get any response back, so maybe it’s something else than the module? Or maybe the network of the wiz550io hasn’t fully initialized yet, so it’s impossible for the host to send back a response?

I hope someone can help me with this problem.

Cheers,

Caspar

I think you have to fix it such as below:
while(!(getPHYCFGR() & PHYCFGR_LNK_ON));

Hi Becky,

Yes you are right, that’s a mistake in my code. Thank you for noticing, i changed it in my code. Unfortunately this is not the solution to my problem. The module still fails to connect with the server without that 3-4 second delay. So i’m curious if there is another factor which plays a part in the initialization of the module.

Caspar

In the first packet, the W5500 sent an arp request. But belkin did not give an arp response. If the w5500 does not receive an arp response, it retransmits every 200ms. However, no retransmission is seen in the first packet.
I think there are two cases.
The first is that there was more arp transmission before, but it was not visible because it was sent before link up.
The second is that the phy link is unstable.

It is recommended to check the phy twice by modifying as follows to ensure the stability of phy
while (1) {
check1 = getPHYCFGR () & PHYCFGR_LNK_ON
check2 = getPHYCFGR () & PHYCFGR_LNK_ON
if (check == 0x01 && check2 == 0x01) break;
}

The suggestion of polling the phy link twice worked. Thank you