d-a-v / W5500lwIP

W5100, W5500 and ENC28J60 for esp8266 and lwIP (or any other uC using lwIP)
43 stars 11 forks source link

W5100 don't work #15

Closed nopnop2002 closed 4 years ago

nopnop2002 commented 4 years ago

Hello. W5500 and ENC28J60 work fine. It works very stably.

But W5100 don't work.

My board: WeMos D1 Mini

My code:

#include <SPI.h>
#include <ESP8266WiFi.h>
//#include <W5500lwIP.h> // https://github.com/d-a-v/W5500lwIP
#include <W5100lwIP.h> // https://github.com/d-a-v/W5500lwIP
//#include <ENC28J60lwIP.h> // https://github.com/d-a-v/W5500lwIP

#define CSPIN D2

//Wiznet5500lwIP eth(SPI, CSPIN);
Wiznet5100lwIP eth(SPI, CSPIN);
//ENC28J60lwIP eth(SPI, CSPIN);
byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};

void setup() {

  Serial.begin(115200);
  Serial.println();
  Serial.print(ESP.getFullVersion());
  Serial.println();

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setFrequency(4000000);

  eth.setDefault(); // use ethernet for default route
  int present = eth.begin(mac);
  if (!present) {
    Serial.println("no ethernet hardware present");
    while(1);
  }

  Serial.print("connecting ethernet");
  while (!eth.connected()) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println();
  Serial.print("ethernet ip address: ");
  Serial.println(eth.localIP());
  Serial.print("ethernet subnetMask: ");
  Serial.println(eth.subnetMask());
  Serial.print("ethernet gateway: ");
  Serial.println(eth.gatewayIP());
}

void loop() {

} 

Wireing:

W5100 PHY --- ESP8266
SCK --- D5
MISO --- D6
MOSI --- D7
CS --- D2
5V --- 5V
GND --- GND

W5100 phy only work 5V.

I added debug print to w5100.cpp:

boolean Wiznet5100::begin(const uint8_t *mac_address)
{
    memcpy(_mac_address, mac_address, 6);

    pinMode(_cs, OUTPUT);
    wizchip_cs_deselect();

#if 0
    _spi.begin();
    _spi.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz?
    _spi.setBitOrder(MSBFIRST);
    _spi.setDataMode(SPI_MODE0);
#endif

    wizchip_sw_reset();

    // Set the size of the Rx and Tx buffers
    wizchip_write(RMSR, RxBufferSize);
    wizchip_write(TMSR, TxBufferSize);

    // Set our local MAC address
    setSHAR(_mac_address);

    // Open Socket 0 in MACRaw mode
    setSn_MR(Sn_MR_MACRAW);
    setSn_CR(Sn_CR_OPEN);
Serial.print("getSn_SR()=");
Serial.println(getSn_SR(),HEX);
    if (getSn_SR() != SOCK_MACRAW) {
        // Failed to put socket 0 into MACRaw mode
        return false;
    }

    // Success
    return true;
}

Serial.print:

SDK:2.2.2-dev(38a443e)/Core:2.7.1=20701000/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-30-g92add50/BearSSL:5c771be
getSn_SR()=0
no ethernet hardware present

Do you have any help.

Thanks for the helpful code.

nopnop2002 commented 4 years ago

I flashed this repo to Arduino UNO. https://github.com/njh/W5100MacRaw It work fine.

[W5100MacRaw]
_cs=10
getSn_SR()=42
Len=301
Dest=ff:ff:ff:ff:ff:ff
Src=02:42:0e:95:0f:93
Type=0x0800

I changed the code a little and flashed this repo to ESP8266.

//SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz?
SPI.setFrequency(4000000); // 4MHz

GPIO15 is used for Chip Select in this repo.

The result:

[W5100MacRaw]
_cs=15
getSn_SR()=0

I don't know why it don't work.

nopnop2002 commented 4 years ago

The W5100 module is a 5V dedicated module.

On the other hand, the GPIO of ESP8266 is 3.3V.

Maybe MOSI needs a level shift from 3.3V to 5V.

I'll try.

nopnop2002 commented 4 years ago

I understood the cause.

I was wrong

I used the board name "Wemod D1 R1".

In this board name, D2 is GPIO16.

I compiled it using the board name "Lolin (WEMOS) D1 R2 & mini".

Everything works fine.

LevelShift is not required.