What pins can I use as SS Pins for SD-Card

I am using a shield which uses Pin 10 as SS Pin. However I also want to hook up an SD Card. What other Pins can I use as SS Pin on:

a) an arduino uno

b) an arduino DUE

PS: I presume all I have to do to change SS is to use the "SD.begin(chipSelect)" Funktion?

On a Uno and other '328P based boards, D10 is SS associated with SPI, must be set to OUTPUT for the '328P to be SPI Master (even if not used for the SS function). D0-D9 and D14-D19 then can be used for the SS function.

On a Mega, SS is D53.
On a '1284P, SS varies by board type - with Bobuino it is D10.

I don't know about Due, I have not used the board at all.

Thanks!

So let me just check if I got this right:

  • If i use only one SPI device I do not have to configure pin 10 as an output. (At least I have never done it before and it has worked, I just used "SD.begin(chipSelect)")

  • If I use another SPI device, I have to set pin 10 to "Output".
    Meaning the lines I would have to add would be:

pinMode(10, OUTPUT);
SD.begin(10);
SecondSpiDevice.begin(any Pin);

Anyone? :o

The SD library sets pin 10 as output and whatever pin you gave it. If you're not using that library, then you have to do the pin 10 output yourself.

Many other libraries for SPI sensors or whatever will do the same. That's probably why you haven't seen this before.

Literally any pin except the SPI bus pins can be used as the CS pin for SPI devices. Even analog pins can be used as digital outputs.

If pin10 is an input and it goes low, then the SPI subsystem drops into slave mode. Usually you don't want that.

b)

The Due only allows a fixed set of pins as SPI CS (chip select, not slave select as you say),
10, 4 and 52 (being NPCS0/1/2) The NPCS3 signal is not routed to one of the Due header pins I believe.
SPI cannot work unless using one of these pins. You can toggle other pins too around the SPI calls,
but you have to use one of these hardware pins.

The SD library sets pin 10 as output and whatever pin you gave it. If you're not using that library, then you have to do the pin 10 output yourself.

Many other libraries for SPI sensors or whatever will do the same. That's probably why you haven't seen this before.

So does that mean I don't have to care about any of the details and just say: SD.begin(X); Where X would be any Pin I like?

Look at the code - you have the source. On the Due it definitely matters.

Note that even on the Uno pin 10 has to be set as an OUTPUT to use the SPI hardware (if you
try to switch it back in an INPUT then the SPI hardware drops out)