Pages: [1]   Go Down
Author Topic: Using Ethernet with interrupts.  (Read 1123 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

PeterO
Logged

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

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...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

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:
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);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

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

So you are looking to add more? Let's say the variable set during the w5100 interrupt is called ethInt. You want this:
Code:
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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

Quote
The "no delay" is because I'm used to writing code properly ;-)
Excellent! Then you should have no problems at all.  smiley-grin

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.
« Last Edit: June 01, 2012, 09:36:34 am by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

 
« Last Edit: June 01, 2012, 10:04:46 am by PeterO » Logged

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

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.  smiley-wink

Maybe someone else can help you.
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: