Does SPI always use digital pins?
Moderators: adafruit_support_bill, adafruit

Does SPI always use digital pins?

by joshuabardwell on Mon Aug 26, 2013 12:27 pm

When I use SPI, does it always use three of my digital pins, or does it use dedicated "SPI" pins on the board? If the former, are those pins fixed (like whether a pin is PWM or not) or arbitrary (like initializing an LCD where it can be whatever you want). Are these answers consistent across most/all Arduino boards, or are there some Arduino boards that are exceptions?
joshuabardwell
 
Posts: 93
Joined: Wed Aug 14, 2013 1:09 pm

Re: Does SPI always use digital pins?

by joshuabardwell on Mon Aug 26, 2013 12:33 pm

Also: If I have multiple SPI devices, then is it correct that I need a separate slave select line for each of them, so the number of pins required is 3 + n, where n is the number of SPI devices on the system?

EDIT: Actually, perhaps if only one SPI device was present, you could just jumper slave select to ground or 5v, whichever was appropriate to cause it to always be selected.
joshuabardwell
 
Posts: 93
Joined: Wed Aug 14, 2013 1:09 pm

Re: Does SPI always use digital pins?

by adafruit_support_bill on Mon Aug 26, 2013 12:45 pm

Hardware SPI implies the use of the hardware SPI pins (11-13 on the Arduino Uno). The default CS(SS) is pin 10, but this can be specified at startup. Additional devices will need their own CS pin. If there is only one device, its CS can often be tied low to permanently enable it.

SoftwareSPI is another story. There are many different implementations of SPI and SPI-like protocols. Most allow you to select the pins you want to use. But not all of them play well together.
User avatar
adafruit_support_bill
 
Posts: 29768
Joined: Sat Feb 07, 2009 9:11 am

Re: Does SPI always use digital pins?

by joshuabardwell on Mon Aug 26, 2013 12:45 pm

Thanks, Bill. Do most/all Arduino boards have hardware SPI? If I am using hardware SPI with a single device, and have tied the slave select line low, can I still use pin 10 as a regular hardware pin, or will the SPI chip be using it as if it was slave select?
joshuabardwell
 
Posts: 93
Joined: Wed Aug 14, 2013 1:09 pm

Re: Does SPI always use digital pins?

by adafruit_support_bill on Mon Aug 26, 2013 1:48 pm

Do most/all Arduino boards have hardware SPI?

Many do. But depending on the library, some can be used for either hardware or software SPI (e.g. anything with an SD card interface). This would be covered in the tutorial for the board(s) in question.

can I still use pin 10 as a regular hardware pin

I believe that on the Uno it needs to be declared as an output pin. But may otherwise be used as you see fit.
User avatar
adafruit_support_bill
 
Posts: 29768
Joined: Sat Feb 07, 2009 9:11 am

Re: Does SPI always use digital pins?

by joshuabardwell on Mon Aug 26, 2013 2:11 pm

Thanks very much. This was all very helpful and clear, and is part of why I keep coming back to Adafruit for my Arduino needs!
joshuabardwell
 
Posts: 93
Joined: Wed Aug 14, 2013 1:09 pm

Re: Does SPI always use digital pins?

by tldr on Tue Aug 27, 2013 12:37 am

the uno and micro actually have two hardware spi interfaces. although it is not supported directly in the arduino api, the usart on each of these boards can be configured to operate as an spi device.
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 12:34 am

Re: Does SPI always use digital pins?

by kscharf on Thu Sep 12, 2013 9:53 am

tldr wrote:the uno and micro actually have two hardware spi interfaces. although it is not supported directly in the arduino api, the usart on each of these boards can be configured to operate as an spi device.

This is ALMOST true about the Arduino Mega. The atmega1280 and atmega2560 chips used on those boards have four usarts that all support SPI mode. HOWEVER, the pins that correspond to the clock output (SCK) (txn==MOSI and rxn==MISO) were NOT brought out to connectors on the board! DUMB DUMB DUMB! The Arduino designers should hang their heads in shame! At least the Seeduino Mega DOES bring EVERY SINGLE I/O PIN of the atmega2560 out to play. Now if you have some real fine guage wire, a very fine tiped soldering iron, steady hands and good eyesight you CAN fix the issue with some flyleads on the Arduino but .....
User avatar
kscharf
 
Posts: 185
Joined: Wed Sep 10, 2008 9:29 am