sstaub / Ethernet3

Ethernet library for Arduino and Ethernetshield2 / WIZ550io / WIZ850io / USR-ES1 with Wiznet W5500 chip
Other
76 stars 34 forks source link

DHCP fails #29

Closed Jim-bee closed 3 years ago

Jim-bee commented 4 years ago

Hi,

I have been using a Metro M4 board with the Adafruit Ethernet2 library, Adafruit Ethernet W5500 Feather-wing DHCP my code always works fine and RX's data fine. Your library has some great new functions I like so I tried using your Ethernet3 library and DHCP fails to configure the board every time but it will (after a very long delay) assign static IP. However with the static IP assigned it will not accept any data seems to hangup. I believe the issue to be something with the Ethernet.init(). Not sure if I am missing something? Below is the order and code setup.

include

//#include

include

define WIZ_CS 12

byte mac[] = { 0x98, 0x76, 0xB6, 0x10, 0x9F, 0xAE }; // Set the static IP address to use if the DHCP fails to assign IP Address IPAddress ip(10, 0, 0, 14); IPAddress gateway(10, 0, 0, 1); IPAddress subnet(255, 255, 255, 0); EthernetServer server(9100); EthernetClient client;

void setup() { Ethernet.setCsPin(WIZ_CS); // used only with Ethernet3 lib //Ethernet.init(WIZ_CS); // used only with Ethernet2 lib. this init works. Ethernet.init(); // used only with Ethernet3 lib tried 1, 2, 4, 8 none work Serial.begin(115200); delay(3000);

if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); Ethernet.begin(mac, ip); } Serial.println(Ethernet.localIP()); }

One question: To change the buffer size for example: Ethernet.init(1) do I need to edit only the w5500.h and change both MAX_SOCKET = 1 and buffer size RX/TX = 16k? Do I need to edit any other files.

sstaub commented 4 years ago

I don`t know what this problem cause. Maybe there are some optimization in Ethernet 2 for M4 chips which are not included in my library. init() with an argument reorder the the stack size for a limited number of sockets, not the maximum of sockets, this must manualy done with MAX_SOCKET. But be aware that some communication like TCP normaly needs more than one socket, please refer to the manual of the W5500.

Jim-bee commented 4 years ago

Hi Stefan,

Issue #29 sorry for not getting back to you sooner. Using your Ethernet3 lib I was able to make the DHCP work reliably with SAMD51X (M4) by adding in a software reset. Here is the lines of code (in red) and location I added them into your W5500.cpp file.

27 void W5500Class::init(uint8_t socketNumbers, uint8_t ss_pin) 28 { 29 SPI_CS = ss_pin; 30 31 delay(1000); 32 initSS(); 33 SPI.begin(); 34 w5500.swReset(); // Jimbee added 2019 to fix DHCP with SAMD51X

224 // Soft reset the Wiznet chip, by writing to its MR register reset bit 225 // Jimbee Added 2019 Added to fix DHCP with SAMD51X 226 uint8_t W5500Class::softReset(void) 227 { 228 uint16_t count=0; 229 // write to reset bit 230 writeMR(0x80); 231 // then wait for soft reset to complete 232 do { 233 uint8_t mr = readMR(); 234 if (mr == 0) return 1; 235 delay(1); 236 } while (++count < 20); 237 return 0; 238 }

Best Regards, Jim

On Apr 23, 2020, at 12:55 AM, Stefan Staub notifications@github.com wrote:

Closed #29 https://github.com/sstaub/Ethernet3/issues/29.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sstaub/Ethernet3/issues/29#event-3263650656, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKVJBA6ADOIJNMGFRUE54JLRN7Q67ANCNFSM4JOLA6VA.

ZsZs73 commented 3 years ago

Jim, while you are using Ethernet3 library you can use the softreset function. BTW I had to use the hardreset as well to make the chip stable. Quote from data sheet of W5500: 'RESET should be held low at least 500 us for W5500 reset.' I sacrificed one pin of the MCU to do this.