I am confused with the documentation I need spi5. I have a pmodsd card reader attached to cs 10 then mosi pin 11 miso pin 12 and sclk pin 13 which I believed means i need to use spi1 which is spi5 but the picture says use spi1 and the text the please note says spi is spi1 and spi1 is spi5 and i dont know how to write data to my sdcard. i’ve connected it to my unor4 and that works fine but i need the power of the giga. I saw and tried to amend the code given in this thread. Help would be much appreciated.
To be more clear, it means you must use the SPI1 object defined by the Arduino "SPI" library. But yes, that is correct.
I think it will be easiest to use the "SdFat" library. You can install it using the Arduino IDE Library Manager. After installing it, you will find an array of example sketches that demonstrate the usage of the library under the File > Examples > SdFat menu in Arduino IDE.
Yes. Your code does communication via the SPI bus at a low level. The "SdFat" library provides a higher level interface that abstracts the complex SPI communication that is required to work with an SD card.
Here is a simple sketch you can use to verify that the communication is working between the GIGA R1 WiFi and the SD card:
#include <SdFat.h>
SdFat sd;
void setup() {
Serial.begin(9600);
while (!Serial) {} // Wait for the serial port to be opened.
if (!sd.begin(SdSpiConfig(10, SHARED_SPI, SD_SCK_MHZ(4), &SPI1))) {
Serial.println("SD initialization failed");
while(true) {} // Do not continue.
}
Serial.println("Files found (date time size name):");
sd.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop() {}