Low speed writing SDIO interface of ESP32S3 on SD Card

Hi Everyone
I want to take pictures using ESP32-S3-WROOM-1-N16R8 module and using OV2640 camera and save them on SD Card, but writing speed on SD Card is very slow.
.
SD card NO limitation in speed.
The frequency of the SDIO is 40 MHz.
But why is the speed of writing files on the SD Card so low? Is there something wrong with the code? Can it be due to the amount of pull-up resistor?

Code

#include "esp_camera.h"
#include "SD_MMC.h"

// Define Camera pins
#define PWDN_GPIO_NUM  -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM  10
#define SIOD_GPIO_NUM  4
#define SIOC_GPIO_NUM  5
#define Y9_GPIO_NUM    9
#define Y8_GPIO_NUM    11
#define Y7_GPIO_NUM    12
#define Y6_GPIO_NUM    14
#define Y5_GPIO_NUM    47
#define Y4_GPIO_NUM    45
#define Y3_GPIO_NUM    48
#define Y2_GPIO_NUM    21
#define VSYNC_GPIO_NUM 3
#define HREF_GPIO_NUM  46
#define PCLK_GPIO_NUM  13

// Define SDIO pins
#define MMCSCK 16
#define MMCCMD 17
#define MMCD0 15
#define MMCD1 7
#define MMCD2 8
#define MMCD3 18


// Frame settings
#define FRAME_RATE       10  // FPS
#define FRAME_DURATION   1000 / FRAME_RATE  // Duration of each frame in milliseconds

unsigned long now;
static unsigned long lastCapture = 0;

static int frameCount = 0;
static File file;


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

    // Camera configuration
    camera_config_t config;
    config.ledc_channel = LEDC_CHANNEL_0;
    config.ledc_timer = LEDC_TIMER_0;
    config.pin_d0 = Y2_GPIO_NUM;
    config.pin_d1 = Y3_GPIO_NUM;
    config.pin_d2 = Y4_GPIO_NUM;
    config.pin_d3 = Y5_GPIO_NUM;
    config.pin_d4 = Y6_GPIO_NUM;
    config.pin_d5 = Y7_GPIO_NUM;
    config.pin_d6 = Y8_GPIO_NUM;
    config.pin_d7 = Y9_GPIO_NUM;
    config.pin_xclk = XCLK_GPIO_NUM;
    config.pin_pclk = PCLK_GPIO_NUM;
    config.pin_vsync = VSYNC_GPIO_NUM;
    config.pin_href = HREF_GPIO_NUM;
    config.pin_sccb_sda = SIOD_GPIO_NUM;
    config.pin_sccb_scl = SIOC_GPIO_NUM;
    config.pin_pwdn = PWDN_GPIO_NUM;
    config.pin_reset = RESET_GPIO_NUM;
    config.xclk_freq_hz = 20000000;
    config.pixel_format = PIXFORMAT_JPEG;

    // Set the resolution frame image
    config.frame_size = FRAMESIZE_XGA; //1024x768
    config.jpeg_quality = 12;
    config.fb_count = 1;

    // Use PSRAM for the frame buffer
    config.fb_location = CAMERA_FB_IN_PSRAM;

    if (psramFound()) {
      Serial.println("PSRAM FOUND"); // when run code alwayse PSRAM FOUND.
    }

    // Initialize the camera
    if (esp_camera_init(&config) != ESP_OK) {
        Serial.println("Failed to initialize camera.");
        return;
    }

    // Initialize SD card
    SD_MMC.setPins(MMCSCK, MMCCMD, MMCD0, MMCD1, MMCD2, MMCD3);
    if (!SD_MMC.begin()) {
        Serial.println("SD card mount failed.");
        return;
    }

    Serial.println("SD card initialized.");
}

void loop() {

    now = millis();

    if (now - lastCapture>=FRAME_DURATION) {
        lastCapture = now;
                
        // Capture a frame
        camera_fb_t *fb = esp_camera_fb_get();
        if (!fb) {
            Serial.println("Failed to capture image.");
            return;
        }
        
        // Save frame to SD card
        String path = "/frame" + String(frameCount) + ".jpg";
        
        file = SD_MMC.open(path, FILE_WRITE);
        if (!file) {
            Serial.println("Failed to open file for writing.");
            esp_camera_fb_return(fb);
            return;
        }

        file.write(fb->buf, fb->len);
        file.close();
        
        esp_camera_fb_return(fb);

        frameCount++;
    }

    // Capture frames for 10 seconds
    if (millis() - start_capture >= 10000) {
        Serial.println("Capture complete.");
        while (true);  // Stop the loop
    }
}

.

Freq Setting:


.
SD Card:
SD Card

And "very slow" is exactly ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.