November 22, 2024, 06:17:21 PM

ESP-POE-ISO and TFT_eSPI

Started by Drjaymz, May 03, 2024, 01:08:15 PM

Previous topic - Next topic

Drjaymz

All, I'm hoping I haven't run into an issue that can't be overcome.
I have used the POE board a few times for remote sensing and not had any issues.

A current project requires an LCD display for feedback to the user.  The LCD I have requires SPI.  I didn't have the normal SPI pins I usually use for the LCD but I did configure it to use the following.  And you'll be glad to know that yes the LCD works.

When I then combine it with the ethernet it kills the ethernet.  As far as I can see they are NOT using the same SPI bus but I am not overly familiar with the ethernet setup.

I will look into SPI bus contention but ideally with chip select you should be able to do this.

If anyone has any information that would help save me time on where I shoudl look please help!  If not I'll update the post with whether or not this was possible.

LubOlimex

Which pins exactly are you using for the LCD?
Technical support and documentation manager at Olimex

Drjaymz

#2
I am back on this project.

The followinhg pins are in use:

    -DTFT_RST=4             
    -DTFT_CS=16             
    -DTFT_DC=2               
    -DTFT_MOSI=15
    -DTFT_SCLK=14   

To rule out a conflict of shared pins I can move them to another group of pins.  The LCD will obviously not work but we can see if the Ethernet stops also.

Changed to the following:

    -DTFT_RST=32             
    -DTFT_CS=33             
    -DTFT_DC=34               
    -DTFT_MOSI=35
    -DTFT_SCLK=36     

and still fails so not a share Pin issue.

Is anyone using a display AND ethernet?  I found a few posts on the subject all questions similar and with no replies.

I thought perhaps that SPI was shared between ethernet and the SPI I am using but I gather than SPI is not used for ethernet.


Drjaymz

Update, I have got it to work but I think its via another bug.

Remember that the Eth init doesn't seem to work unless you give it a 250ms pause at boot - its on your demo code?  If you initialise the TFT screen in that 250ms pause then it works and the ethernet appears to subsequently initialise without breaking the TFT.

The reason I call it a bug is that something is happening in that period which prevents the Eth being setup and we don't know what it is - and looking at it nothing should be comflicting.  If its some sort of contention then I'm nervous that it may not reliably work.

See below, if you move SetupTFT(); to after or less than 250ms before ETH.begin() and it will fail.  As-in you cannot ping the device and communication doesn't work.

The following works:

void setup()
{
  SetupTFT();
  delay(250);

  WiFi.onEvent(WiFiEvent);
  Serial.begin(115200);

  ETH.begin();
  delay(250);

  String mac = ETH.macAddress();
  mac.replace(":", "");

  uint64_t value = ESP.getEfuseMac();
  uint32_t highPart = (value >> 32) & 0xFFFFFFFF;

  sprintf(mac_address, "%d", highPart);
  debug.printf("info: Eth %s connecting ", mac_address);

  int timeout = 0;

  while (!ETH.localIP()[0] && timeout < 20)
  {
    delay(500);
    debug.print(".");
    timeout++;
  }

  debug.setStoreOffline(true);
  debug.begin(115200);

  debug.print("Connected ");
  tft.print("Connected: ");
  debug.println(ETH.localIP());
  tft.println(ETH.localIP());
  eth_connected = true;

  tft.println("Contacting NTP...");
  delay(500);
  configTime(0 * 3600, 0, "2.pool.ntp.org", "time.nist.gov");
  setenv("TZ", "GMT+0BST-1,M3.5.0/01:00:00,M10.5.0/02:00:00", 1);

  delay(250);
  tft.fillScreen(TFT_BLACK);
  delay(250);
 
  sensors.begin();
  setupOTA();
 
  tft.setTextSize(1);
  tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set the font color
  tft.drawString("See this its working", 160, 0, 4);
}

Using the following connections and build flags for platformio:

build_flags =
    -DUSER_SETUP_LOADED=1
    -DILI9341_DRIVER=1       ; Switch to ILI9341 if that's your display, or adjust as needed for your model
    -DTFT_WIDTH=240          ; Set width to 240 pixels
    -DTFT_HEIGHT=320         ; Set height to 320 pixels for ILI9341, adjust if different
    -DTFT_RST=4             
    -DTFT_CS=16             
    -DTFT_DC=2               
    -DTFT_MOSI=15
    -DTFT_SCLK=14         
    -DLOAD_GLCD=1            ; Load the GLCD font (essential for basic text)
    -DLOAD_FONT2=1           ; Load Font2
    -DLOAD_FONT4=1           ; Load Font4
    -DLOAD_FONT6=1           ; Load Font6
    -DLOAD_FONT7=1           ; Load Font7
    -DLOAD_FONT8=1           ; Load Font8
    -DSUPPORT_TRANSACTIONS=1 ; may facilitate sharing with other SPI thingies
    -DLOAD_GFXFF=1           ; Load the GFX Free Fonts
    -DSMOOTH_FONT=1          ; Enable smooth font


Now to really test my patience I need to get ANOTHER spi device working on the same SPI bus.

LubOlimex

I think the problem is in GPIO2, it is toggled automatically on power up it is important bootstrap pin related to whether the board would get programmed or just execute off the SPI flash. Delaying the things lets it clear off boot function.

Try using another pin instead of GPIO2. If that is not possible maybe there are ways to disable its bootstrap function for the release version.
Technical support and documentation manager at Olimex