Using the old Ethernet Board + SD with IDE 0019

Hi Everyone, I can't find anyone discussing this on the forum, so i thought i would ask. I have a Duemilanove and a old Ethernet Shield, plus another shield with a SD card connection. I was just about to connect the two together with IDE 0018 to try to make them talk, plus following this note on the playground http://www.arduino.cc/playground/Main/EthernetShieldSDHardwareSPIMod I was wondering what are the changes to 0019 and the new Ethernet board, and can i adapt my old sheild to get the ethernet and SD working together using the 0019 IDE?

Thanks

Pete

There is a bug on the Wiznet Ethernet Controller chip that causes an unmodified old version of the Ethernet Shield to interfere with other SPI devices.

On the Wiznet site http://www.wiznet.co.kr/en/, there is an errata sheet and an application note that shows a way to work around that bug . You can refer to the schematic of the latest Ethernet shield to see how it is done on the new version.

For the old version of the Ethernet Shield. you don't have to change anything in the arduino Ethernet library (or anything else) if you do the following mod on the Ethernet Shield.

Connect the input of a logic inverter to the SPI "SS" signal coming into the Ethernet Shield. Connect the output of the inverter to the "SEN" pin on the '5100. (That's pad number 2 of the "Prog" pads).

Now, when the Ethernet SPI interface is not selected ("SS" is high), the SEN signal on the '5100 is pulled low. This keeps the '5100 from corrupting data on the MISO pin back to the Arduino.

A single section of a CD4049 or a 74HC4049 hex inverter will do the trick. At least, it does for me. With a little hot-melt glue, a $0.15 chip and some 30-gauge insulated wire, the SPI now works as it should.

Note that I connected the power and ground of the hex inverter chip to Arduino +3.3 Volts (not +5 volts) and GND signals, respectively, and I connected the five unused inverter inputs to GND because you shouldn't leave CMOS inputs floating.

Anyhow...

With this modification on the Ethernet Shield, I can use other SPI devices.

I use the SdFat library for SD card accesses. In the setup() function that uses SdFat, you put something like:

  void setup()
{
  //  whatever other setup stuff you need
  pinMode(SS_PIN, OUTPUT); //This is redundant, since it's in the library Sd2Card
  digitalWrite(SS_PIN, HIGH); // This keeps the modified Ethernet shield from interfering with SPI
}

Then, to initialize the SD card you have something like the following (a slight modification from the SdFatInfo example)

//const int SD_ChipSelect = 10; // For unmodified data logger shield
const int SD_ChipSelect = 9; // For modified data logger shield
void loop() {
  PgmPrintln("\ntype any character to start");
  while (!Serial.available())
    ;

  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  //uint8_t r = card.init(SPI_HALF_SPEED, SD_ChipSelect);
  uint8_t r = card.init(SPI_FULL_SPEED, SD_ChipSelect);
  if (!r) {
    PgmPrintln("\ncard.init failed");
    lcd.print("card.init failed");
    sdError();
    return;
  }
.
.
.

If you use an unmodified Data Logger Shield, you can't have the Ethernet Shield plugged in at the same time.

If you use something like the adafruit MicroSD breakout board you can wire the SD Chip select to any digital output pin that you want. It works very well with me along with my modified Ethernet Shield, using pin 9 for the SD Chip select.

If you use the adafruit Data Logger Shield, you will have to modify it, since it uses pin 10 for the SD chip select. I just made a tiny cut in the trace from the pin 10 position on the Data Logger shield header and connected a piece of 30 gauge insulated wire from the pin 9 position to the "CS CARD" pad on the Shield.

If you use some other SD card interface, you may find that the SD Chip select is selectable by some jumper or other mechanism that doesn't require cut/jump modifications to your SD shield.

I have used 8 GByte SDHC and MicroSDHC cards with my old (modified) Ethernet Shields and homebrew SD interface cards as well as the adafruit cards that I mention above

Bottom line: No software mods required on arduino-0019 (and later) installations. Works marvelously well with the SdFat library and SDHC cards formatted as FAT32---that's the way they come out of the package, and I don't see the need to reformat them. (Well, I get a couple hundred kBytes/sec transfer rate, and I think that's about all I would expect.)

Regards,

Dave

Footnote: If you are actually using the Ethernet shield, you don't have to put the "digitalWrite(SS_PIN, HIGH);" in your setup(), since the Ethernet library takes care of SS_PIN values.

On the other hand...

If you are just testing the SD card with the Ethernet card attached and you don't actually do any Ethernet initialization stuff, you should make sure that the SS_PIN is in the HIGH state.

Anyhow...

It doesn't hurt to make sure that it's high, and the SdFat library initialization stuff doesn't do it for you. (In fact, I actually modified Sd2Card.cpp to do this, but I like to advise people to start out with unmodified libraries until they confirm that it can work.)

Wow thanks for the reply Dave! Very Very Helpful! I will see what i can find over the weekend and I'll give it a go!

You seem to be an expert with the old ethernet stuff, so one additional question if i may? What i'd really like to do is to use the SD card to hold web site info, ie html,css and js scripts, so the internal memory is free and stand alone, (Not replying on other websites to be live to be able to get code to work). have you ever done this, or do you know of any examples?

Thanks

Pete

With the SdFat library you can create directories and files on the SD card. You can write to the files and read from the files with functions defined in the classes of the SdFat library. You can not make the SD memory act like "normal" ATmega RAM.

That is, you can't simply declare a variable or array (in your Arduino sketch) that resides in the SD memory and then access it with usual Arduino (C++) assignment statements.

Regards,

Dave

Hi Dave, I understand that, but technically i should be able to put files onto the SD card and tell the code to read them and output them on port 80. So i could write a html file, put it onto the sd card, and tell the arduino to read it and push it to port 80 when requested. Thus giving me a 8-bit web server with at the moment 2GB memory! Better than my actual web server domain! :P

I would also like to be able to do this for javascript files as well to get some ajax working.

I was just wondering if i had the correct idea and seeing if you know of any examples on the web of someone doing this, for pointers.

Thanks

Pete

No direct experience, but the example at Ovidiu Predescu's Weblog looks like it might be right down your alley.

Ovidu's fix for the SPI problem doesn't require you to sky-wire an inverter IC onto the Ethernet Shield, but that method costs an I/O pin and requires a slight modification to the library. Lots of people prefer that to my (somewhat messier) hardware-only fix. Chacun à son goût!

Regards,

Dave

Yes it does!!!!! Thanks Dave!

Hi Dave, Hoping you can help, still having some fun and games trying to get the two sheilds to work together. On there own, they work fine, On top of each other they just refuse to let the SD card initalise. Any ideas?

I've done your suggested HW mod, i've noticed 2 things. 1. The I/O pin from the Ardunio is at 5V and the inverter chip is connected to 3.3V is that going to cause any issues. 2. To prove that it should work, if i was to ground pin 2 of the prog jump on the ethernet sheild, should the SPI bus be fully free'd up???

So if i did that and the SD card then initialised i'd know it was something to do with the ethernet sheild.

I'm using both the ethernet and SD card in the same script so i'm not doing the additional code changes as you suggested, as the ethernet library should do that, right??

And as the same code works when the boards are on independatly i dont THINK that there should be any issues with enable pins etc.

Any help or advice you can give me would be very helpful!

Pete