Go Down

Topic: Using Ethernet with interrupts. (Read 1 time) previous topic - next topic

PeterO

Is anyone writing code that used the interrupt facility provided on the Ethernet shield ?

PeterO

SurferTim

I briefly considered it, then dropped the idea when I decided to use the microSD card in conjuction with the w5100. They are both SPI devices. If your sketch was accessing the SD card, and the w5100 interrupt happened, there would be a SPI bus collision unless your ethernet code tracks all other SPI devices. Otherwise, you would need to disable interrupts before any SPI device library call, and enable them again on exit.

Just a thought...

PeterO

I hadn't thought about the possible interaction with other SPI devices, but in the first instance all I was going to try to get the interrupt to is just set a flag to say that the w5100 needed some attention and then use the normal "polling" (non interrupt) interface to actually access the data.  That wouldn't conflict with the sd card i/f.  The advantage would be less time spent polling the w5100.

PeterO

SurferTim

I kinda see what you are after. If you are looking for something to check if the w5100 needs service, then it already has that capability.
Code: [Select]
void loop() {
  // do the GET send here

  // this checks if the device is still connected
  while(client.connected()) {
    // this checks if the device has sent anything
    while(client.available()) {
       // if it has, then you get stuff from the w5100
      char c = client.read();
    }
  }
  // when the device disconnects, close your end
  client.stop();
  // delay 10 seconds
  delay(10000);
}


PeterO


I kinda see what you are after. If you are looking for something to check if the w5100 needs service, then it already has that capability.

Yes, and that's the sort of code I'll use when the interrupt pending flag has been set.
PeterO


SurferTim

So you are looking to add more? Let's say the variable set during the w5100 interrupt is called ethInt. You want this:
Code: [Select]
void loop() {
  // do the connect and GET send here

  // this now checks if anything has changed
  if(ethInt) {
    // this still checks if the device is still connected
    while(client.connected()) {
      // this still checks if the device has sent anything
      while(client.available()) {
         // if it has, then you get stuff from the w5100
        char c = client.read();
      }
    }
    // when the device disconnects, close your end
    client.stop();
    // clear ethInt
    ethInt = 0;
  }
  // delay 10 seconds
  delay(10000);
}

Where do you see that adding anything to the performance?

PeterO

Yes the test of ethInt is what I have in mind, but more care may be needed when resetting the flag as another interrupt may have occurred as a consequence of accessing the W5100, that needs checking. The performance improvement comes from not calling client.connected and client.available each time round the loop.  By the way my loop won't have any calls to dealy() in it.
PeterO

SurferTim


Yes the test of ethInt is what I have in mind, but more care may be needed when resetting the flag as another interrupt may have occurred as a consequence of accessing the W5100, that needs checking. The performance improvement comes from not calling client.connected and client.available each time round the loop.  By the way my loop won't have any calls to dealy() in it.
PeterO


OK on the no delay if it is your server. I prefer a persistent connection if you are connecting and disconnecting that fast.

Insure you prevent a "logjam" by disabling logging on that page, or set it to log "every 10th". You will be surprised how quickly that can fill up a not-very-large hard drive if you picked a default partition.

PeterO


OK on the no delay if it is your server. I prefer a persistent connection if you are connecting and disconnecting that fast.

The "no delay" is because I'm used to writing code properly ;-)
Quote

Insure you prevent a "logjam" by disabling logging on that page, or set it to log "every 10th". You will be surprised how quickly that can fill up a not-very-large hard drive if you picked a default partition.

The "other end" will not be a web server but will be an application running on a local PC that provided the GUI to control the code running on the arduino.
PeterO

SurferTim

#9
Jun 01, 2012, 04:15 pm Last Edit: Jun 01, 2012, 04:36 pm by SurferTim Reason: 1
Quote
The "no delay" is because I'm used to writing code properly ;-)

Excellent! Then you should have no problems at all.  :D

edit: I want you to know what you are up against. With a persistent connection (like telnet happening really fast), I can send a packet, and the server responds with a packet, 30 times per second for hours and hours. Let me know if you get even close to that with the "connect-disconnect" method.

PeterO

#10
Jun 01, 2012, 04:56 pm Last Edit: Jun 01, 2012, 05:04 pm by PeterO Reason: 1

Let me know if you get even close to that with the "connect-disconnect" method.

I'm confused by your repeated assumption that I'm using what you refer to as a  "connect-disconnect" method.

I'll be opening a TCP connection and using it to send system status updates to be displayed on the GUI, and getting GUI event messages (from button presses etc) back.

PeterO


EDIT: AH HA, I see in the code you posted there is a while loop that executes until the connection closes then it calls client.stop()   That's not how I'll be doing it !

PeterO


SurferTim

Quote
I'm confused by your repeated assumption that I'm using what you refer to as a  "connect-disconnect" method.

I'm also confused by your assumption that I am looking over your shoulder. My apology! My crystal ball is in the shop for repairs.  ;)

Maybe someone else can help you.

cwrose

Be aware that while the Ethernet _Shield_ brings out the W5100 line to a pad,
the Arduino Ethernet _board_ doesn't, and since the chip is SMT there seems
no way of getting at the pin.

Will

PeterO


Be aware that while the Ethernet _Shield_ brings out the W5100 line to a pad,

And be aware that it's an unlabelled pad on the underside of the board which fooled me for a while !
PeterO

Go Up