44 lines
948 B
C++
44 lines
948 B
C++
#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);
|
|
}
|