Beginner, confused about SPI bus.

Hi everyone,

So for a project of mine, I have been given the Adafruit GPS+logger shield. I only really need the sd logging capability of this component. However, I am confused as to which pins this device is using. I looked online everywhere for an explanation but I couldn't find what I was looking for.

Could someone tell me which digital pins the data logger will be using on the arduino that I cannot use for anything else?

BTW, I have both an Uno and a Mega and I'm not sure which one I'll be using for the final product.

It's explained pretty well at:
https://www.arduino.cc/en/reference/SPI
but I'll give a short summary. The idea with SPI is that it allows communication with multiple devices sharing the SPI bus pins (MOSI, MISO, SCK). In order to control which device is communicated with you also need a dedicated pin on your Arduino for each device, CS, which is connected to the SS pin on the device. When you set the CS pin for a given device LOW it goes into slave mode. The Arduino is also on the SPI bus and has its own SS pin. Generally you don't want the Arduino going into slave mode so you need to be careful not to set its SS pin to INPUT, LOW when using SPI. For that reason it's common to use the Arduino's SS pin for a CS pin since its general use is otherwise limited but any pin can be used for CS so you will see different shields use a variety of CS pins. If you have two shields that use the same CS pin this could be a problem and you might need to connect that pin differently.

The SPI pins are found on different pins from one Arduino board to another. For this reason well designed shields that use SPI use the ICSP header, which always will have the SPI pins.

Unfortunately the theory of multiple devices sharing the bus sometimes doesn't work in practice because the usage of SPI is inconsistent. You can also do software SPI ("bit banged") on any pins.

So to answer your question of which pins it's using, check the chart found at the link above to find which pins MOSI, MISO, CLK are found on. Those pins should only be used for SPI when you are using the shield. If you check out Adafruit's information on the shield:

you'll see that the CS pin for the SD card reader is pin 10, but can be changed with some soldering. Pin 10 is also SS on the Uno so on that board there are only 4 pins you need to worry about but SS is 53 on the Mega so on that board you have to be careful of 5 pins: 10, 50, 51, 52, 53.

Thanks pert, that answer was very concise and i really appreciate it :slight_smile: .

BTW I researched a lot yesterday. For other newbies confused about the same thing, I read through the adafruit library '.h' file and found that if you use the MEGA, adafruit tells you to switch to 'Soft SPI' as pert described and will be using pins 11 for MOSI, 12 for MISO, 13 for SCK and 10 for chip select (although you can change this easily). This is obviously because the shield doesn't cover the actual SPI pins on the MEGA.