Changing SPI pins

I am working on building for an Uno, a shield PCB with a chip that runs SPI. The chip is surface mount and I would like to make the traces leading to it as simple as possible.

My question is, can I move the SPI pins to any digital pin that I want? I found a code that ebw44 posted in the storage section and I want to know if I can modify it to work with Uno? I am guessing the biggest difference would be just setting the pins numbers between 2-13.

Any suggestions would be great,
Mark

The code is most likely out of order, I have more saved but, the rest is specific to his application.

void setupExternalADC(){ 
 pinMode(SELPIN, OUTPUT); 
 pinMode(DATAOUT, OUTPUT); 
 pinMode(DATAIN, INPUT); 
 pinMode(SPICLOCK, OUTPUT); 
 //disable device to start with 
 digitalWrite(SELPIN,HIGH); 
 digitalWrite(DATAOUT,LOW); 
 digitalWrite(SPICLOCK,LOW); 
} 

there is an header file for pin configuration
#define SELPIN 25 //Selection Pin 
#define DATAOUT 24//MOSI 
#define DATAIN  26//MISO 
#define SPICLOCK  22//Clock

I think you need to post more of the code, but it appears from that bit that other parts of the code are bit-banging SPI, rather than using the hardware SPI. Hardware SPI is implemented on specific pins that vary by board type. The hardware SPI pins can not be changed without a soldering iron.

PaulS, I think you are correct, he is doing some sort of bit-banging SPI. I have not reached a full understand how it is done yet.

Thank you for the response. I am now leaning toward making the traces as necessary rather than adding more complex code.

Here is the rest of the code that ebw44 posted.

int read_adc(int channel){
  int adcvalue = 0;
  byte commandbits = B11000000; //command bits - start, mode, chn (3), dont care (3)

  //allow channel selection
  commandbits|=((channel-1)<<3);

  digitalWrite(SELPIN,LOW); //Select adc
  // setup bits to be written
  for (int i=7; i>=3; i--){
    digitalWrite(DATAOUT,commandbits&1<<i);
    //cycle clock
    digitalWrite(SPICLOCK,HIGH);
    digitalWrite(SPICLOCK,LOW);    
  }

  digitalWrite(SPICLOCK,HIGH);    //ignores 2 null bits
  digitalWrite(SPICLOCK,LOW);
  digitalWrite(SPICLOCK,HIGH);  
  digitalWrite(SPICLOCK,LOW);

  //read bits from adc
  for (int i=11; i>=0; i--){
    adcvalue+=digitalRead(DATAIN)<<i;
    //cycle clock
    digitalWrite(SPICLOCK,HIGH);
    digitalWrite(SPICLOCK,LOW);
  }
  digitalWrite(SELPIN, HIGH); //turn off device
  return adcvalue;
}

PaulS:
I think you need to post more of the code, but it appears from that bit that other parts of the code are bit-banging SPI, rather than using the hardware SPI. Hardware SPI is implemented on specific pins that vary by board type. The hardware SPI pins can not be changed without a soldering iron.

Or even WITH a soldering iron… XD

Edit: Read too fast, thought you meant the chip…

I think you are correct, he is doing some sort of bit-banging SPI.

That code is how you bit-bang SPI. So, why not use the hardware SPI method (and pins)?

Using digitalWrite() to bit bang SPI is going to be much slower than the hardware SPI, if this matters. Direct port manipulation can give a big speed up if the hardware SPI is out of the question.

PaulS:

I think you are correct, he is doing some sort of bit-banging SPI.

That code is how you bit-bang SPI. So, why not use the hardware SPI method (and pins)?

After reading all of the replies, I plan to make the hardware SPI pins work and adjust my PCB traces to get to the pins.

Thanks for all the help,
Mark