Hi I'm getting in twist switching between talking to the SD Card and the W5100 chip. This simple sketch is supposed to get some data from the Analog inputs and write it to a file on the card AND output it to a web client. I thought that the libary functions were supposed to handle the CS/SS lines but I cant get the thing to work. I've even thrown in some 'digitalWrite(ChipSelectPin,HIGH); or LOW lines to force the issue. But I just get Garbage scrolling across the serial screen and nothing over the intranet. Individually the two halves work. If I take out the Client.print bit then I can write to the card and visa versa send info to the client if datafile.print part is zapped.
This is really annoying as I want to be able to hold most of the web page info on the SD card as well as a datafile using unfo from the analoginputs. The final pages will be a mix of static HTML selective reads of the data and some NTP info gleaned by UDP. I've looked at the CAT on the MAT bit of Tom Igoe's 'Making Things Talk' several times but I'm dammed if I can see why my sketch doesn't behave.
Switching the SD line 'if (!SD.begin(...' to pin 10 was a deliberate act not a typo and is an indication of how frustrated Ive got with the thing!
The sketch started off with the right line 'if (!SD.begin(chipSelect)) {... but that did not work!!!
even forcing the chip selects on and off, which ought to be handled by '<Ethernet.h> and ,SD.h>.
The sketch started off with the right line 'if (!SD.begin(chipSelect)) {... but that did not work!!!
even forcing the chip selects on and off, which ought to be handled by <Ethernet.h> and <SD.h>.
Once the two interfaces are set up, the libraries do handle the SS pins. You do not need to manipulate the SS pins after both begin() functions are complete. It is up to you to avoid data collisions on the SPI bus until then.
edit: Does this work for you?
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
void setup() {
Serial.begin(9600);
// disable w5100 while setting up SD
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
Serial.print("Initializing SD card...");
if (!SD.begin(4)) Serial.println("failed");
else Serial.println("OK");
// the SD.begin(4) function returns with its SPI disabled, so nothing needs to be done
// set up w5100 with dhcp
Serial.print("Initializing ethernet...");
if(!Ethernet.begin(mac)) Serial.println("failed");
else Serial.println("ok");
// the Ethernet.begin(mac) function returns with its SPI enabled, so disable it
digitalWrite(10,HIGH);
}
void loop() {
}