Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TFT_Espi and SD lib not compatible #3601

Open
tonbor opened this issue Dec 30, 2024 · 14 comments
Open

TFT_Espi and SD lib not compatible #3601

tonbor opened this issue Dec 30, 2024 · 14 comments

Comments

@tonbor
Copy link

tonbor commented Dec 30, 2024

Example https://github.com/Bodmer/TFT_eSPI/tree/master/examples/Generic/ESP32_SDcard_jpeg with SD not working with Esp32 S3 because TFT uses HSPI and SD lib not. So the SPI bus brakes when using both TFT and SD. Solution Platform esp32:[email protected] : https://forum.arduino.cc/t/esp32-initialize-hspi-as-default-spi/1155093/11

#define HSPI_SCK 12
#define HSPI_MISO 13
#define HSPI_MOSI 11
#define SD_CS 10
hspi = new SPIClass(HSPI);
hspi->begin(HSPI_SCK, HSPI_MISO, HSPI_MOSI, SD_CS);

if(!SD.begin(SD_CS, *hspi)){
    Serial.println("Card Mount Failed");
    return;
}
 tft.begin();

Took me 2 days to find this out!!!!! Still with esp32:[email protected] and later not working 👎

@sjorsvr
Copy link

sjorsvr commented Jan 4, 2025

see #3464 : Replace #define SPI_PORT FSPI into #define SPI_PORT 2 in TFT_eSPI_ESP32_S3.h in the Processors folder
in the tft_espi library.
In windows you maybe also need to clear the folder c:\Users\username\AppData\Local\arduino\ : this clears the precompiled libraries
then it works : I have a project with tft_espi library and sd library

@tonbor
Copy link
Author

tonbor commented Jan 4, 2025

see #3464 : Replace #define SPI_PORT FSPI into #define SPI_PORT 2 in TFT_eSPI_ESP32_S3.h in the Processors folder in the tft_espi library. In windows you maybe also need to clear the folder c:\Users\username\AppData\Local\arduino\ : this clears the precompiled libraries then it works : I have a project with tft_espi library and sd library

in the user setup I have #define USE_HSPI_PORT so where must alter? Here ?
// ESP32 specific SPI port selection
#ifdef USE_HSPI_PORT
#ifdef CONFIG_IDF_TARGET_ESP32
#define SPI_PORT HSPI //HSPI is port 2 on ESP32
#else

this a will never reach

 #elif CONFIG_IDF_TARGET_ESP32S3
#define SPI_PORT FSPI

will I ?

My problem is not repeatedly boot with Guru Meditation Error: Core 0 panic'ed (Store access fault). Exception was unhandled.
My problem is the spi used by the sd card and the tft, using the tft the sd is halting

@sjorsvr
Copy link

sjorsvr commented Jan 4, 2025 via email

@sjorsvr
Copy link

sjorsvr commented Jan 4, 2025

and this was the only change to get tft_espi working again with esp32 2.0.15 and higher

@tonbor
Copy link
Author

tonbor commented Jan 4, 2025

and this was the only change to get tft_espi working again with esp32 2.0.15 and higher

I got TFT working with esp 32 3.0.6. But not TFT and SD together on the same SPI with only different CS pins

@sjorsvr
Copy link

sjorsvr commented Jan 4, 2025 via email

@sjorsvr
Copy link

sjorsvr commented Jan 4, 2025 via email

@tonbor
Copy link
Author

tonbor commented Jan 4, 2025

got tft working for weeks, that is not the problem

@tonbor
Copy link
Author

tonbor commented Jan 4, 2025

I use following pins :
D display S sd card
18 D cs
7 D dc
10 S cs
11 D sda and S mosi
12 D clk and S clk
13 S miso
in arduino I use board esp32s3 Dev Module

and
this is in my user setup in the tft_espi library
....
#define TFT_CS 18
#define TFT_MOSI 11
#define TFT_MISO 13
#define TFT_SCLK 12

#define TFT_DC 7
//#define TFT_RST 10
#define TFT_RST 15

@sjorsvr
Copy link

sjorsvr commented Jan 4, 2025

did it work with esp32 2.0.14 ?

@tonbor
Copy link
Author

tonbor commented Jan 4, 2025 via email

@sjorsvr
Copy link

sjorsvr commented Jan 4, 2025

look into my change above , And I did NOT include in my user setup :
#define USE_HSPI_PORT
so in the code above it will reach the replaced line

@tonbor
Copy link
Author

tonbor commented Jan 5, 2025

Thanks, this is working, :-) #define USE_HSPI_PORT makes spi working SPI_PORT 3 your change makes spi working at SPI_PORT 2, Suppose sd is working at SPI_PORT 2 too.

@tonbor
Copy link
Author

tonbor commented Jan 5, 2025

Thanks, this is working, :-) #define USE_HSPI_PORT makes spi working SPI_PORT 3 your change makes spi working at SPI_PORT 2, Suppose sd is working at SPI_PORT 2 too.

had to change the ino setup too:
void setup() {
Serial.begin(115200);

// Set all chip selects high to avoid bus contention during initialisation of each peripheral
//digitalWrite(22, HIGH); // Touch controller chip select (if used)
pinMode(18, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(18, HIGH); // TFT screen chip select
digitalWrite( 10, HIGH); // SD card chips select, must use GPIO 5 (ESP32 SS)
if (!SD.begin(10)) {
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();

if (cardType == CARD_NONE) {
Serial.println("No SD card attached");
return;
}
Serial.print("SD Card Type: ");
if (cardType == CARD_MMC) {
Serial.println("MMC");
} else if (cardType == CARD_SD) {
Serial.println("SDSC");
} else if (cardType == CARD_SDHC) {
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
tft.begin();
Serial.println("initialisation done.");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants