From 373e6fa0615e8295aba484a39a0d8b541111ff91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20L=C3=A1ska?= Date: Mon, 14 Aug 2023 17:02:04 +0200 Subject: [PATCH] Create SD_Test.ino --- SW/SD_Test/SD_Test.ino | 114 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 SW/SD_Test/SD_Test.ino diff --git a/SW/SD_Test/SD_Test.ino b/SW/SD_Test/SD_Test.ino new file mode 100755 index 0000000..7d772e3 --- /dev/null +++ b/SW/SD_Test/SD_Test.ino @@ -0,0 +1,114 @@ +#include "FS.h" +#include +#include + +#define SCK 14 +#define MISO 12 +#define MOSI 13 +#define SS 15 + + +SPIClass SPISD(HSPI); + +void printDirectory(File dir, int numTabs); + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(115200); + SPI.begin(SCK, MISO, MOSI, -1); + + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.print("MOSI: "); + Serial.println(MOSI); + Serial.print("MISO: "); + Serial.println(MISO); + Serial.print("SCK: "); + Serial.println(SCK); + Serial.print("SS: "); + Serial.println(SS); + + Serial.print("\nInitializing SD card..."); + + // we'll use the initialization code from the utility libraries + // since we're just testing if the card is working! + if (!SD.begin(SS)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("* is a card inserted?"); + Serial.println("* is your wiring correct?"); + Serial.println("* did you change the chipSelect pin to match your shield or module?"); + while (1); + } else { + Serial.println("Wiring is correct and a card is present."); + } + + // print the type of card + Serial.println(); + Serial.print("Card type: "); + switch (SD.cardType()) { + case CARD_NONE: + Serial.println("NONE"); + break; + case CARD_MMC: + Serial.println("MMC"); + break; + case CARD_SD: + Serial.println("SD"); + break; + case CARD_SDHC: + Serial.println("SDHC"); + break; + default: + Serial.println("Unknown"); + } + + // print the type and size of the first FAT-type volume +// uint32_t volumesize; +// Serial.print("Volume type is: FAT"); +// Serial.println(SDFS.usefatType(), DEC); + + Serial.print("Card size: "); + Serial.println((float)SD.cardSize()/1000); + + Serial.print("Total bytes: "); + Serial.println(SD.totalBytes()); + + Serial.print("Used bytes: "); + Serial.println(SD.usedBytes()); + + File dir = SD.open("/"); + printDirectory(dir, 0); + +} + +void loop(void) { +} + +void printDirectory(File dir, int numTabs) { + while (true) { + + File entry = dir.openNextFile(); + if (! entry) { + // no more files + break; + } + for (uint8_t i = 0; i < numTabs; i++) { + Serial.print('\t'); + } + Serial.print(entry.name()); + if (entry.isDirectory()) { + Serial.println("/"); + printDirectory(entry, numTabs + 1); + } else { + // files have sizes, directories do not + Serial.print("\t\t"); + Serial.print(entry.size(), DEC); + time_t lw = entry.getLastWrite(); + struct tm * tmstruct = localtime(&lw); + Serial.printf("\tLAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); + } + entry.close(); + } +}