3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ESP32 と MicroSD スロットの結線(SPIの場合)

Last updated at Posted at 2022-05-20

結論

Arduino のコードでは、下記のピンがデフォルトになっているようです、

pins_arduino.h
static const uint8_t SS    = 5;
static const uint8_t MOSI  = 23;
static const uint8_t MISO  = 19;
static const uint8_t SCK   = 18;

つまり、下記の通りです。

ESP32 PIN番号 SPI(ESP側) SPI(MicroSD側) SD mode
5 SS CS CD/DAT3
23 MOSI D1 CMD
19 MISO D0 DAT0
18 SCK SCLK CLK

Arduino の場合

上記の結線をした場合、下記のコードでいけます。

.cpp
#include <SD.h>

void setup() {
  Serial.begin(115200);
  
  if(!SD.begin(sd_ss)){
      Serial.println("Card Mount Failed");
      return;
  }
  Serial.println("INIT OK");
}

SPI のピンを変更する場合は下記です。

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

enum { // ここを適切に変更する
    sd_ss = 5,
    sd_mosi = 23,
    sd_miso = 19,
    sd_sck = 18
};

void setup()
{
    SPI.end();
    SPI.begin( sd_sck, sd_miso, sd_mosi, sd_ss );

    Serial.begin(115200);

    if ( !SD.begin( sd_ss, SPI ) )
    {
       Serial.println("Card Mount Failed");
       return;
    }
}

参考

悩んだらコードをみるべし。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?