完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
首先我对这一切和学习还是陌生的。我不确定 ESP12E 是否能正确处理所有这些连接。最后,我希望在 ESP 上安装 gps/sd/audio。我正在逐个连接设备并学习如何操作,我能够连接音频板并使其正常工作。但是我无法将 SD 板连接到 ESP。
代码:全选/* * This program attempts to initialize an SD card and analyze its structure. */ #include #include "SdFat.h" #include "sdios.h" using namespace sdfat; // Set USE_SDIO to zero for SPI card access. #define USE_SDIO 0 /* * SD chip select pin. Common values are: * * Arduino Ethernet shield, pin 4. * SparkFun SD shield, pin 8. * Adafruit SD shields and modules, pin 10. * Default SD chip select is the SPI SS pin. */ const uint8_t SD_CHIP_SELECT = SS; /* * Set DISABLE_CHIP_SELECT to disable a second SPI device. * For example, with the Ethernet shield, set DISABLE_CHIP_SELECT * to 10 to disable the Ethernet controller. */ const int8_t DISABLE_CHIP_SELECT = -1; #if USE_SDIO // Use faster SdioCardEX SdFatSdioEX sd; // SdFatSdio sd; #else // USE_SDIO SdFat sd; #endif // USE_SDIO // serial output steam ArduinoOutStream cout(Serial); // global for card size uint32_t cardSize; // global for card erase size uint32_t eraseSize; //------------------------------------------------------------------------------ // store error strings in flash #define sdErrorMsg(msg) sd.errorPrint(F(msg)); //------------------------------------------------------------------------------ uint8_t cidDmp() { cid_t cid; if (!sd.card()->readCID(&cid)) { sdErrorMsg("readCID failed"); return false; } cout << F("\nManufacturer ID: "); cout << hex << int(cid.mid) << dec << endl; cout << F("OEM ID: ") << cid.oid[0] << cid.oid[1] << endl; cout << F("Product: "); for (uint8_t i = 0; i < 5; i++) { cout << cid.pnm; } cout << F("\nVersion: "); cout << int(cid.prv_n) << '.' << int(cid.prv_m) << endl; cout << F("Serial number: ") << hex << cid.psn << dec << endl; cout << F("Manufacturing date: "); cout << int(cid.mdt_month) << '/'; cout << (2000 + cid.mdt_year_low + 10 * cid.mdt_year_high) << endl; cout << endl; return true; } //------------------------------------------------------------------------------ uint8_t csdDmp() { csd_t csd; uint8_t eraseSingleBlock; if (!sd.card()->readCSD(&csd)) { sdErrorMsg("readCSD failed"); return false; } if (csd.v1.csd_ver == 0) { eraseSingleBlock = csd.v1.erase_blk_en; eraseSize = (csd.v1.sector_size_high << 1) | csd.v1.sector_size_low; } else if (csd.v2.csd_ver == 1) { eraseSingleBlock = csd.v2.erase_blk_en; eraseSize = (csd.v2.sector_size_high << 1) | csd.v2.sector_size_low; } else { cout << F("csd version error\n"); return false; } eraseSize++; cout << F("cardSize: ") << 0.000512*cardSize; cout << F(" MB (MB = 1,000,000 bytes)\n"); cout << F("flashEraseSize: ") << int(eraseSize) << F(" blocks\n"); cout << F("eraseSingleBlock: "); if (eraseSingleBlock) { cout << F("true\n"); } else { cout << F("false\n"); } return true; } //------------------------------------------------------------------------------ // print partition table uint8_t partDmp() { mbr_t mbr; if (!sd.card()->readBlock(0, (uint8_t*)&mbr)) { sdErrorMsg("read MBR failed"); return false; } for (uint8_t ip = 1; ip < 5; ip++) { part_t *pt = &mbr.part[ip - 1]; if ((pt->boot & 0X7F) != 0 || pt->firstSector > cardSize) { cout << F("\nNo MBR. Assuming Super Floppy format.\n"); return true; } } cout << F("\nSD Partition Table\n"); cout << F("part,boot,type,start,length\n"); for (uint8_t ip = 1; ip < 5; ip++) { part_t *pt = &mbr.part[ip - 1]; cout << int(ip) << ',' << hex << int(pt->boot) << ',' << int(pt->type); cout << dec << ',' << pt->firstSector <<',' << pt->totalSectors << endl; } return true; } //------------------------------------------------------------------------------ void volDmp() { cout << F("\nVolume is FAT") << int(sd.vol()->fatType()) << endl; cout << F("blocksPerCluster: ") << int(sd.vol()->blocksPerCluster()) << endl; cout << F("clusterCount: ") << sd.vol()->clusterCount() << endl; cout << F("freeClusters: "); uint32_t volFree = sd.vol()->freeClusterCount(); cout << volFree << endl; float fs = 0.000512*volFree*sd.vol()->blocksPerCluster(); cout << F("freeSpace: ") << fs << F(" MB (MB = 1,000,000 bytes)\n"); cout << F("fatStartBlock: ") << sd.vol()->fatStartBlock() << endl; cout << F("fatCount: ") << int(sd.vol()->fatCount()) << endl; cout << F("blocksPerFat: ") << sd.vol()->blocksPerFat() << endl; cout << F("rootDirStart: ") << sd.vol()->rootDirStart() << endl; cout << F("dataStartBlock: ") << sd.vol()->dataStartBlock() << endl; if (sd.vol()->dataStartBlock() % eraseSize) { cout << F("Data area is not aligned on flash erase boundaries!\n"); cout << F("Download and use formatter from www.sdcard.org!\n"); } } //------------------------------------------------------------------------------ void setup() { Serial.begin(9600); // Wait for USB Serial while (!Serial) { SysCall::yield(); } // use uppercase in hex and use 0X base prefix cout << uppercase << showbase << endl; // F stores strings in flash to save RAM cout << F("SdFat version: ") << SD_FAT_VERSION << endl; #if !USE_SDIO if (DISABLE_CHIP_SELECT < 0) { cout << F( "\nAssuming the SD is the only SPI device.\n" "Edit DISABLE_CHIP_SELECT to disable another device.\n"); } else { cout << F("\nDisabling SPI device on pin "); cout << int(DISABLE_CHIP_SELECT) << endl; pinMode(DISABLE_CHIP_SELECT, OUTPUT); digitalWrite(DISABLE_CHIP_SELECT, HIGH); } cout << F("\nAssuming the SD chip select pin is: ") <= 0); // F stores strings in flash to save RAM cout << F("\ntype any character to start\n"); while (!Serial.available()) { SysCall::yield(); } uint32_t t = millis(); #if USE_SDIO if (!sd.cardBegin()) { sdErrorMsg("\ncardBegin failed"); return; } #else // USE_SDIO // Initialize at the highest speed supported by the board that is // not over 50 MHz. Try a lower speed if SPI errors occur. if (!sd.cardBegin(SD_CHIP_SELECT, SD_SCK_MHZ(50))) { sdErrorMsg("cardBegin failed"); return; } #endif // USE_SDIO t = millis() - t; cardSize = sd.card()->cardSize(); if (cardSize == 0) { sdErrorMsg("cardSize failed"); return; } cout << F("\ninit time: ") << t << " ms" << endl; cout << F("\nCard type: "); switch (sd.card()->type()) { case SD_CARD_TYPE_SD1: cout << F("SD1\n"); break; case SD_CARD_TYPE_SD2: cout << F("SD2\n"); break; case SD_CARD_TYPE_SDHC: if (cardSize < 70000000) { cout << F("SDHC\n"); } else { cout << F("SDXC\n"); } break; default: cout << F("Unknown\n"); } if (!cidDmp()) { return; } if (!csdDmp()) { return; } uint32_t ocr; if (!sd.card()->readOCR(&ocr)) { sdErrorMsg("\nreadOCR failed"); return; } cout << F("OCR: ") << hex << ocr << dec << endl; if (!partDmp()) { return; } if (!sd.fsBegin()) { sdErrorMsg("\nFile System initialization failed.\n"); return; } volDmp(); } |
|
相关推荐 |
|
只有小组成员才能发言,加入小组>>
540浏览 6评论
451浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
434浏览 5评论
435浏览 4评论
407浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-15 20:16 , Processed in 0.923898 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号