Pages: [1]   Go Down
Author Topic: Ethernet and SD in the same sketch  (Read 509 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

This is my problem :
During the setup, i read info from a SD card. After That, i don't need the SD card anymore. I also begin listening on the network using the UDP class.

When doing that, i'm missing a lot of network packets. The system is built to receive 60 packets per second (or more) and i miss about 30 packets per second (there is an id in each packet to know if a packet has been missed)... If i comment the "SD.begin(4)", i don't lose any network packet anymore...but i can't read the info from the SD card...

Can you explain me why and how to fix that?

Board used : Arduino Ethernet R3

Thanks a lot!

Edit : i tried with network packets of 1 byte and it works, but with packets of 10 bytes it doesn't work :

Example :
Quote
#include <SPI.h>        
#include <Ethernet.h>
#include <SD.h>
#include <EthernetUdp.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 3);
EthernetUDP Udp;

void setup(){
  //SD.begin(4);
  Ethernet.begin(mac, ip);
  Udp.begin(8002);
}

void loop()  {
  if(Udp.parsePacket()==10){
    analogWrite(9,Udp.read());  
     Udp.read();
     Udp.read();
     Udp.read();
     Udp.read();
     Udp.read();
     Udp.read();
     Udp.read();
     Udp.read();
     Udp.read();
  }  
}

edit 2 : in fact, by changing the value send by my computer, the led changes with 4 to 5 seconds delay...and withouth the SD.begin, the led changes instantly.
« Last Edit: May 21, 2013, 03:10:50 pm by smiletech » Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What hardware are you using - is the SD on the Ethernet card, or separate? Are they both using SPI? You might need to turn off the chip select pin for the SD to stop it getting involved in SPI transfers, but I can't guess what pin that is.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your answer PeterH!

I use the microSD on the Ethernet card, so ethernet and SD reader both use SPI. The chipselect pin for ethernet is pin 10 and the chipselectpin for SD is pin 4.

When i disable SD.Begin, pin 4 is at 0V (mesured with voltmeter) and when i enable it, pin 4 is also at 0V.

I tried to add "digitalwrite(4,HIGH)" before my ethernet.begin() to disable the SD reader but it doesn't solve the problem... (the pin 4 is then at 5V)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still investigating...I tried With the Arduino 1.0.5 IDE but without success...
Logged

UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I've just came across the same issue. After wondering if the problem was with the ethernet library I found through Zoomkat reply that I needed to remove the SD card (left in from previous test).

Have you found a solution for this problem?
Logged

UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

this worked for me:
http://forum.arduino.cc/index.php?topic=168374.msg1253159#msg1253159

Code:
void setup() {
  Serial.begin(9600);

  // disable SD SPI
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);

  // now do the rest of your setup stuff.
}

thanks to SurferTim.
Logged

Pages: [1]   Go Up
Jump to: