赞
踩
如果网页无法加载,将域名改为镜像地址的例如:https://hub.fastgit.org/nhatuan84/esp32-micro-sdcard
if (!SD.begin()) {
Serial.println("initialization failed!");
return;
}
if (!SD.begin(26, 14, 13, 27)) {
Serial.println("initialization failed!");
return;
}
Soft SPI
[ESP32 IO26 – CS MICRO SD]
[ESP32 IO14 – MOSI MICRO SD]
[ESP32 IO13 – MISO MICRO SD]
[ESP32 IO27 – SCK MICRO SD]
[ESP32 GND – GND MICRO SD]
[VIN – VCC MICRO SD]
Hard SPI
* MICROSD CS - ESP32 IO5
MICROSD SCK - ESP32 IO18
MICROSD MOSI - ESP32 IO23
MICROSD MISO - ESP32 IO19
MICROSD Vcc - ESP32 VIN
MICROSD GND - ESP32 GND
#include <SPI.h>
#include <mySD.h>
File root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on Arduino Uno boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
// pinMode(SS, OUTPUT);
if (!SD.begin(26, 14, 13, 27)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!");
}
void loop()
{
// nothing happens after setup finishes.
}
void printDirectory(File dir, int numTabs) {
// Begin at the start of the directory
dir.rewindDirectory();
while(true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
//Serial.println("**nomorefiles**");
break;
}
for (uint8_t i=0; i<numTabs; i++) {
Serial.print('\t'); // we'll have a nice indentation
}
// Print the 8.3 name
Serial.print(entry.name());
// Recurse for directories, otherwise print the file size
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs+1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
使用 1.0 版本的库 SPI 在文件夹: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SPI
使用库 esp32-micro-sdcard-master 在文件夹: C:\Program Files (x86)\Arduino\libraries\esp32-micro-sdcard-master (legacy)
"C:\\Users\\Administrator\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-97-gc752ad5-5.2.0/bin/xtensa-esp32-elf-size" -A "d:\\arduino\\MyHexDir/nanosdcard1.ino.elf"
项目使用了 216594 字节,占用了 (16%) 程序存储空间。最大为 1310720 字节。
全局变量使用了14224字节,(4%)的动态内存,余留313456字节局部变量。最大为327680字节。
实例代码一
读取到卡内信息,但是读不全信息。Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。