Go Down

Topic: Wireless SD Shield - initialize SD card with switch on 'micro' (Read 1 time) previous topic - next topic

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.



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:

Code: [Select]

#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()
  delay(2000);  // let shields initialize


  // 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
    //Serial.println("Initializing SD...");
    FC.InitializeSD(2, TimeInfo);
  DataFilename = "Pyr" + String(TimeInfo[5]) + "-" + String(TimeInfo[4]) + ".txt";
  LogFilename = "Log" + String(TimeInfo[5]) + "-" + String(TimeInfo[4]) + ".txt";


Here is the init procedure in FileControl.cpp

Code: [Select]

boolean FileControl::InitSD(int TimeInfo[7])
  bool DFresult = false;
  SD.begin(4); // init SD card
  File okfile = SD.open("okfile.txt", FILE_WRITE);
  boolean CardOk = (boolean)okfile;
  // write start time
  okfile.print("Started at:  ");
  // check if file exists, if not create one with a header
     File DataFile = SD.open("PyrData.txt", FILE_WRITE);
     DataFile.println("Timestamp,millis,1084176782, 1084176774, 1084176750, 1084176731, 1084176749, 1084176970, 1084176956, 1084177011");
  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:




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. 

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131