Simple webserver - problem with loopback and interrupts

I’m trying to setup a simple webservice server on your wiz550io board and faced some strange behavior. Please explain what a I doing wrong and how to fix it. Heres what I do:

first I reset w5500 and wait for its RDY signal:

gpio_set_pin_high(LAN_RST); delay_ms(500); gpio_set_pin_low(LAN_RST); delay_ms(500); gpio_set_pin_high(LAN_RST); while ( gpio_pin_is_low( LAN_RDY ) ); // follow below

then I initiate w5500 with default buffers size:

reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect); reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write); wizchip_init( null,null ); // follow below

next I initiate interrupt:

cpu_irq_disable(); ext_int_set_interrupt_callback( LAN_INT, lan_int_callback ); ext_int_init( LAN_INT, IOPORT_SENSE_FALLING ); wizchip_setinterruptmask( IK_SOCK_3 ); ctlsocket( 3, CS_SET_INTMASK, SIK_ALL ); cpu_irq_enable(); // follow below

open socket, put it on listen and wait:

socket(3,Sn_MR_TCP,80,SF_TCP_NODELAY); listen(3); while(1); // follow below

my irq callback looks as follows:

static void lan_int_callback(void) { ctlsocket(3, CS_GET_INTERRUPT, &i ); switch( getSn_SR(3) ) { case SOCK_ESTABLISHED: if( getSn_IR(3) & Sn_IR_CON ) { WIZCHIP_WRITE( getSn_IR(3), Sn_IR_CON ); } if( getSn_IR(3) & Sn_IR_RECV ) { int8_t len = recv( 3, &buf, 20 ); send( 3, &buf, len ); disconnect(3); lan_int_callback(); // <- no SIK_DISCONNECTED } break; case SOCK_CLOSE_WAIT: disconnect(3); break; case SOCK_CLOSED: close(3); socket(3,Sn_MR_TCP,80,SF_TCP_NODELAY); case SOCK_INIT: listen(3); break; } ctlsocket(3, CS_CLR_INTERRUPT, &i ); }

Heres what the problems are:

  1. once I run it, and point my browser onto I recieve something ( not necessary whats expected i.e. /test.html ) after refersh I recieve something else and so on - basically it looks like the chip is sending back quite random portion of socket buffer ( sometimes it sends back expected /test.html but only from time to time )

  2. I never recieve interrupts other than SIK_CONNECTED and SIK_RECEIVED so I need to reinvoke irq callback manually after disconnecting client in line marked with // ← no SIK_DISCONNECTED

  3. after quick repeating tries to connect from client ( I keep F5 in my browser pushed for a couple of seconds ) the whole thing simply hangs and mu browser shows “the connection has been reset” forever

Thanks a lot in advance :slight_smile:


Below is my recommendation for your debugging.
-. Disable the interrupt and use polling because normally polling is easy to debug.
-. Use the wireshark( to capture the packet. This tool is required to see how packet is sent and received.
-. Check your board can receive / send the data correctly before you test the webserver function.

What kind of MCU do you use?
We already port our driver to some general MCU and if you use same one, I think you don’t need to develop it from the scratch. :smiley:


Hi JB,
thanks for your advice, I’ll try it today and inform back :slight_smile:
I’m using atmega ( atmega256rfr2 to be precise ) w/o arduino and objective cpp - just c as you do in your driver.