-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlash_Storage.ino
More file actions
81 lines (66 loc) · 2.23 KB
/
Copy pathFlash_Storage.ino
File metadata and controls
81 lines (66 loc) · 2.23 KB
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
// Credit to Marzogh for example code that was used
// Written by Roman Silivra for UC Berkeley STAR
#include <SPIMemory.h>
// Designate SPI pins
const int8_t PIN_SCK = 8;
const int8_t PIN_MISO = 10;
const int8_t PIN_MOSI = 9;
const int8_t PIN_CS = 14; // CS pins are 11, 12, 13, 14, 21, 47, 48; all but 14 (250 MB NAND) currently work, suspect wiring issue
const unsigned long BAUD_RATE = 115200;
// Method to print horizontal lines
void printLine() {
Serial.println();
for (uint8_t i = 0; i < 125; i++) {
Serial.print("-");
}
Serial.println();
}
// Initialize the flash object
SPIFlash flash(PIN_CS);
void setup() {
// Start SPI
SPI.begin(PIN_SCK, PIN_MISO, PIN_MOSI, PIN_CS);
// Start Serial
Serial.begin(BAUD_RATE);
while(!Serial);
delay(50);
// Horizontal line to improve visibility
printLine();
Serial.println("Serial connection established, beginning flash");
// Start flash assuming size of 32 Megabytes, check for errors
flash.begin();
// if (flash.error()) {
// Serial.println(flash.error(VERBOSE));
// }
Serial.println("Flash set-up complete");
// // Erase chip
// Serial.println("Erasing chip...");
// flash.eraseBlock32K(0);
// Serial.println("Erased chip");
// Test String "Hello world!"
String testStr = "Hello world!";
uint16_t strSize = sizeof(char)*(testStr.length()+1);
Serial.print("Size of string is: ");
Serial.println(strSize);
uint32_t testAddress = flash.getAddress(strSize);
Serial.print("Address of string is: 0x");
Serial.println(testAddress, HEX);
// Try to write that String to memory
flash.writeStr(testAddress, testStr, strSize);
String outputStr = String(testStr.length()+1);
// Try to read that String from memory
flash.readStr(testAddress, outputStr, strSize);
delay(20);
Serial.print("The read string is: ");
Serial.println(outputStr);
// uint16_t testUint = 0;
// testAddress = testAddress + 0xD;
// Serial.print("Address of string is: 0x");
// Serial.println(testAddress, HEX);
// testUint = flash.readWord(testAddress);
// delay(20);
// Serial.print("The read word is: ");
// Serial.println(testUint, HEX);
}
void loop() {
}