Xinyuan-LilyGO / T-Deck

191 stars 43 forks source link

SD card is not working #30

Open laulin opened 1 month ago

laulin commented 1 month ago

Hello !

I read the pinout from utilities.h and I write a micropython code to mount the SD card :

from machine import SPI, Pin
from sdcard import SDCard
import os
import hw

power_en = Pin(hw.PERI_POWERON, mode=Pin.OUT, value=1)

clk = Pin(hw.SPI_SCK, mode=Pin.OUT, value=0) # pin 40
mosi = Pin(hw.SPI_MOSI, mode=Pin.OUT, value=0) # pin 41
miso = Pin(hw.SPI_MISO, mode=Pin.IN) # pin 38
cs_sd = Pin(hw.SDCARD_CS, mode=Pin.OUT, value=1) # pin 39

spi = SPI(1, baudrate=int(hw.SPI_SPEED), sck=clk, mosi=mosi, miso=miso)

try:
    print("SDcard")
    sd = SDCard(spi, cs_sd)
    print("Sdcard mounted")
    os.mount(sd, '/sd')
except Exception as e:
    print(str(e))

I always got "OSError: no SD card". The SPI works since I can use the TFT display and I check on the schematic that ESP_SD_CS is on IO39 (real pin : 32).

Do you have any idea ?

contractorwolf commented 2 weeks ago

I am having this same issue, cut my code back to barebones but it only says that is doesnt see the sd card. no damage to the card reader or card. Card is brand new and FAT32 formatted.

lewisxhe commented 1 week ago

Refer to the Arduino initialization code, you need to turn on POWERON and disable the CS of other SPI devices. https://github.com/Xinyuan-LilyGO/T-Deck/blob/36841457bf1c4f9a6e88c9de2199f6ff132885a5/examples/UnitTest/UnitTest.ino#L941