sdcard read with ESP32-LyraT-Mini V1.2

pavepart
Posts: 9
Joined: Thu Jun 25, 2020 4:38 am

sdcard read with ESP32-LyraT-Mini V1.2

Postby pavepart » Sat Feb 13, 2021 12:14 pm

Image

Recently I got ESP32-LyraT-Mini V1.2 board.
Today try to read & write sdcard. But it doesn't work.
I referred this code.
https://github.com/espressif/esp-idf/bl ... ple_main.c

in this description, ESP32-LyraT-Mini support SPI/1-bit mode.
https://docs.espressif.com/projects/esp ... crosd-card

where should I change in my code?

Code: Select all

void app_main(void)
{
    printf("Hello world!\n");
    // xTaskCreate((void *) task_01, "Task 01", 1024 * 2, "Task01", 2, &h_myTask);

    vTaskDelay(100/portTICK_PERIOD_MS);
    esp_err_t ret;
    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
        .format_if_mount_failed = false,
        .max_files = 5,

    };

    sdmmc_card_t* card;
    const char mount_point[] = MOUNT_POINT;
    ESP_LOGI(TAG, "Initializing SD card");


    ESP_LOGI(TAG, "Using SDMMC peripheral");
    sdmmc_host_t host = SDMMC_HOST_DEFAULT();
    host.flags = SDMMC_HOST_FLAG_1BIT;

    sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
    slot_config.width = 1;


    gpio_set_pull_mode(15, GPIO_PULLUP_ONLY);   // CMD, needed in 4- and 1- line modes
    gpio_set_pull_mode(2, GPIO_PULLUP_ONLY);    // D0, needed in 4- and 1-line modes
    gpio_set_pull_mode(4, GPIO_PULLUP_ONLY);    // D1, needed in 4-line mode only
    gpio_set_pull_mode(12, GPIO_PULLUP_ONLY);   // D2, needed in 4-line mode only
    gpio_set_pull_mode(13, GPIO_PULLUP_ONLY);   // D3, needed in 4- and 1-line modes

    ESP_LOGI(TAG, "ret");
    ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);

    if (ret != ESP_OK) {
        if (ret == ESP_FAIL) {
            ESP_LOGE(TAG, "Failed to mount filesystem. "
                "If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option.");
        } else {
            ESP_LOGE(TAG, "Failed to initialize the card (%s). "
                "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret));
        }
        return;
    }

    ESP_LOGI(TAG, "MOUNT_POINT");
    FILE* f = fopen(MOUNT_POINT"/hello.txt", "w");
    if (f == NULL) {
        ESP_LOGE(TAG, "Failed to open file for writing");
        return;
    }
    fprintf(f, "Hello %s!\n", card->cid.name);
    fclose(f);
    ESP_LOGI(TAG, "File written");
}

Altivecer
Posts: 15
Joined: Thu May 05, 2022 10:55 pm

Re: sdcard read with ESP32-LyraT-Mini V1.2

Postby Altivecer » Wed Jun 22, 2022 11:00 pm

I don't know if you ever figured this out, but I ran into the same issue.

You need to set GPIO 13 as an output and drive it low. This turns on the power to the SD Card.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 333 guests