[ESP32-Audio-Kit音频开发板测评]SD卡的读写
<p style="text-align:justify">在音频开发板上配有TF卡接口,该接口在程序的控制下,可对TF卡进行读写操作。TF卡的接口电路及实物状态分别如图1和图2所示。</p><p>图1 TF卡接口电路</p>
<p></p>
<p>图2 实物状态</p>
<p>TF卡各引脚的连接关系见表1所示:</p>
<p>表1 引脚连接关系</p>
<table>
<tbody>
<tr>
<td>
<p>TF卡</p>
</td>
<td>
<p>开发板</p>
</td>
</tr>
<tr>
<td>
<p>VDD</p>
</td>
<td>
<p>3.3V</p>
</td>
</tr>
<tr>
<td>
<p>D0</p>
</td>
<td>
<p>2 (add 1K pull up after flashing)</p>
</td>
</tr>
<tr>
<td>
<p>D1</p>
</td>
<td>
<p>4</p>
</td>
</tr>
<tr>
<td>
<p>D2</p>
</td>
<td>
<p>12</p>
</td>
</tr>
<tr>
<td>
<p>D3</p>
</td>
<td>
<p>13</p>
</td>
</tr>
<tr>
<td>
<p>CLK</p>
</td>
<td>
<p>14</p>
</td>
</tr>
<tr>
<td>
<p>CMD</p>
</td>
<td>
<p>15</p>
</td>
</tr>
<tr>
<td>
<p>VSS</p>
</td>
<td>
<p>GND</p>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p>由于引脚复用的关系,在进行TF卡读写时应S1的指拨开关设置到SD卡一侧,见图3所示。</p>
<p>图3指拨开关</p>
<p> </p>
<p>在进行TF卡读写时,需包含以下头文件:</p>
<p>#include "FS.h"</p>
<p>#include "SD_MMC.h"</p>
<p> </p>
<p>进行TF卡读写的程序如下:</p>
<pre>
<code class="language-cpp">void setup(){
Serial.begin(115200);
if(!SD_MMC.begin()){
Serial.println("Card Mount Failed");
return;
}
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");
} else {
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);
listDir(SD_MMC, "/", 0);
createDir(SD_MMC, "/mydir");
listDir(SD_MMC, "/", 0);
removeDir(SD_MMC, "/mydir");
listDir(SD_MMC, "/", 2);
writeFile(SD_MMC, "/hello.txt", "Hello ");
appendFile(SD_MMC, "/hello.txt", "World!\n");
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\n", SD_MMC.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
}
void loop(){
}</code></pre>
<p>经编译上传,其结果如图4所示。</p>
<p>图4读写文件结果</p>
<p> </p>
<p>在此基础上,若配上显示屏及图片显示函数,则可以实现数码相框功能。</p>
<p>一直在关注楼主的测评,讲的很细心</p>
<p>ESP32-Audio-Kit音频开发板的TF卡接口电路看起来很简洁。</p>
<p>楼主加油,在搞一个数码相框的测评</p>
火辣西米秀 发表于 2021-10-7 18:04
一直在关注楼主的测评,讲的很细心
ESP32-Audio-Kit音频开发板的TF卡接口电路看起来很简洁。
楼主加 ...
<p>努力!!!</p>
页:
[1]