Can anyone advise me if there are known incompatabilities with the SD library. I am using an EtherTen with built in Micro SD reader. All of the standard examples in the 0022 version of the IDE work corrently. When I transplant the code into my test app, it suddenly hangs on the SD.begin(4) line and does not return.
If I remove the 2G memory card and restart it correctly indicates a failure and continues on. Pin 10 is defined as an output, but as per the examples nothing has been written to pin 10 by the app. I do have quite a few includes but they are pretty much standard. I have used them previously in differing combinations but this is my first time with the SD card library. The memory card is readable on my laptop and the files from the test apps are present.
One thought may be relating the the fact the SD card is not in a shield but built in to the EtherTen board.
Thanks in advance for your assistance
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Udp.h>
#include <avr/pgmspace.h>
#include <string.h>
#include <OneWire.h>
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
#include <EEPROM.h>
#include "im.h"
#include "EEPROMAnything.h"
...
boolean mySd_card;
...
File myFile;
...
setup()
{
.....
/* Initialise the SD memory card. */
Serial.println("Initializing SD card...");
mySd_card = false;
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("Memory card failed!");
}
else
{
Serial.println("Memory card OK ...");
Serial.println("Verifying default.txt file");
myFile = SD.open("default.txt", FILE_READ);
if(myFile)
{
mySd_card = true;
Serial.println("default.txt was found");
}
else
{
Serial.println("default.txt is missing");
}
}
....
}
We can't tell what code you cut out, but, both the ethernet and SD card access is through SPI. Only one SPI device (ethernet or SD card) can be active at once. You need to make sure you set pins 4 and 10 correctly (one HIGH, the other LOW) before each attempt to access each device (and that includes calling begin() for the device).
PaulS, thanks for your help. It sort of makes sense, though I would have hoped that a limitiation like this was more visible when you purchased a freetronics EtherTen board. Is there a specific value for pins 4 & 10 for the Ethernet and another for the SD reader ?, the SD example app just says to set pin 10 as an output and not what state to drive it.
From the schematic it looks like:D10 = Lo to Enable Ethernet, D4 Hi to enable SD card right and don't enable both at the same time, is that about right then ?
I was hoping to read from the SD card and write straight to the Ethernet but it looks like I will have to buffer the data now.
though I would have hoped that a limitiation like this was more visible when you purchased a freetronics EtherTen board.
It's how the SPI bus works. I wouldn't expect different hardware to address software requirements.
From the schematic it looks like:D10 = Lo to Enable Ethernet, D4 Hi to enable SD card right and don't enable both at the same time, is that about right then ?
Set D10 to LOW AND D4 to HIGH for ethernet, and set D10 to HIGH AND D4 to LOW for SD card.
I was hoping to read from the SD card and write straight to the Ethernet but it looks like I will have to buffer the data now.
Write a function that reads some data from the SD card (a line, for instance). In that function, set D10 and D4 appropriately, and perform the read and stores the data.
Write a function that writes to the client/server. In that function, set D10 and D4 appropriately, and perform the write.