I would appreciate the community’s help on this odd outcome:
I made an exact copy of a program. Before making any changes to it, I tried to compile it and ended up with errors related to SDFat and ParticleSerial libraries(please see below).
I fixed the problems with the help above and here is what I found out:
Going to the older SDFat library (0.0.7) fixed the two SDFat errors reported.
The new ParticleSoftLibrary appears to compile fine. I had copied my old code which was lacking the #include statement for that library. That code compiled fine with an older firmware but not with 1.0.0.
Per your request, the code is below. I am getting with SDFat (1.0.16) the error:
fgets.ino:8:11: invalid conversion from ‘int’ to ‘SPIClass*’ [-fpermissive]
// Demo of fgets function to read lines from a file.
#include <SPI.h>
#include "SdFat.h"
#include "sdios.h"
// Secondary SPI with DMA
// SCK => D4, MISO => D3, MOSI => D2, SS => D5 (changed from D1)
SdFat sd(1);
const uint8_t chipSelect = D5; //<-------------------- Use D5
// print stream
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
// store error strings in flash memory
#define error(s) sd.errorHalt(F(s))
//------------------------------------------------------------------------------
void demoFgets() {
char line[25];
int n;
// open test file
SdFile rdfile("fgets.txt", O_RDONLY);
// check for open error
if (!rdfile.isOpen()) {
error("demoFgets");
}
cout << endl << F(
"Lines with '>' end with a '\\n' character\n"
"Lines with '#' do not end with a '\\n' character\n"
"\n");
// read lines from the file
while ((n = rdfile.fgets(line, sizeof(line))) > 0) {
if (line[n - 1] == '\n') {
cout << '>' << line;
} else {
cout << '#' << line << endl;
}
}
}
//------------------------------------------------------------------------------
void makeTestFile() {
// create or open test file
SdFile wrfile("fgets.txt", O_WRONLY | O_CREAT | O_TRUNC);
// check for open error
if (!wrfile.isOpen()) {
error("MakeTestFile");
}
// write test file
wrfile.print(F(
"Line with CRLF\r\n"
"Line with only LF\n"
"Long line that will require an extra read\n"
"\n" // empty line
"Line at EOF without NL"
));
wrfile.close();
}
//------------------------------------------------------------------------------
void setup(void) {
Serial.begin(9600);
// Wait for USB Serial
while (!Serial) {
SysCall::yield();
}
cout << F("Type any character to start\n");
while (!Serial.available()) {
SysCall::yield();
}
delay(400); // catch Due reset problem
// Initialize at the highest speed supported by the board that is
// not over 50 MHz. Try a lower speed if SPI errors occur.
if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
sd.initErrorHalt();
}
makeTestFile();
demoFgets();
cout << F("\nDone\n");
}
void loop(void) {}
If you looked at the raw error message you’d have seen this
__test.ino:7:11: error: invalid conversion from 'int' to 'SPIClass*' [-fpermissive]
In file included from __test.ino:2:0:
lib/SdFat/src/SdFat.h:319:12: note: initializing argument 1 of 'SdFat::SdFat(SPIClass*)'
explicit SdFat(SPIClass* spiPort) {
This tells you that you cannot just pass a 1 to the constructor but you need to do this
// either
SdFat sd; // for the default SPI interface
// or
SdFat sd(&SPI1); // for an alternative SPI interface
The selection of the CS pin follows in the sd.begin() call.
BTW, what did you intend to achieve with the 1 as parameter?
I will try it. But to answer your question, with version 0.0.7 of the library, SdFat sd(1) was needed to get the SD card to work. The program then compiled fine and the SD card was working.
Thank you so much for this you just solved an issue I have been fighting for 2 days. I could not figure out why I was unable to switch to SPI 1 or 2. Thank you so much.