How SPI works with SD Card with Leonardo

I've used the Ethernet shield with a few Arduino projects, but I've never used the SD card. I'm looking at a project where I want to use a Leonardo with Ethernet connection and the SD card. I've been doing some reading and I want to make sure I understand how this works.

If I was using an UNO instead of Leonardo, I would need to use digital pins 11, 12 & 13 for SPI communication. Pin 10 and pin 4 would be reserved for CS for the Ethernet and SD Card respectively.

But the Leonardo his separate SPI pins, it doesn't use digital pins 4, 10, 11,12, 13 to communicate with the Ethernet shield and SD card.

So, to use both the Ethernet and SD card with a Leonardo, do I need to do anything special? I read on this forum that to enable software SPI, I need to change #define LEONARDO_SOFT_SPI 1 in SdFatConfig.h. I'd appreciate any tips and best practices for this configuration.

So, to use both the Ethernet and SD card with a Leonardo, do I need to do anything special?

As long as the Ethernet shield has the ICSP (6 pin) connector on the bottom, no.

I read on this forum that to enable software SPI, I need to change #define LEONARDO_SOFT_SPI 1 in SdFatConfig.h

So? Why do you think you need to use software SPI when there is a perfectly good hardware SPI available?

PaulS:

I read on this forum that to enable software SPI, I need to change #define LEONARDO_SOFT_SPI 1 in SdFatConfig.h

So? Why do you think you need to use software SPI when there is a perfectly good hardware SPI available?

I want to free up some I/O pins so I can use them for sensor inputs.

I want to free up some I/O pins so I can use them for sensor inputs.

How is software SPI going to accomplish that?

PaulS:

I want to free up some I/O pins so I can use them for sensor inputs.

How is software SPI going to accomplish that?

I assumed that using software SPI would free up pins 4,10,11,12 & 13. But based on your questions, I'm starting to think these pins are freed up anyway and being able to use them for my sensors isn't linked to hardware/sofware SPI setting. is that the case?

is that the case?

The way I read it, hardware SPI does not use pins 11, 12, and 13 on the Leonardo. Pins 4 and 10, the slave select pins, are still used. Software SPI would tie up several pins, though not necessarily 11, 12, and 13.

I'm not convinced that software SPI is suitable for the Ethernet shield, since it is hardwired to the SPI pins.

PaulS:

is that the case?

The way I read it, hardware SPI does not use pins 11, 12, and 13 on the Leonardo. Pins 4 and 10, the slave select pins, are still used. Software SPI would tie up several pins, though not necessarily 11, 12, and 13.

I'm not convinced that software SPI is suitable for the Ethernet shield, since it is hardwired to the SPI pins.

Okay, I get it now. I'm glad you told me I still need to reserve pins 10 and 4 the CS.

I can confirm that Leonardo has dedicated SPI pins in the 6 pin header at the bottom or the board. When using these as SPI master or slave you can use any other digital pin as SS. If you need both master and slave you will have to use another set of pins, e.g. as a software SPI master. I am in the process of finding out how to configure SPI libraries to get these two modes to coexist.