I have an Arduino Zero processor (atsamd21g18a) with a microSD shield connected (check images of schematics)
The point is that I cant make it to work, not with sd.h sketch and not with sdfat.h sketch.
Chip-select for the SD card is A3 or digital pin 17.
sd.h sketch
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
// Open serial communications and wait for port to open:
SerialUSB.begin(9600);
delay(1000);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
SerialUSB.print("Initializing SD card...");
if (!SD.begin(A3)) {
SerialUSB.println("initialization failed!");
return;
}
SerialUSB.println("initialization done.");
if (SD.exists("example.txt")) {
SerialUSB.println("example.txt exists.");
} else {
SerialUSB.println("example.txt doesn't exist.");
}
// open a new file and immediately close it:
SerialUSB.println("Creating example.txt...");
myFile = SD.open("example.txt", FILE_WRITE);
myFile.close();
// Check to see if the file exists:
if (SD.exists("example.txt")) {
SerialUSB.println("example.txt exists.");
} else {
SerialUSB.println("example.txt doesn't exist.");
}
// delete the file:
SerialUSB.println("Removing example.txt...");
//SD.remove("example.txt");
if (SD.exists("example.txt")) {
SerialUSB.println("example.txt exists.");
} else {
SerialUSB.println("example.txt doesn't exist.");
}
}
void loop() {
// nothing happens after setup finishes.
}
sdfat.h code
const int chipSelect = A3;
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
updated 2 Dec 2010
by Tom Igoe
modified by Bill Greiman 11 Apr 2011
This example code is in the public domain.
*/
#include <SdFat.h>
SdFat sd;
SdFile myFile;
pinMode(chipSelect, OUTPUT);
void setup() {
delay(5000);
SerialUSB.begin(9600);
SerialUSB.println("Serial start");
//while (!SerialUSB) {} // wait for Leonardo
//SerialUSB.println("Type any character to start");
//while (SerialUSB.read() <= 0) {}
delay(1000); // catch Due reset problem
// 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:
SerialUSB.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
SerialUSB.println("done.");
// re-open the file for reading:
if (!myFile.open("test.txt", O_READ)) {
sd.errorHalt("opening test.txt for read failed");
}
SerialUSB.println("test.txt:");
// read from the file until there's nothing else in it:
int data;
while ((data = myFile.read()) >= 0) SerialUSB.write(data);
// close the file:
myFile.close();
}
void loop() {
// nothing happens after setup
SerialUSB.println("loop done.");
}
I am not sure if it is a hardware or software issue, but soldering and tracks are good.
Its like the hardware gets frozen, so I cant really see the serial messages. I know its not a serial issue because I can make a simple print serial script and it shows up. I think it might be related with libraries, or maybe some hardware limitation?
Can I use any pin as Chipselect? is digitalpin17 / A3 right?
