-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump_sd_card.ino
64 lines (48 loc) · 1.48 KB
/
dump_sd_card.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
#include <SD.h>
#include "base64.h"
Sd2Card card;
void setup()
{
Serial.begin(115200);
pinMode(10, OUTPUT);
if (!card.init(SPI_HALF_SPEED, 10)) {
Serial.print("Error code: 0x");
Serial.println(card.errorCode(), HEX);
Serial.print("Status code: 0x");
Serial.println(card.errorData(), HEX);
Serial.println("");
// Several of my cards reported errors here but then worked fine, so
// let's keep going. If the card is unreadable, it will report 0
// blocks of capacity below.
}
Serial.print("Card type: 0x");
Serial.println(card.type(), HEX);
long blocks = card.cardSize();
Serial.print("512B blocks: ");
Serial.println(blocks);
Serial.println("");
Serial.println("begin");
uint8_t data[512];
char encoded[344];
char *p;
for (long blockNumber = 0; blockNumber < blocks; blockNumber++) {
if (!card.readBlock(blockNumber, data)) {
Serial.print("Error reading block ");
Serial.println(blockNumber);
} else {
// The Uno doesn't have enough RAM to base64 encode the entire
// 512B data block, so split it in two.
p = (char *) data;
while (p < data + 512) {
Base64encode(encoded, p, 256);
Serial.println(encoded);
p += 256;
}
}
}
Serial.println("done");
}
void loop()
{
// nothing happens after setup finishes.
}