Pages: [1]   Go Down
Author Topic: Ethernet shield hangs  (Read 1002 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have funny problem with ethernet shield. I am using version 21 software. Duemillanove and official ethernet shield with W5100.

My Arduino controls my remote station electric energy production and usage. And it sends data as statistics to pachube (www.pachube.com/feeds/7458) and from webserver it checks if there are configuration changes, and adjusts its RTC time with NTP.
It is designed to work without internet. If ethernet is disconnected it is no problem. But now problem comes. If there are problems with internet further away from local router, that causes no response from webserver or other services, connection making hangs for too long before shield returns "no connection". This again causes Watchdog to reset the whole system, which again causes loss of power in the whole system. So every time lights go out I know there is no internet again smiley
So, question is how to make timeout happen faster?

Of the working principle and saving power, ethernet shield is switched off if not used. Every time it is powered up, waited until it resets properly and then initialised for every usege. So there can not be multiple connection problem. And it hangs on connect();

Any hints?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've seen that there was a problem with too lenghty delay before recognizing connection fail. It was possible to make that time out shorter by modifying library only I can't find it anymore. Could anyone give some hints?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5872
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The timeout is controlled by the W5100 chip. I discovered you can change that timeout retry count and cut the timeout delay in half. You might want to play with that number. I have not tried a value less than 4.

This is in
/arduino-022/libraries/Ethernet/utility/w5100.cpp

I added a line in the init() function to shorten the timeout delay. The default retry count is 8. This sets that to 4.
Look for the "//Tim added" comment.

Code:
void W5100Class::init(void)
{
  delay(300);

  SPI.begin();
  initSS();
  
  writeMR(1<<RST);
  writeTMSR(0x55);
  writeRMSR(0x55);

// Tim added
  writeRCR(0x04);
  
  for (int i=0; i<MAX_SOCK_NUM; i++) {
    SBASE[i] = TXBUF_BASE + SSIZE * i;
    RBASE[i] = RXBUF_BASE + RSIZE * i;
  }
}

If you try a number smaller than 4, please let me know how it worked.
« Last Edit: September 11, 2011, 06:38:27 am by SurferTim » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanx! It seems it worked. I set the retry count to 1. In that system it is not reasonable to frantically try to connect at any cost. Nothing serious happen if connection fails.

I will monitor how it works and if there are something interesting to report, I'll let you know.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5872
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, peep rada!  smiley

I am about to need that in a few days, and it is good to know it works with 1. That is what I will need. One try, then back. I'll determine when it tries again.

Edit: I might be incorrect about the count. That register is a "retry" count. So setting that to '1' may try the connection twice. Maybe when I try the code in a few days, I will try setting that to '0'.  smiley-eek
« Last Edit: September 16, 2011, 07:29:05 am by SurferTim » Logged

Pages: [1]   Go Up
Jump to: