issue in Ethernet lib for w5500 (RTR, RCR)

Hi

I an pretty sure I found an issue (while investigating something else) in the Ethernet library.

In utility/w5100.h, the RTR and RCR registers are right for w5100 and w5200 but not for w5500:

__GP_REGISTER16(RTR,    0x0017);    // Timeout address
__GP_REGISTER8 (RCR,    0x0019);    // Retry count

These two registers are used when calling Ethernet.setRetransmissionTimeout() and Ethernet.setRetransmissionCount() - which means the fonctions will not work when using w5500.

For w5500 it should be:

__GP_REGISTER16(RTR,    0x0017);    // Timeout address for w5100 and w5200
__GP_REGISTER8 (RCR,    0x0019);    // Retry count for w5100 and w5200
__GP_REGISTER16(RTR_W5500,0x0019);    // Timeout address for w5500
__GP_REGISTER8 (RCR_W5500,0x001B);    // Retry count for w5500

as shown in the datasheet (page 29 - http://wizwiki.net/wiki/doku.php?id=products:w5500:datasheet)

Then the setRetransmissionTime() and setRetransmissionCount() in the W5100Class must be adapted to use the right registers:

inline void setRetransmissionTime(uint16_t timeout) { if (chip==55) writeRTR_W5500(timeout); else writeRTR(timeout); }
inline void setRetransmissionCount(uint8_t retry) { if (chip==55) writeRCR_W5500(retry); else writeRCR(retry); }

I would appreciate if someone with more experience than me could confirm and if it is confirmed I guess this should be reported somewhere? :slight_smile:

And while I am there, another minor issue in the same file - all the way at the bottom:

#define htons(x) ( (((x)<<8)&0xFF00) | (((x)>>8)&0xFF) )

This generates a warning when compiling (from usage of the macro in Dns.cpp:164), replacing with this one removes the warning:

#define htons(x) ( (((x)&0xFF)<<8) | (((x)>>8)&0xFF) )

Also mentioned here