Arduinio sd on Ethernet shield not working at all

落花浮王杯 提交于 2019-12-06 05:28:17
dragonfly

Check here:

https://electronics.stackexchange.com/questions/67212/how-to-avoid-sd-card-and-w1500-spi-mixup-on-the-ethernet-shield/93868#93868

short overview of the answer from the link above:

#define SS_SD_CARD 4 #define SS_ETHERNET 10

digitalWrite(SS_SD_CARD, HIGH); // SD Card not active
digitalWrite(SS_ETHERNET, HIGH); // Ethernet not active

digitalWrite(SS_SD_CARD, LOW); // SD Card ACTIVE

//do SD-Card stuff here

digitalWrite(SS_SD_CARD, HIGH); // SD Card not active

digitalWrite(SS_ETHERNET, LOW); // Ethernet ACTIVE

//do Ethernet stuff here

if you have a Arduino Ethernet / SD Shield with the Wiznet 5100 Chip on it, you have exactly that known W5100 bug - as my Shield has. There are more informations about that bug by googling it.

When you connect this shield with the arduino the ethernet function is active and will not work if a sd-card is inserted in the slot. By using one of the Ethernet Examples from the standard library you will always get a DHCP failure (Failed to configure Ethernet using DHCP). By removing the SD-Card and restarting arduino (reset) it will work.

When you have to use both functions as I like to do you will have to struggle within the code in order to turn ethernet off and sd on and vice versa.

pinMode(4, OUTPUT);

or to be correct

pinMode(chipSelect,OUTPUT);

Add this in the setting pin 10. hope this helps.

Some times in life it is the little things that mess us up.

Put the following line of code after you set the pin 10 to output:

digitalWrite(10, High);

This should do the trick.

FYI for anyone experiencing similar issues, i.e. using the Ethernet shield SD card and essentially the Arduino website SD card sample code and having inexplicable issues initializing the SD card. The above solution allowed the initialization for me.

Harry Singh

I ran your code and fixed it by initializing SD.begin() before the line Serial.print("\n Initializing SD card...");

Something like this:

SD.begin();
Serial.print("\nInitializing SD card..."); 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!