W5500 - Example code of using the INTn interrupt

We work with the INT interrupt. It works fine, as long as you make sure you keep polling for changes as long as the INT pin is high.

This is because the INT pin seem to be a level interrupt (remains high as long as the condition is high) rather than the edge interrupt (high when something happens, and then reset in the interrupt handler).

So the interrupt routine looks like this (schematic only, I use Microchip Dspic)

volatile unsigned int socketinterrupt = 0;

int _w5500pininterrupt()
{
socketinterrupt++; // run service routine
pininterrupt=0; // clear end of interrupt
}

and the main loop checks the service routine:

int main()
{int rcvsiz;
// lots of initialization

while (1) do
{
if (socketinterrupt)
{ socketinterrupt–; // declare interrupt as “handled”.
res=check_for_read_data(&rcvsiz); // writes SN_IR_RECV to SN_IR and reads Sn_RX_RSR0 twice till first read=second read.

     // !!!!!!!!!!!!!!! handle w5500 level instead of edge interrupt.
     if (W5500INTActive() && (socketinterrupt==0) )   // If INT  high, and no interrupts pending, retrigger.
      { socketinterrupt++;}
     if (res)
       {
           res=udpgetpayload (&rxsiz);  // get and process one payload. returns true if there are more unprocessed bytes in the RX buffer.
          if (res)
              {socketinterrupt++;}
       }

  } // if socketinterrupt
if (something else)
  {
  }

} // while
}// main