Hi all,
Just a question in regards to using software SPI on the mega with a sparkfun SD shield.. I have some code that worked with the deumi to get analogreads and store to sd card at 2.5kHz+. Just wanted to use the same shield with the mega as it provides more analog ins and ISR enabled digital pins.
Used the latest version of the Sdfat library with the removal of the // before #define MEGA_SOFT_SPI and setting it nonzero (in SdfatConfig.h) so it looks like this:
#define MEGA_SOFT_SPI 1
and ran following:
//Add the SdFat Libraries
#include <SdFat.h>
#include <SdFatUtil.h>
#include <ctype.h>
//Define Pins
int pot1Pin = 8;
int pot2Pin = 9;
int start;
long n = 0;
//Create the variables to be used by SdFat Library
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
char name[] = "log.csv"; //Array that contains name of file.
char contents[32]; //Data buffer for writing contents to the file.
#define FASTADC 1
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
void setup()
{
pinMode(8, OUTPUT); //Pin 8 must be set as an output for the SD communication to work on sparkfun shield.
card.init(); //Initialize the SD card and configure the I/O pins.
volume.init(card); //Initialize a volume on the SD card.
root.openRoot(volume); //Open the root directory in the volume.
#if FASTADC
// set prescale to 16
sbi(ADCSRA,ADPS2) ;
cbi(ADCSRA,ADPS1) ;
cbi(ADCSRA,ADPS0) ;
#endif
//Create header
file.open(root, name, O_CREAT | O_APPEND | O_WRITE); //Open or create the file 'name' in 'root' for writing to the end of the file.
sprintf(contents, ", , \nPOT1, POT2");
file.println(contents); //Write the 'contents' array to the end of the file.
start = millis();
while (millis()-start <= 1000){
n++;
sprintf(contents, "%i, %i", analogRead(pot1Pin), analogRead(pot2Pin));;
file.println(contents);
}
file.println(n);
file.close();
}
void loop(){
}
Tried the above as well as changing pin 10 to output (rather than pin8) and pin 53 as well just in case and still no file being written at all.