1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include <SPI.h>
- #include "SdFat.h"
- #error See Version 2 software SPI example
- #if ENABLE_SOFTWARE_SPI_CLASS
- const uint8_t SOFT_MISO_PIN = 12;
- const uint8_t SOFT_MOSI_PIN = 11;
- const uint8_t SOFT_SCK_PIN = 13;
- const uint8_t SD_CHIP_SELECT_PIN = 10;
- SdFatSoftSpi<SOFT_MISO_PIN, SOFT_MOSI_PIN, SOFT_SCK_PIN> sd;
- SdFile file;
- void setup() {
- Serial.begin(9600);
-
- while (!Serial) {
- SysCall::yield();
- }
- Serial.println("Type any character to start");
- while (!Serial.available()) {
- SysCall::yield();
- }
- if (!sd.begin(SD_CHIP_SELECT_PIN)) {
- sd.initErrorHalt();
- }
- if (!file.open("SoftSPI.txt", O_RDWR | O_CREAT)) {
- sd.errorHalt(F("open failed"));
- }
- file.println(F("This line was printed using software SPI."));
- file.rewind();
-
- while (file.available()) {
- Serial.write(file.read());
- }
- file.close();
- Serial.println(F("Done."));
- }
- void loop() {}
- #else
- #error ENABLE_SOFTWARE_SPI_CLASS must be set non-zero in SdFat/SdFatConfig.h
- #endif
|