W5500 TCP Server Port Hangup

#1

I created a TCP server using W5500 for Modbus TCP. Everything works well, but the W5500 port is freeze after exchanging several thousand transactions of BACnet packets with a client.

However, spi port of W5500 is still working because simulation on the micro-controller and scope are still getiing data back from W5500.

Ping request from the PC was time out and packet lost was 100%

From the spi port, S0_SR=0x14, and S0_IR=0x00.

W5500 did not take any S0_CR command.

I had to manually sent an spi MR_7=0 to RESET W5500

This happened frequently, so what cause the W5500 to be hung like that and what is a solution in this case.

#2

The first (and only thing) that comes to my mind is writing over the borders of the socket memory. To you reset/overflow the pointers when exceeding the assigned memory areas?

#3

… corrupting the chip configuration (e.g. SIP, mask, MAC address …)

#4

I manually verified all registers after W5500’s port being frozen, and I found that a SHAR0 had been changed. The rest of the registers are all the same.

Is there an app manual that tell you what to do at each Sn_SR?

I think I missed the action for each status or react wrongly, so would you please verify my code:

switch (Wiznet_Connection_Status)
{
case 0x00: // SOCK_CLOSED
WiznetClearInterruptStatus(Int_AllBit);// clear all int bit
WiznetSocketOpen();
WiznetSocketListen();
break;
case 0x13: // SOCK_INT
WiznetClearInterruptStatus(Int_AllBit);// clear all int bit
WiznetSocketListen();
break;
case 0x14: // Keep socket open
WiznetSocketSendKeep();
break;
case 0x17: // SOCK_ESTABLISHED
WiznetSocketSend(); // Command Wiznet to send
if (SocketInterruptStatus.SendComplete==1)
WiznetClearInterruptStatus(Int_SendComplete); // Clear SEND_OK interrupt bit
WiznetSocketSendKeep();
break;
case 0x1C: // SOCK_CLOSE_WAIT
WiznetClearInterruptStatus(Int_AllBit); // clear all int bit
WiznetSocketDisConnectCloseReOpenListen(); // Command socket to close and reopen
break;
case 0x22: // SOCK_UDP
break;
case 0x42: // SOCK_MACRAW
break;
/////////////// Temporary status
case 0x15
break;
case 0x16: // SOCK_SYNRECV
break;
case 0x18: // SOCK_FIN_WAIT
break;
case 0x1A: // SOCK_CLOSING
break;
case 0x1B: // SOCK_TIME_WAIT
break;
case 0x1D: // SOCK_LAST_ACK
break;
default:
WiznetClearInterruptStatus(Int_AllBit);// clear all int bit
break;
}

Thank you very much.

#5

I am using the WIZNET ioLibrary, which has all the socket API source code. I can see that APIs like connect(), disconnect(), send() all check the Sn_IR register for socket timeout. Are you doing the same thing in your code?

#6

No, I wrote my own libs.

#7

I used Wireshark to capture my TCP frame. When client sent a request, my server responded with a RST, ACK.

Anyone has any idea why my server stayed in this mode?

Server status and interrupt as: S0_SR=0x14, and S0_IR=0, and server still replied to a ping request from the pc.

#8

Do you use different source port numbers at client side? Not sure why client continues with retransmissions as it was clearly told RST. There’s something wrong with the packets. Attach Wireshark log instead of the picture.

#9

Eugeny, Philipp_K, and acpie360

Thanks for taking time to understand my issues and helped me.

The client is a third party software, and they used a different port for sure. My server used port 502 which dedicates for BACnet TCP/IP. Currently, I hard coded to send only one packet out, and I still have trouble with the W5500 on both RX/TX sides. I got about 48000 packets correct, and about 2000 incorrect packets. I know for sure that my Spi bus is very stable because it shares with an EEPROM, and there is no error on the EEPROM at all.

The W5500 is giving me lot of headache for the last couple weeks.

Many people mentions W5500io libs. I may start to look into them next week. Do you know if W5500io libs include source code for TCP server? Any pre-built libraries that you recommend?

I started this project from scratch by reading the specification version 1.0.6 and now is 1.0.8, but it does not clarify many TCP server apps.

Again, thank y’all very much.

#10

i once had an issue that was not entirely dissimilar to yours. In my case, it was that I did not overflow the pointers correctly. I think, you idea to use the ioLibraries might eventually help you.

Yes they do, IIRC.

#11

You may want to consider giving this W5500 library a try. I’m using it with great success. Even if it doesn’t completely meet your needs, you may gleen useful information from it.