Timer Interrupt not called when making network connection with ethernet shield

Hi,

I have seen other posts with problems concerning the shield and timer service routines but the answers don't seem to provide me with a solution.

I have constructed an external watchdog using a 555 timer which I reset with a call to toggle a digital output pin which works fine. However, several of the functions I call take differing times to return and the watchdog resets the board occasionally. I can sprinkle calls to the reset routine throughout the functions and hope I've covered all eventualities but I thought an interrupt would be perfect until I discovered regular resets were still occurring which were associated with the use of the ethernet card.

Is this a well documented effect rendering timer interrupts useless or is there a fix I've not found.

I am assuming my coding of the comms routines is not efficient and maybe that is causing the problem and I attach the code here.

String PostData(String DataMessage, byte StepperID)
{
  // Making a TCP connection to remote host
  int x;
  int StartPosn;
  int EndPosn;
  String Temp;
  String Response;
  bool ConnectionFailed;
  static bool IsConnected = false;

  int mNow = hour() * 60 + minute();

  ConnectionFailed = false;

#if defined (LOUNGE)
  if (StepperID == 1) {
    client.connect(Loungeserver, 80);
    delay(150);
    if (client.connected()) {
      IsConnected = true;
#if defined (SERIALOUTPUT)
      Serial.println("Posting to Lounge");
      Serial.println(DataMessage);
#endif
      client.print(DataMessage);
      client.print(" HTTP/1.1");
      digitalWrite(LOUNGEB_LED, HIGH);
      delay(150);
      digitalWrite(LOUNGEB_LED, LOW);
    }
    else
    {
      digitalWrite(LOUNGEB_LED, DIM);
      PrintMins2Time2File(mNow, 0);
      Message2File(" - Lounge", 0);
      Message2File(CONNFAIL, 1);
      ConnectionFailed = true;
#if defined(DEBUG)
      Serial.print("Lounge");
      Serial.println(CONNFAIL);
#endif
    }
  }
#endif

#if defined (BED1)
  if (StepperID == 2) {
    client.connect(B1server, 80);
    delay(150);
    if (client.connected()) {
      IsConnected = true;
#if defined (SERIALOUTPUT)
      Serial.println("Posting to Bedroom 1");
      Serial.println(DataMessage);
#endif
      client.print(DataMessage);
      client.print(" HTTP/1.1");
      digitalWrite(BED1B_LED, HIGH);
      delay(150);
      digitalWrite(BED1B_LED, LOW);
    }
    else
    {
      analogWrite(BED1B_LED, DIM);
      PrintMins2Time2File(mNow, 0);
      Message2File(" - Bedroom1", 0);
      Message2File(CONNFAIL, 1);
      ConnectionFailed = true;
#if defined(DEBUG)
      Serial.print("Bedroom1");
      Serial.println(CONNFAIL);
#endif
    }
  }
#endif

#if defined (BED2)
  if (StepperID == 3) {
    if (client.connect(B2server, 80)) {
      IsConnected = true;
#if defined (SERIALOUTPUT)
      Serial.println("Posting to Bedroom 2");
      Serial.println(DataMessage);
#endif
      client.print(DataMessage);
      client.print(" HTTP/1.1");
      digitalWrite(BED2B_LED, HIGH);
      delay(150);
      digitalWrite(BED2B_LED, LOW);
    }
    else
    {
      digitalWrite(BED2B_LED, DIM);
      PrintMins2Time2File(mNow, 0);
      Message2File(" - Bedroom2", 0);
      Message2File(CONNFAIL, 1);
      ConnectionFailed = true;
#if defined(DEBUG)
      Serial.print("Bedroom2");
      Serial.println(CONNFAIL);
#endif
    }
  }
#endif

#if defined (BED3)
  if (StepperID == 4) {
    if (client.connect(B3server, 80)) {
      IsConnected = true;
#if defined (SERIALOUTPUT)
      Serial.println("Posting to Bedroom 3");
      Serial.println(DataMessage);
#endif
      client.print(DataMessage);
      client.print(" HTTP/1.1");
      digitalWrite(BED3B_LED, HIGH);
      delay(150);
      digitalWrite(BED3B_LED, LOW);
    }
    else
    {
      digitalWrite(BED3B_LED, DIM);
      PrintMins2Time2File(mNow, 0);
      Message2File(" - Bedroom3", 0);
      Message2File(CONNFAIL, 1);
      ConnectionFailed = true;
#if defined(DEBUG)
      Serial.print("Bedroom3");
      Serial.println(CONNFAIL);
#endif
    }
  }
#endif

  if (!ConnectionFailed) {
    // Check for a response from the server, and route it to the serial port.
    delay(20);
    Response = "";
    while (client.connected()) {
      while ( client.available()) {
        Response += char(client.read());
      }
      delay(2);
    }
  }
#if defined (SERIALOUTPUT)
  Serial.println(Response);
#endif
  if (IsConnected == true) {
    IsConnected = false;
    client.stop();
  }

  return Response;
}

Thanks for looking.

Is this a well documented effect rendering timer interrupts useless or is there a fix I've not found.

I don't think this is an either/or question. There is no problem with interrupts when using the ethernet shield.

I am assuming my coding of the comms routines is not efficient

They use Strings, so, no, they are not.

#if defined (LOUNGE)

I can't even guess what the heck LOUNGE is supposed to mean.

I can't imagine why all those (not shown) #defines are there. I get the impression that you are using compile-time processing when you should be using run-time processing.

Thanks for reply.

Being new to C programming I made the assumption of my inefficiency because I've seen some extremely terse coding that I can't understand but does a lot in a few lines and yes, the #if defined are there to remove coding during compile not required for hardware that is not yet implement or turned off.

There is no problem with interrupts when using the ethernet shield.

This doesn't seem to explain the lack of interrupts to reset the watchdog circuit during the calls to the PostData function. Elsewhere the interrupt is called on schedule and the watchdog is held off until the PostData function is called!

This doesn't seem to explain the lack of interrupts to reset the watchdog circuit during the calls to the PostData function.

We can't see the rest of your code, so you are on your own figuring things out.

I didn’t really want to post 56kB of code (much of which is probably badly written) when I seemed to have tracked the problem to the one routine where the timer interrupt stops running.

If I can tidy the code to be more presentable I will post again.

Thanks so far.

Well, I reduced the code to the essentials adding debug statements to identify entering and leaving suspect functions and ran it again. At first it looked as though the WD resets did all occurred in the ethernet function but then after numerous such resets occasional resets appeared elsewhere so I tried to reduce the interrupt time interval to see if that was a problem but the interval didn't change.

Now I'm looking at the setup of the timer registers etc 'cos I'm not convinced that I fully understand or follow the various examples and explanations I've read. In searching I came across the TimerOne and Timer3 libraries which looked simpler and behold it all worked.

Still don't understand what I was doing wrong or why the settings I used allowed the WD circuit to timeout occasionally, but at least I have timer libraries I can use.

Thanks for the patience.