Regarding esp32s3 and sd card or SPI intialisation

I am new to esp32s3, i am not able to intialise sd card through esp32s3, basically spi is not working.

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

#define PIN_MOSI 20
#define PIN_MISO 21
#define PIN_SCK 47
#define PIN_CS 48

File myFile;

void setup() {
  Serial.begin(9600);

  // Initialize software SPI
  SPI.begin(PIN_SCK, PIN_MISO, PIN_MOSI);

  // Deselect SD card initially
  pinMode(PIN_CS, OUTPUT);
  digitalWrite(PIN_CS, HIGH);

  if (!SD.begin(PIN_CS)) {
    Serial.println(F("SD CARD FAILED, OR NOT PRESENT!")); // don't do anything more:
  }

  Serial.println(F("SD CARD INITIALIZED."));

  if (!SD.exists("arduino.txt")) {
    Serial.println(F("arduino.txt doesn't exist. Creating arduino.txt file..."));
    // create a new file by opening a new file and immediately close it
    myFile = SD.open("arduino.txt", FILE_WRITE);
    myFile.close();
  }

  // recheck if file is created or not
  if (SD.exists("arduino.txt"))
    Serial.println(F("arduino.txt exists on SD Card."));
  else
    Serial.println(F("arduino.txt doesn't exist on SD Card."));
}

void loop() {
  // Your main code goes here
}

``` i am getting sd card not intialised, i am using custom pins. i tried with default pins that is also not working.why?? 
thank you

Can you reveal which ESP32S3 board you are using ?

And which SD card adapter board you are using ?

Pin 48 for PIN_CS is one that you may need to avoid.

i am using esp32-s3 wroom-1u, also i used cs as 10 and 5 also, i am using micosd-card adapter HW-125, the normal one. i think the problem is with intialising spi.
Thank You...

Is that not the one used to connect micro SD cards to 5V logic Arduinos ?

Whenever I connect a micro SD card up to an ESP32, I always use an adapter thats designed for 3.3V logic Arduinos.

yes that is the one which i am using
image
if this is not Which sd card module should i use.. also it has logical level shifter

Just to see if that's the problem, can you power the SD module with 5V? It should work that way. It will level shift 3.3V to 3.3V, but it should still work.

And try running an example from the library.

With one side of the level shifter connected to 5V and the other connected to 3.3V (from the regulator ?), the normal situation, I would have thought the level shifter is expecting 5V logic signals on the module pins .........

The level shifter is typically a 74LVC125A, which is powered by 3.3V out of the 3.3V regulator. It's basically just a buffer with 5V-tolerant inputs. So it will work with either 5V or 3.3V input. Of course it's totally unnecessary with 3.3V input, but it should still work, and that could help isolate where the problem is. But you do need 5V coming in on the Vcc pin. Otherwise you have 3.3V on the input of a 3.3V regulator, which doesn't quite satisfy the dropout requirements.

i tried with powering of 5v it did not work, i used default spi pins and custom its still not working, i personally think that problem is with intialisation of SPI in esp-s3. please help. thank you

With the correct pins defined and connected, I have not had a problem with the 'intialisation' on an ESP32S3, LoRa devcices, TFt displays and SD cards, so you probably have yours wired up incorrectly, and\or the SD card or adapter is faulty.

Or the Arduino IDE is not set correctly.

Try to add also the CS pin and let the SD library handle the pin mode and the pin level (remove the 2 lines from setup)

My module is different (without 74LCV125) but I have no problem with the ESP32-S3 and custom pins.

Do you have an Arduino that you could use to test the HW-125 and the SD card, just to be sure they are working? An example sketch from the SD.h library should work.