Go Down

Topic: Can I reassign SPI pins on an Arduino UNO? (Read 2220 times) previous topic - next topic

vagulus

Feb 23, 2018, 12:16 am Last Edit: Feb 23, 2018, 12:18 am by vagulus Reason: Inserting image
Pins D10-D13 on an Arduino UNO are regularly assigned for SPI use



Are these hardwired in some way?
Can I assign any digital pins for these uses?
How do I declare these assignments in my Arduino code?
What about the six pins at the right of the PCB (in the illustration)?  Can I use those (although I notice there is no SS pin there)?

In short, can I, and how do I, assign other pins for SPI?

Thanks
"Answers are easy;
               it's asking the right questions
                                                      which is hard."
 The Doctor (Dr Who: The Face of Evil (1977))

Nick_Pyner

#1
Feb 23, 2018, 12:45 am Last Edit: Feb 23, 2018, 12:46 am by Nick_Pyner
In short, can I, and how do I, assign other pins for SPI?
I think not, and much more to the point would be your explanation as to why you would want to do that.

The ICSP cluster is simply an alternative set of the same pins. It is common to both Uno and Mega, while pins 11,13 are not SPI on Mega. SS is not part of the ISP bus. Pin 10 is just a common and obvious choice.

Some devices have software SPI , but that doesn't mean you get to change Arduino's hardware SPI.

Delta_G

There are libraries to do software SPI on Arduino but you'll pay a performance penalty for it. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

vagulus

I think not,
I take that to mean that these pins are hardwired to some hardware handling of SPI.
Is that correct?

and much more to the point would be your explanation as to why you would want to do that.
I was planning on using those pins for something else, bit I can do the something else on other pins - so that is not a real problem.


SS is not part of the ISP bus.
What is SS then?  The graphic in the initial post labels it something to do with SPI.

Some devices have software SPI , but that doesn't mean you get to change Arduino's hardware SPI.
Delta_G referred to that - thanks.
"Answers are easy;
               it's asking the right questions
                                                      which is hard."
 The Doctor (Dr Who: The Face of Evil (1977))

Delta_G

#4
Feb 23, 2018, 01:41 am Last Edit: Feb 23, 2018, 01:41 am by Delta_G
SS is slave select.  Go read any introductory document on SPI and it will explain the four lines.  The SS line selects which slave you'll send to.  It is also sometimes referred to as Chip Select or CS. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

vagulus

It is also sometimes referred to as Chip Select or CS.  
CS I am familiar with.  Thanks
"Answers are easy;
               it's asking the right questions
                                                      which is hard."
 The Doctor (Dr Who: The Face of Evil (1977))

CrossRoads

SS Must be an Output on the SPI master. If it is an Input and some other device drives it low, the Arduino will go into SPI slave mode.

SS does not have to be used as a chip select driver, but it has to be an output.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

gfvalvo

What is SS then?  The graphic in the initial post labels it something to do with SPI.
The SPI Bus proper consists of SPCLK, MOSI, and MISO. They operate at the SPI bit rate (multiple Mbits / sec) and typically require specialized hardware within the processor -- or, performance-sucking bit bang software SPI. That's why you can't reassign their pins willy-nilly. SS (aka CS) is only required to select the intended slave on the bus -- if there is more than one. It can be a relatively low speed GPIO because it just needs to be asserted before the SPI transaction and de-asserted after. With the Arduino SPI library, SS is handled by the user's code or by a library that uses the SPI library.

vagulus

SS does not have to be used as a chip select driver, but it has to be an output.
Thanks for that.

Thanks also to gfvalvo, Delta_G and Nick_Pyner
"Answers are easy;
               it's asking the right questions
                                                      which is hard."
 The Doctor (Dr Who: The Face of Evil (1977))

Nick_Pyner

I can do the something else on other pins
That sounds like a really good idea.

vagulus

In response to 'I can do the something else on other pins'  Nick wrote,

That sounds like a really good idea.
Well, it gets curiouser!  :o

The something else is code to drive a 128x64 OLED display with is a PCB (breakout) set up for SPI communication using u8g2lib.h.  This is the declaration which instantiates the OLED communication
Code: [Select]

/* Create instance of library used to communicate with the OLED. */
/* This configuration for remoteWeatherStation-PRX */
U8G2_SSD1325_NHD_128X64_1_4W_SW_SPI u8g2(
/* rotation zero */ U8G2_R0,
/* clock=*/ 7,
/* data=*/ 6,
/* cs=*/ 5,
/* dc=*/ 4,
/* reset=*/ 3);


You can see that I have assigned pins (other that 9-13) to those nice SPI tasks.  This works!  Clock, data, cs and dc are working from pins other that the Arduino standard pins!

How does that happen?
"Answers are easy;
               it's asking the right questions
                                                      which is hard."
 The Doctor (Dr Who: The Face of Evil (1977))

Delta_G

It is using software to drive the SPI instead of the hardware SPI.  You're paying a big performance penalty that way. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

el_supremo

The SW_SPI in the name means software SPI. It doesn't use the hardware pins.

Pete
Don't send me technical questions via Private Message.

srnet

You can see that I have assigned pins (other that 9-13) to those nice SPI tasks.  This works!  Clock, data, cs and dc are working from pins other that the Arduino standard pins!

How does that happen?

As has been mentioned more than once in this thread, you can run a software version of SPI (slower) on just about any of the pins.

Not curious at all really.
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

Go Up