Skip to content

Instantly share code, notes, and snippets.

@xeecos
Created June 27, 2022 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeecos/d6b84a46fafa151f86d30f8f1afc7b01 to your computer and use it in GitHub Desktop.
Save xeecos/d6b84a46fafa151f86d30f8f1afc7b01 to your computer and use it in GitHub Desktop.
#include "SdFat.h"
// SPI_DRIVER_SELECT == 0 // Must be set in SdFat/SdFatConfig.h
#define PIN_SD_CS 33
#define PIN_SD_MOSI 27
#define PIN_SD_MISO 25
#define PIN_SD_SCK 26
#define SD_FAT_TYPE 0
SPIClass spi(HSPI);
//#define ENABLE_DEDICATED_SPI 1
#define SD_CONFIG SdSpiConfig(PIN_SD_CS, DEDICATED_SPI, SD_SCK_MHZ(25), &spi)
SdFat sd;
SdFile file;
void setup()
{
Serial.begin(115200);
softSpi.begin(PIN_SD_SCK, PIN_SD_MISO, PIN_SD_MOSI, PIN_SD_CS);
// Wait for USB Serial
while (!Serial)
{
yield();
}
Serial.println("Type any character to start");
while (!Serial.available())
{
yield();
}
if (!sd.begin(SD_CONFIG))
{
sd.initErrorHalt();
}
Serial.println(F("Start."));
uint8_t *buf = (uint8_t *)malloc(16384);
for(int i=0;i<16384;i++)
{
buf[i] = i&0xff;
}
long t = micros();
if (!file.open("SoftSPI.txt", O_RDWR | O_CREAT))
{
sd.errorHalt(F("open failed"));
}
for (int i = 0; i < 32; i++)
{
file.write(buf, 16384);
}
file.close();
Serial.printf("Done:%d\n", micros()-t);
}
//------------------------------------------------------------------------------
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment