Wireless SD Shield - initialize SD card with switch on 'micro'

Hello, has anyone gotten the SD card to initialize with the switch set to 'micro'? I have a mega 2560 with the wireless SD shield, xbee works fine, sd writing works fine, however the SD card will only initialize when the switch is set to 'usb'. I need this unit to be able to start in the field, with no on around to switch it to 'micro' after the SD car initializes.

Thanks

They are both SPI MODE0 devices with MSBFIRST, so they should be compatible. If you post your code, maybe I (or someone else) can show you how to initialize them to work together.

I have a lib that controls the card. This is the code in the setup:

#include <FileControl.h>
#include <RTC.h>
#include <XBee.h>
#include <SD.h>
#include <Wire.h>//I2C header file
#include <SoftwareSerial.h>

// Xbee 
XBee xbee = XBee();
ZBRxIoSampleResponse ioSample = ZBRxIoSampleResponse();
XBeeAddress64 xbeeID = XBeeAddress64();

int numMods = 8; // number of Modules
int Values[8]; // array to hold pyranometer data
uint32_t Names[8] = {1084176782, 1084176774, 1084176750, 1084176731, 1084176749, 1084176970, 1084176956, 1084177011}; // array to hold Xbee serial numbers

int uploadDay = 4;
int delayTime = 0;  // used to calculate time to next iteration
long now = 0;
int startHr = 5;
int endHr = 20;
unsigned long sendDuration = 1800000;

unsigned long cupReads = 0;
unsigned int cupPeak = 0;
unsigned int cup = 0;
float cupms = 0;
int cupPin = 15;

int TimeInfo[7];

RTC rtc;
FileControl FC;

String Data = "";
int reads = 0;

String LogFilename = "";
String DataFilename = "";

void setup() 
{   
  analogReference(INTERNAL2V56);
  delay(2000);  // let shields initialize
 
//Serial.begin(19200);
//Serial.println("Starting...");  

  // uncomment to set the time on the RTC
//  TimeInfo[0] = 15; // seconds
//  TimeInfo[1] = 25; // minutes
//  TimeInfo[2] = 9; // 24 hour
//  TimeInfo[3] = 4; // 0-6 -> sun-sat
//  TimeInfo[4] = 13; // day
//  TimeInfo[5] = 6; // month
//  TimeInfo[6] = 13; // year
//  rtc.SetTime(TimeInfo);
  
  //xbee.begin(9600);  // initialize Xbee
  
  while(!FC.IsInitialized())
  {
    //Serial.println("Initializing SD...");
    rtc.GetTime(TimeInfo);
    FC.InitializeSD(2, TimeInfo);
  }
  
  rtc.GetTime(TimeInfo);
  DataFilename = "Pyr" + String(TimeInfo[5]) + "-" + String(TimeInfo[4]) + ".txt";
  LogFilename = "Log" + String(TimeInfo[5]) + "-" + String(TimeInfo[4]) + ".txt";

//Serial.println("Starting..."); 
}

Here is the init procedure in FileControl.cpp

boolean FileControl::InitSD(int TimeInfo[7])
{
  bool DFresult = false;
  SD.begin(4); // init SD card
  
  delay(2000);
  
  File okfile = SD.open("okfile.txt", FILE_WRITE);
  boolean CardOk = (boolean)okfile;
  
  // write start time
  
  okfile.print("Started at:  ");
  okfile.print(TimeInfo[5]);
  okfile.print("/");
  okfile.print(TimeInfo[4]);
  okfile.print("/");
  okfile.print(TimeInfo[6]);
  okfile.print("-");
  okfile.print(TimeInfo[2]);
  okfile.print(":");
  okfile.print(TimeInfo[1]);
  okfile.print(":");
  okfile.println(TimeInfo[0]);
  okfile.close();
  
  // check if file exists, if not create one with a header
  if(!SD.exists("PyrData.txt"))
  {
     File DataFile = SD.open("PyrData.txt", FILE_WRITE);
     DataFile.println("Timestamp,millis,1084176782, 1084176774, 1084176750, 1084176731, 1084176749, 1084176970, 1084176956, 1084177011");
     DataFile.close();
  } 
  
  return CardOk;
}

It will only initialize the card when the shield is set to usb, after that I can switch it to micro and communicate with the xbees and write the data.

Thanks for your help.

My bad. I thought you were talking about the Arduino wifi shield, not an XBee shield. And you mentioned nothing of the RTC device. A link to all your hardware might help.

The RTC is just a small clock that runs off the SDA/SCL pins with the wire lib...

I've had this problem since the beginning of the project, adding the clock didn't change anything. I haven't connected anything to pin 53 (SS pin), and don't know if it will help initialization.

And the other devices involved:

http://www.jayconsystems.com/xbee-pro-s2b-63mw-wire-antenna-series-2.html

Well the fix to this problem seems to be to to wire a jumper from pin 53 on the mega to the CS pin (pin 4) on the shield and use pin 53 as the CS pin in software. Unknown why switching between 'usb' and 'micro' affects the operation of pin 4 on the mega.