Any concerns? support@freenove.com
Chapter 4 Read and Write the SDcard
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
readFile(SD_MMC, "/hello.txt");
deleteFile(SD_MMC, "/foo.txt");
renameFile(SD_MMC, "/hello.txt", "/foo.txt");
readFile(SD_MMC, "/foo.txt");
testFileIO(SD_MMC, "/test.txt");
Serial.printf("Total space: %lluMB\r\n", SD_MMC.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\r\n", SD_MMC.usedBytes() / (1024 * 1024));
}
void loop(){
delay(10000);
}
Add the SD card drive header file.
#include "sd_read_write.h"
#include "SD_MMC.h"
Defines the drive pins of the SD card. Please do not modify it. Because these pins are fixed.
#define SD_MMC_CMD 38 //Please do not modify it.
#define SD_MMC_CLK 39 //Please do not modify it.
#define SD_MMC_D0 40 //Please do not modify it.
Initialize the serial port function. Sets the drive pin for SDMMC one-bit bus mode.
Serial.begin(115200);
SD_MMC.setPins(SD_MMC_CLK, SD_MMC_CMD, SD_MMC_D0);
Set the mount point of the SD card, set SDMMC to one-bit bus mode, and set the read and write speed to
20MHz.
if (!SD_MMC.begin("/sdcard", true, true, SDMMC_FREQ_DEFAULT, 5)) {
Serial.println("Card Mount Failed");
return;
}
Get the type of SD card and print it out through the serial port.
15
16
17
18
19
20
21
22
23
24
25
26
uint8_t cardType = SD_MMC.cardType();
if(cardType == CARD_NONE){
Serial.println("No SD_MMC card attached");
return;
}
Serial.print("SD_MMC Card Type: ");
if(cardType == CARD_MMC){
Serial.println("MMC");
} else if(cardType == CARD_SD){
Serial.println("SDSC");
} else if(cardType == CARD_SDHC){
Serial.println("SDHC");