New to Particle and need some assistance on an SD card reader.
I am using the SDFat library in conjunction with a sparkfun SD card reader which I soldered some pins on. I am using an example code provided by GitHub to test out the reader and keep receiving an error- “SD errorCode: 0XF,0X1”. Was not sure what was causing the error since I am unfamiliar with the registers of the Particle Electron board in which I am using. Just looking for any assistance. Any help would be greatly appreciated.
I have tried to tweak the code to work with the wiring/pin setup. (Basically I tried to use pins A2,A3,A4,A5)
The full error says: “error: opening test.txt for write failed
SD errorCode: 0XF,0X1”
Below is the example code:
#include "SdFat/SdFat.h"
// Pick an SPI configuration.
// See SPI configuration section below (comments are for photon).
#define SPI_CONFIGURATION 3
//------------------------------------------------------------------------------
// Setup SPI configuration.
#if SPI_CONFIGURATION == 0
// Primary SPI with DMA
// SCK => A3, MISO => A4, MOSI => A5, SS => A2 (default)
SdFat sd;
const uint8_t chipSelect = A2;
//#elif SPI_CONFIGURATION == 1
// Secondary SPI with DMA
// SCK => D4, MISO => D3, MOSI => D2, SS => D1
//SdFat sd(1);
//const uint8_t chipSelect = D1;
#elif SPI_CONFIGURATION == 2
// Primary SPI with Arduino SPI library style byte I/O.
// SCK => A3, MISO => A4, MOSI => A5, SS => A2 (default)
SdFatLibSpi sd;
const uint8_t chipSelect = SS;
#elif SPI_CONFIGURATION == 3
// Software SPI. Use any digital pins.
// MISO => A4, MOSI => A5, SCK => A3, SS => A2
SdFatSoftSpi<A4, A5, A3> sd;
const uint8_t chipSelect = A2;
#endif // SPI_CONFIGURATION
//------------------------------------------------------------------------------
File myFile;
void setup() {
Serial.begin(9600);
// Wait for USB Serial
while (!Serial) {
SysCall::yield();
}
// Serial.println("Type any character to start");
//while (Serial.read() <= 0) {
// SysCall::yield();
//}
// Initialize SdFat or print a detailed error message and halt
// Use half speed like the native library.
// Change to SPI_FULL_SPEED for more performance.
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
sd.initErrorHalt();
}
// open the file for write at end like the "Native SD library"
if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt("opening test.txt for write failed");
}
// if the file opened okay, write to it:
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
myFile.printf("fileSize: %d\n", myFile.fileSize());
// close the file:
myFile.close();
Serial.println("done.");
// re-open the file for reading:
if (!myFile.open("test.txt", O_READ)) {
sd.errorHalt("opening test.txt for read failed");
}
Serial.println("test.txt content:");
// read from the file until there's nothing else in it:
int data;
while ((data = myFile.read()) >= 0) {
Serial.write(data);
}
// close the file:
myFile.close();
}
void loop() {
// nothing happens after setup
}