Ethernet optimisation

Hello,

I just have to write this down because after a day spent trying to improve ethernet performance I found out quite some things about libraries.

I am not very technical, I am more like an explorer though, so maybe some little unprecision is possible. As usual I will write what worked for me.

The ethernet expansion is connected to the SPI bus and it uses pin 4 as SS select.

It works out of the box, ie. the Industruino version is already setup to operate with this extension.

Some of the features are not set and I had to explore to find out how to make them work.

One of the most important things is to set this parameter:

#define W5500_ETHERNET_SHIELD

which tells the library that our ethernet chip is indeed a w5500.

This will tell the library to get its routines from utility/w5500.h

The the instance of the class W5500 is called W5100 so you don't have to bother:

// W5500 controller instance
W5500Class W5100;

The optimization functions of the W5100 class are:

  W5100.setRetransmissionTime(iuint16_t timeout);    
  W5100.setRetransmissionCount(uint8_t count);    

These are used to reduce the timeout of the ethernet.begin() function when using DHCP.

  client.setTimeout(500);

This sets the timeout of the client.connect() call.

In order to have these functions working, I had to do the following:

- define the following before the library declaration:

#define W5500_ETHERNET_SHIELD
#define REL_GR_KURUMI
#define SS 4

 The REL_GR_KURUMI constant tells the library to use SS as select. I had to define explicitly SS as 4 because in some instances I got different values, ie. 17

Actually the W5500 library has a __AVR_AT90USB1286__ constant, but I think this is related to a different hardware setup and it doesn't work.

After all this, with the functions still not working, I had to init the chip by using W5100.init(); which does the following:

void W5500Class::init(void)
{

    initSS();
    delay(300);
    SPI.begin();

    for (int i=0; i<MAX_SOCK_NUM; i++) {
        uint8_t cntl_byte = (0x0C + (i<<5));
        write( 0x1E, cntl_byte, 2); //0x1E - Sn_RXBUF_SIZE
        write( 0x1F, cntl_byte, 2); //0x1F - Sn_TXBUF_SIZE
    }
}

Sounds greek to me, but after this the chip started operating normally with the optimization functions, so maybe some of the previous steps might be redundant. I haven't tried every combination thereof.

So the final setup for my network is as follows:

typedef uint8_t SOCKET;
#include <SPI.h>

#define W5500_ETHERNET_SHIELD
#define REL_GR_KURUMI
#define SS 4

#include <EthernetIndustruino.h>
#include <EthernetUdp.h>
//#include <utility/w5100.h>


// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x00 };  
// Edit buffer for IPAddress
IPAddress editBuf;

EthernetClient client;
EthernetServer server(80);

The setup routine:

  W5100.init();
      
  //set timeout for network connect
  W5100.setRetransmissionTime(0x07D0);    //200ms 
  W5100.setRetransmissionCount(5);        //5 tries

  Ethernet.begin(mac);

  //set timeout for server connection
 client.setTimeout(500);

Hope this is useful, as I spent quite some time to figure it out!

 

Stefano Giuseppe Bonvini
Stefano Giuseppe Bonvini
107
| 4 1 3
Asked on 3/13/17, 6:27 PM
0
vote
3745 Views

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

32 follower(s)

Stats

Asked: 3/13/17, 6:27 PM
Seen: 3745 times
Last updated: 3/13/17, 6:27 PM