Write test program for the SdFat library

This commit is contained in:
Starbeamrainbowlabs 2019-07-11 13:10:24 +01:00
parent a77fcf637c
commit f80571e444

View 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);
}