Pages: [1]   Go Down
Author Topic: Arduino mega 2560 + ENC28J60 Ethernet Shield + Sd Card Shield  (Read 2596 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone.
I begin my project for a little home automation.
I want to read a room temp , a motion sensor and to on/off the light.
I made the code for this and works great with this shield ENC28J60 Ethernet LAN / Network Module
ebay.com/itm/NEW-ENC28J60-Ethernet-LAN-Network-Module-For-51-AVR-STM32-LPC-/140717532321?pt=LH_DefaultDomain_0&hash=item20c36b24a1
I use the thiseldo-EtherShield-3793b4c library.

Now i connect the sd card shield
ebay.com/itm/SD-Card-Module-Slot-Socket-Reader-For-Arduino-ARM-MCU-NEW-/140717254516?pt=LH_DefaultDomain_0&hash=item20c366e774
on the arduino at the same pins like enc28j60 shield :
CS 53
MOSI 51
MISO 50
SCK 52

If you see in the image of sd card shield it has a double pins and one part i use to likn the sd card shield to the arduino pins and other part for link the enc shield to sd card shield.

I tested in this configuration the ethernet code and sd code but not in the same code , only one by one and they works separatly.
When i combined code , doesn't work.

So please tell me if i cand use the same pin 53 for many shields, or if i must do something in my code.
I want to load an image from sd card to use it like a backgroun on my web page and open a file where to write all operation who was made on my web page.
This is my code (a part of it for initialisation)

#include <etherShield.h>
#include <SdFat.h>
sdFat sd;
SdFile file;
#define error(s) sd.errorHalt_P(PSTR(s))
static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};   //Mac address
static uint8_t ip[4] = {192, 168, 1, 15};                       //IP address
static uint16_t port = 80;                                      //port 80
ETHER28J60 e;

void setup()
{
  Serial.begin(9600);
  
  //initializare ethernet
  e.setup(mac, ip, port);
  
  //initializare sd card
  if (!sd.init(SPI_HALF_SPEED)) sd.initErrorHalt();
  char name[] = "WRITE00.TXT";
  if (file.open(name, O_CREAT | O_EXCL | O_WRITE)) break;
  if (!file.isOpen()) error ("file.create");
}  

void loop
{
void loop()

  char* params;
 
  if (params = e.serviceRequest())
  {       
    e.print("<center><p><h1>TAO13 HOME SYSTEM PAGE </h1></p> ");
    e.print("<body background=\"image2.gif\">"); \\where image2.gif found on my sd card
    e.print("<META HTTP-EQUIV='refresh' CONTENT='2; /'>");
    e.respond();
   }
}

Many thanks everyone.


« Last Edit: September 18, 2012, 03:21:43 am by tao13 » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46215
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So please tell me if i cand use the same pin 53 for many shields
No, you can not. Each SPI device needs a separate chip/slave select pin. Usually, pin 4 is the SD card select pin.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.
Thanks for your ansewer and help.
I'm a begginer and i don't know many thing about electronics.
So i understand if i have many items who works on spi i must use one pin for one item ?
For my case i must use pin 53 for ethernet and pin 4 for sd card? So i must modify the library for sd or something else?
Thanks again to all.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46215
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So i must modify the library for sd or something else?
That depends. I can't see the purpose of having more than one SD reader, for instance. Not that it really matters, because the SD card pin is an input to the class, not hardcoded in a library.

What SPI devices are you trying to talk to? Be specific, and we can help you figure out how to make them play together.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi and thanks.
Sorry for the delay.
So i don't have many sd module.I have one module for sd (like in the link) and one enc28j60 shield (without sd module).
I don't know what can i do to work both in the same time.
I use the same pin for sd module and enc28j60.
Many thanks again.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46215
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I don't know what can i do to work both in the same time.
I use the same pin for sd module and enc28j60.
Well, you can't do that. You need separate slave select pins to select the two different slaves.
Logged

Pages: [1]   Go Up
Jump to: