I have written a driver for the Wiznet W5100 ethernet chip (currently sits on the WIZ812MJ breakout board). It is connected via SPI1.
Everything works fine - ping, tcp client mode, receiving and sending data - but, after a random time (from 1 minute up to 10 minutes) the connection is closed suddenly! I tried to debug all the steps that happen, but I can't find anything that helps. Has anybody ever experienced similar problems?
As the driver is written for my company, I can't put all the code here, but I try to paste the (to me) most important parts. Most of this is pseudo-code, but you can assume that SPI communication works and all the registers are set to the given values!
Flowchart:
W5100_Init - Pass SPI pin configuration and do W5100 initialization
Pass SPI configuration
Write reset-cmd to MR register
Write retry time-value to RTR register (0x07D0 = 2000ms)
Write retry count to RCR register (0x05)
Write socket memory information to TMSR/RMSR register (0x55)
W5100_NetworkInit - Write GW, MAC, SubnetMask and IP Addr
Write Gateway to GAR register
Write MAC to SHAR register
Write Subnet to SUBR register
Write IP to SIPR register
W5100_SocketInit - Map important socket registers to given socket and initialize the socket
/*This maps all important/required ports to the socketConfig struct*/
if(socketX == SOCKET0)
{
socketConfig.PORT0 = W5100_ADDR_S0_PORT0;
socketConfig.PORT1 = W5100_ADDR_S0_PORT1;
socketConfig.MR = W5100_ADDR_S0_MR;
socketConfig.CR = W5100_ADDR_S0_CR;
socketConfig.SR = W5100_ADDR_S0_SR;
//...
}
Write protocol type to MR register
write Port to PORT register
Write CMD_OPEN to CR register
Use client mode:
Write server IP to DIPR register
Write server Port to DPORT register
Now that we've got a tcp connection in client mode, start loop.
Check socket status from SR register
If there's any data on the line, call W5100_Socket_ReceiveData method
This works fine for some time (latest run: 10 minutes), but then suddenly the socket status returns 0x00 and the connection is closed. Is there still anything important that I may have forgotten? Why is the socket closed?
Thank you very much for providing any hints!
Eventually, I found the answer myself. The problem is not based on my code, but all about EMC: the Wiznet chip resets. But the reset itself isn't time related but always appeared when I stood up from my chair.. The reset pin is very sensitive, so standing toggled the reset pin;