greiman / SdFat

Arduino FAT16/FAT32 exFAT Library
MIT License
1.07k stars 503 forks source link

Unable to share the same SPI bus with TFT_eSPI on ESP32 #477

Open JerryZRF opened 5 months ago

JerryZRF commented 5 months ago

Hi, I am using a LCD screen which shares its SPI bus with a SD reader on ESP32.

// User_Setup.h in TFT_eSPI
#define ST7796_DRIVER

#define SPI_FREQUENCY  40000000

#define TFT_MISO  25
#define TFT_MOSI  27
#define TFT_SCLK  26
#define TFT_CS    13  // Chip select control pin
#define TFT_DC    14  // Data Command control pin
#define TFT_RST   12  // Reset pin (could connect to RST pin)
//SdFatConfig.h in SdFat
#define SDFAT_FILE_TYPE 3
#define ENABLE_DEDICATED_SPI 0
#define SPI_DRIVER_SELECT 2
// My code
const uint8_t SD_CS = 33;
SoftSpiDriver<TFT_MISO, TFT_MOSI, TFT_SCLK> softSpi;
#define SD_CONFIG SdSpiConfig(SD_CS, SHARED_SPI, SD_SCK_MHZ(40), &softSpi)

When I try to init the SdFat and then the TFT_eSPI, the SdFat doesn't work.

sd.begin(SD_CONFIG); // It succeeds.

tft.begin();
tft.setRotation(1);
tft.fillScreen(TFT_BLUE);

uint32_t size = sd.card()->sectorCount();  // It returns 0.

And when I try to init the TFT_eSPI and then the SdFat, the TFT_eSPI doesn't work.

tft.begin();
tft.setRotation(1);
tft.fillScreen(TFT_BLUE);

sd.begin(SD_CONFIG) // It succeeds.

uint32_t size = sd.card()->sectorCount();  // It returns the right value.
tft.println("Succeed");  // Nothing happends
Serial.println("Succeed");  // It succeeds.
greiman commented 5 months ago

Are you pulling chip select high on the second device to to be initialized so it won't interfere with initializing of the first device?

sud-sharma commented 1 month ago

I am also facing the same issue. Did you find a solution ?

Andy2No commented 1 month ago

Not all SD breakouts are the same. The ones that use a logic level shifter to work with 5V Arduinos tend not to work well with 3.3V MCUs. SD SPI is 3.3V so the sort of breakout you need should just have some resistors and capacitors on it, no voltage regulator or level shifter.

archearth commented 1 week ago

I am in the same situation. I was able to get the SD to mount and list the files inside but only in the setup() function. After that, it does not list the files if the function is called inside loop() and also, when I tried to load a function that displays an image on the TFT screen it does not work. I am trying to use SdFs and the TFT_eSPI library and read/display images from the SD card. If anyone has found a solution or has one, it will be much appreciated.