Does SPI always use digital pins?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
joshuabardwell
 
Posts: 93
Joined: Wed Aug 14, 2013 2:09 pm

Does SPI always use digital pins?

Post by joshuabardwell »

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?

User avatar
joshuabardwell
 
Posts: 93
Joined: Wed Aug 14, 2013 2:09 pm

Re: Does SPI always use digital pins?

Post by joshuabardwell »

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.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Does SPI always use digital pins?

Post by adafruit_support_bill »

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
joshuabardwell
 
Posts: 93
Joined: Wed Aug 14, 2013 2:09 pm

Re: Does SPI always use digital pins?

Post by joshuabardwell »

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?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Does SPI always use digital pins?

Post by adafruit_support_bill »

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
joshuabardwell
 
Posts: 93
Joined: Wed Aug 14, 2013 2:09 pm

Re: Does SPI always use digital pins?

Post by joshuabardwell »

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!

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: Does SPI always use digital pins?

Post by tldr »

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.

User avatar
kscharf
 
Posts: 277
Joined: Wed Sep 10, 2008 10:29 am

Re: Does SPI always use digital pins?

Post by kscharf »

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 .....

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”