Write test program for the SdFat library
This commit is contained in:
parent
a77fcf637c
commit
f80571e444
1 changed files with 44 additions and 0 deletions
44
iot/SdFatTest/SdFatTest.ino
Normal file
44
iot/SdFatTest/SdFatTest.ino
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <SdFat.h>
|
||||||
|
|
||||||
|
#define PIN_SPI_CHIP_SELECT_OTHER_DEVICE SS
|
||||||
|
#define PIN_SPI_CHIP_SELECT 3
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
// Disable everything by default
|
||||||
|
pinMode(PIN_SPI_CHIP_SELECT_OTHER_DEVICE, OUTPUT);
|
||||||
|
pinMode(PIN_SPI_CHIP_SELECT, 3);
|
||||||
|
digitalWrite(PIN_SPI_CHIP_SELECT_OTHER_DEVICE, HIGH);
|
||||||
|
digitalWrite(PIN_SPI_CHIP_SELECT, HIGH);
|
||||||
|
|
||||||
|
Serial.println("Setup complete");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
SdFat card;
|
||||||
|
if(!card.begin(PIN_SPI_CHIP_SELECT, SD_SCK_MHZ(50))) {
|
||||||
|
card.initErrorHalt();
|
||||||
|
}
|
||||||
|
|
||||||
|
SdFile file;
|
||||||
|
|
||||||
|
if(!file.open("TEST.TXT", O_WRITE | O_CREAT | O_APPEND)) {
|
||||||
|
Serial.println(F("Error: Failed to open microSD card"));
|
||||||
|
while(true) delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
char message[] = "strawberry\n";
|
||||||
|
file.write(message, 11);
|
||||||
|
|
||||||
|
if(!file.sync() || file.getWriteError()) {
|
||||||
|
Serial.println(F("Error: Failed to open microSD card"));
|
||||||
|
while(true) delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
Serial.println(F("tick"));
|
||||||
|
|
||||||
|
delay(5000);
|
||||||
|
}
|
Loading…
Reference in a new issue