-
Notifications
You must be signed in to change notification settings - Fork 1
/
SD.ino
113 lines (91 loc) · 2.38 KB
/
SD.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* @Description:SD card test procedure.
* @version: V1.0.0
* @Author: LILYGO_L
* @Date: 2023-08-18 15:33:23
* @LastEditors: LILYGO_L
* @LastEditTime: 2023-11-22 17:23:31
* @License: GPL 3.0
*/
#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include "pin_config.h"
File testFile;
bool SelfLocking_Flag = false;
void setup()
{
Serial.begin(115200);
// pinMode(37, INPUT_PULLUP);// MISO pull-up resistor
SPI.begin(SD_SCLK, SD_MISO, SD_MOSI, SD_CS); // SPI boots
}
void loop()
{
uint8_t cardType = 0;
uint64_t cardSize = 0;
uint8_t numSectors = 0;
if (!SD.begin(SD_CS, SPI, 40000000)) // SD boots
{
SelfLocking_Flag = false;
Serial.println("Detecting SD card");
Serial.println("SD card initialization failed !");
delay(100);
Serial.println(".");
delay(100);
Serial.println(".");
delay(100);
Serial.println(".");
delay(100);
Serial.println(".");
delay(100);
Serial.println(".");
delay(100);
Serial.println(".");
delay(100);
}
else
{
delay(50); // Wait for the SD card
if (SelfLocking_Flag == false)
{
SelfLocking_Flag = true;
delay(50);
}
Serial.println("SD card initialization successful !");
delay(100);
cardType = SD.cardType();
cardSize = SD.cardSize() / (1024 * 1024);
numSectors = SD.numSectors();
switch (cardType)
{
case CARD_NONE:
Serial.println("No SD card attached");
delay(100);
break;
case CARD_MMC:
Serial.print("SD Card Type: ");
Serial.println("MMC");
Serial.printf("SD Card Size: %lluMB\n", cardSize);
delay(100);
break;
case CARD_SD:
Serial.print("SD Card Type: ");
Serial.println("SDSC");
Serial.printf("SD Card Size: %lluMB\n", cardSize);
delay(100);
break;
case CARD_SDHC:
Serial.print("SD Card Type: ");
Serial.println("SDHC");
Serial.printf("SD Card Size: %lluMB\n", cardSize);
delay(100);
break;
default:
Serial.println("UNKNOWN");
delay(100);
break;
}
}
SD.end();
}