Greetings,
I've designed and built a number of 328 based systems that suscessfully utilize both the SD & SDfat (depending on project) components. These systems interface the SD card directly for they are powered by 3.3V. The connections are direct between the SD card & microcontroller (ie. SS-->SS, MOSI-->MOSI, MISO-->MISO, SCK-->SCK....essentially utilizing the SPI port). These designs run flawlessly. However, recently I decided to dabble with the 32U4 processors and acquired a MattairTech breakout board. I installed the Leonardo bootloader which works remarkably well. It has served me well in my endeavors, until now. For some reason, I simply cannot get either SD (in Arduino 1.0) or SDFat (12/5/11 version compiled with Arduino 1.0) to initialize the microSD card.
I have connected the microSD card ports to the SPI port (as above) and setup the unit to be powered by a 3.3V source. The USB plug is NOT utilized for testing, but is used to load the sketch onto the unit for testing, then the VCC is sourced by a regulated 3.3V (from another board). Also the SD card is NEVER exposed to 5V for it is only inserted AFTER the wiring is switched over to 3.3V. I have a small LCD attached to the device that displays the activity of the system and persistently states the the SD intitialization fails. The same setup on a 328 based system works like a champ (even with Arduino 1.0). For reference the LCD does not link up to the SPI. Below is the code snippet that I'm using.
I simply cannot figure out why it persistently fails initialization. Any thought or suggestions?
#include <SD.h>
File myFile;
#define PIN_SCE 0 //F0
#define PIN_RESET 1 //F1
#define PIN_DC 4 //F4
#define PIN_SDIN 5 //F5
#define PIN_SCLK 6 //F6
#define LCD_C LOW
#define LCD_D HIGH
#define LCD_X 84
#define LCD_Y 48
#define LCD_CMD 0
const int LEDPin = 3; //D0
///...... bunch of LCD code
void setup(void)
{
LcdInitialise();
LcdClear();
//LcdString("Screen works");
if (!SD.begin()) {
LcdString("initialization failed!"); //<<------ This is where it fails every time with the 32U4 processor
return;
}
// re-open the file for reading:
myFile = SD.open("hello.txt");
if (myFile) {
LcdString("hello.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
LcdCharacter(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
LcdString("error opening hello.txt");
}
}
void loop(void)
{int j=0;
for (int i=0; i < 48; i++){
// just some LCD stuff here
analogWrite(LEDPin,j); /* fade the backlight */
j=j+5;
if (j>245)
{j=0;}
}
}