ESP8266 E12 multiple SPI devices

Hello everyone, I'm trying to make a small device with a TFT display and a SD card. The TFT I've choose is the ILI 9488 with touch (not in use now) and it's SD card slot.

The board I'm using is an ESP8266 E12 and I've connected the SPI devices as follow:

  • TFT_MISO D6 // DEFAULT
  • TFT_MOSI D7 // DEFAULT
  • TFT_SCLK D5 // DEFAULT
  • TFT_DC D3 // DEFAULT
  • TFT_RST D4 // DEFAULT
  • TFT_CS D8 // DEFAULT
  • SD_MISO D6
  • SD_MOSI D7
  • SD_SCLK D5
  • SD_CS D2

LED and VCC are under 3.3v (tried also under VIN)
The libraries I'm using are TFT_eSPI.h (from github), SPI.h and SD.h.

The problem is that i can write on the TFT but I cannot read from SD, what's wrong on what I'm doing? It's like the SD.begin(SD_CS) doesn't work at all.

Try removing the connection to the TFT_MISO pin. Some controllers don't properly tri-state that output when not selected, and that prevents the SD card from working.

2 Likes

Try manually switching the TFT_CS & SD_CS to HIGH after use . Most libraries don't actually disable the device they are controlling after operation. So switch TFT_CS HIGH before starting to use the SD card and switch the SD_CS HIGH after that and TFT_CS LOW again.

1 Like

Based on what you have told us, it should work.

To understand why it is not working, more information will be needed.

Post links to the detailed specs, including internal schematics, for:

  • The ESP8266 board
  • The TFT display
  • The SD card board

Also post the complete code you have been using and schematic showing how you connected all components and power supply.

Also explain what your project is about. Knowing that, we may be able to suggest alternative approaches.

First thing I'm gonna try is this one, I'll let you know. Thanks for now!

Ugh I did't considered actually to switch between the two CS, nice catch! I'm gonna try this!

@ilcoso96
Your TFT or SD module (or both) probably have an incorrect design that doesn't allow it to free the SPI bus.
It was discussed on the forum recently:

Loocking at It the labeling seems correct. I'll post later all the info.

@PaulRB so the ESP8266 E12 board has the following pinout:

The TFT display is an ILI9488 480x320 with embedded SD slot as in the picture. The pinout printed is consistent, no SDA SCL as @b707 mentioned. Unfortunetly I didn't have luck to find the actual schematic.

The project is actually pretty straight forward: I want to make a tiny digital frame with images loaded on the SD with a routine to download from internet via Wi-Fi.

I hope that all this info are enough.

Not enough to understand why your circuit is not working.

I found this page that seems to be the same display. It was one of the first hits when I googled for "ILI9488 480x320". Did you not find this?

http://www.lcdwiki.com/3.5inch_SPI_Module_ILI9488_SKU:MSP3520

Try connecting the power pins and the SD card pins to the NodeMCU, but leave all the display pins disconnected. Can you read from the SD card like that?

The schematic for the display is here:
http://www.lcdwiki.com/res/MSP3520/3.5寸SPI模块原理图.pdf

There do not appear to be any level shifters to allow it to be used with a 5V Arduino. These level shifters are often the source of problems when there is a need for two or more devices to be connected to the SPI bus.

Time to post your code. Use code tags.

We will check if the code handles the two SPI devices correctly.

In some way not of course. We need the code with which you have attempted to get it working but failed.
Also please include the core version you are using. For the SD card on the ESP8266 it is rather relevant since the SD library is core specific.

The main question before was: Does the SD card work without the TFT connected ?

Yeah, sorry, forgot to mention that: the SD works fine without the display connected. The code is pretty basic:

#include <SPI.h>
#include <SD.h>
#include "TFT_eSPI.h"

#define SD_CS D2
#define BAUDRATE 115200

void setup(){
  Serial.begin(BAUDRATE);
  Serial.println("Serial opened...");

  InitTFT();
  TftPrintln("HELLO WORLD!");

  InitSD();
}

void loop(){
  delay(1);
}

void InitTFT(){
  tft.begin();
  tft.setRotation(1); //LANDSCAPE
  tft.setTextSize(3);
}

void TftPrintln(String text){
  tft.println(text);
}

void InitSD(){
  if(SD.begin(SD_CS)){
      Serial.println("SD INITIALIZED!");
  }
  else{
      Serial.println("CANNOT INITIALIZE SD!");
  }
}

That's the first code I wrote. I didn't tried the suggestion from @van_der_decken and @Deva_Rishi yet.

For the schematics, nope, I didn't actually saw them... maybe I've had overlooked them...

Anyway everything I'm using is pretty standard, I didn't use anything special, out of the box experience if you want...

To mention also that: I've tried to use the SD0, SD1, SDCMD and SDCLK thinking that maybe two devices, two SPI busses. Well, nope...

Ok, I've tried both setting LOW the TFT_CS and SD_CS and disconnecting the TFT_MISO and those are the results:

  • TFT_CS and SD_CS state switch: not working, the TFT display has the priority over SD
  • TFT_MISO disconnected: sort of working. At the first start it must be connected to the TFT or it do not inizialize correctly the display (flipped text, no background and so on). After the first boot I can disconnect it

Something is going on here, not quite sure what tho...

What I thought was strange is that your code does not specify which pins are TFT_CS, TFT_RES or TFT_DC.

Those are defined in User_Settings.h of the library TFT_eSPI.h

Yeah, I just realised that. Please post your version.

Wait, it's this file?

@bodmer can you assist in this topic please? What could be preventing the SD card from working correctly?