SPI Ethernet W5500 and SD Card issues

I am using a W5500 ethernet Module like this one.

W5500 Ethernet Module

I have this working using Pin 10 as CS.

I now want to use a SD Card so I can write data to it and load/saves files when working with the ethernet module.

Just having the SD card module plugged into the SPI (pins 50,51,52 on Mega2560) stops the Ethernet module from working.

The sd card CS is plugged into pin 4.

I have set the following

pinMode(4, OUTPUT);
digitalWrite(4, HIGH);

I have also tried with digitalWrite(4, LOW);

I do not know much about SPI but I believe that it is designed to share ports (50,51,52) and use CS to select the device when it needs to write to it.

At this point I have no SD CARD LIBRARY or anything like that. Just the Ethernet module + library and the SD Card module (no library).

Is there something I am supposed to do to support this configuration?

I did some checking on the Ethernet library and it is hard coded to use pin 10.

Deep in the library is this code for setting up the SPI bus

inline static void initSS() { DDRB |= _BV(4); };
inline static void setSS() { PORTB &= ~_BV(4); };
inline static void resetSS() { PORTB |= _BV(4); };

PORTB refers to pins 8-13, the value 4 is bit 3 (so this equates to pin 10)

Now I am wondering if the SD Card physically is trying to use pin 10 as well?

I tried with the SD card library and it works fine. It shows files on the sd card.

So the SD Card works, the Ethernet does not when both are connected.

You have solved the trouble with the Ethernet shield : Ethernet module W5500 from AliExpress - how to use? - Networking, Protocols, and Devices - Arduino Forum. Nice !

I think you have run into the MISO trouble, because the SPI bus is not well defined. The I2C bus is better defined.

The Arduino Mega 2560 is a 5V board, and the W5500 chip and SD memory are 3.3V. Are you sure that those modules are compatible with 5V. You must be sure that they are. A SD module that is compatible with 5V often has a level converter on board.

Then there is the MISO trouble. The SPI bus uses a single MISO, that is the data from the module to the Arduino. MISO = Master In - Slave Out. When a module is not selected, it should keep its MISO floating, so another module can use it.
That is often not done. Many modules will work when only that module is connected to the Arduino board, and do not allow any other module on the SPI bus. I know, it's dirty, it's bad, it's cheap, but that's how it is with many modules.

Often pin 10 is used for chip select for Ethernet, and pin 4 for SD.
It is best to set 'SS', pin 53 as output, and set all chip selects to HIGH (HIGH is not active) before using the SPI bus.

I hope that I have explained it well. If you don't understand it, please ask.
You need this : Ethernet Shield for Arduino - W5500 Chipset : ID 2971 : $39.95 : Adafruit Industries, Unique & fun DIY electronics and kits

Koepel:
You have solved the trouble with the Ethernet shield : http://forum.arduino.cc/index.php?topic=414399.0. Nice !

I had the SD card inline when I had this problem last weekend - hence my fustration - the Ethernet worked when connected by itself, and it works for the SD card by itself.

But it is not happy when connected together. This was my issue last week.

Koepel:
I think you have run into the MISO trouble, because the SPI bus is not well defined. The I2C bus is better defined.

The Arduino Mega 2560 is a 5V board, and the W5500 chip and SD memory are 3.3V. Are you sure that those modules are compatible with 5V. You must be sure that they are. A SD module that is compatible with 5V often has a level converter on board.

Then there is the MISO trouble. The SPI bus uses a single MISO, that is the data from the module to the Arduino. MISO = Master In - Slave Out. When a module is not selected, it should keep its MISO floating, so another module can use it.
That is often not done. Many modules will work when only that module is connected to the Arduino board, and do not allow any other module on the SPI bus. I know, it's dirty, it's bad, it's cheap, but that's how it is with many modules.

Often pin 10 is used for chip select for Ethernet, and pin 4 for SD.
It is best to set 'SS', pin 53 as output, and set all chip selects to HIGH (HIGH is not active) before using the SPI bus.

The ethernet is a 5v module, and the sd card is a 5v module as well.

The SD card came from Ebay - see here EBAY

The SD module was only $1 AUS and the Ethernet was about 6 USD - quite a lot different than the adafruit at $33 USD or about $55 NZD

I have set pin 53 as an output, and I have set all Chip Selects to High.

I read an interesting article on Hackaday
about using a Pull Up resister on the CS lines - but this ended up making nothing work for me at all.

So at this time I am still a bit lost - could the SPI bus speed be an issue?

I also noticed that even having the SD library code in the skectch without the SD module connected stopped the Ethernet module from working.

Do you know if the MISO lines from the Ethernet and SD module can be tied together ?
Can you get schematics of both modules ?
I think the W5500 is 5V tolerant, and its MISO line is high impedance when the chip is not selected. That is good, but it is a 3.3V MISO line.
The datasheet can be found here : http://www.wiznet.co.kr/product-item/w5500/

The normal SPI speed can't be a problem. I still have a W5100 and it works at higher SPI speeds as well.

I don't understand that the Ethernet module stopped working when the SD library code is used. That is very weird. Perhaps something else is going on. Or it was a call to the SD library that stopped the Ethernet.

Instead of the pullup resistors as mentioned at Hackaday, you can make the chip-selects high in software.

Can you show your sketch ?

The W5500 Ethernet Shield from Adafruit is made by seeedstudio, and they give a schematic. That schematic shows that both the MISO lines from W5500 and SD card are floating when the chip select did not select it.

Everyone can buy cheap electronics and get into trouble. That is easy. Your goal is to make something that works.

Hi all

Sorry for the lack of a reply - I put the project away as it was on the dining room table and only manged to use the table again tonight.

I found that there is a SDFAT library and it has a Software SPI capability.

In my case it worked so I will use this option - not as good as a hardware solution but a solution is just that - a solution.

Thanks for your time in replying to my issue.

cheers

Chris