setClockDivider() does not work

I am unable to change the SPI clock rate regardless of what parameter i use for setClockDivider().

Code is below.

int CS = D0; 

void setup() {

pinMode(CS,OUTPUT);
digitalWrite(CS, HIGH );

// Prove to me that this latest example has been 
// downloaded 
Serial1.begin(115200);
Serial1.println("SPI Test 0.5");

//MSBFIRST
//LSBFIRST
SPI.setBitOrder(LSBFIRST);

//SPI_CLOCK_DIV2
//SPI_CLOCK_DIV4
//SPI_CLOCK_DIV8
//SPI_CLOCK_DIV16
//SPI_CLOCK_DIV32
//SPI_CLOCK_DIV64
//SPI_CLOCK_DIV128 
//SPI_CLOCK_DIV256
SPI.setClockDivider(SPI_CLOCK_DIV256);

//SPI_MODE0
//SPI_MODE1
//SPI_MODE2
//SPI_MODE3
SPI.setClockDivider(SPI_MODE0);

// initialise it 
SPI.begin();

}

void loop() {

// Bring my CS pin low
digitalWrite(CS, LOW );

// Send some data     
SPI.transfer(0xa5);

// Bring my CS pin high
digitalWrite(CS, HIGH );


delay(10);

}

Spark Team, any ideas here on this. I am ata stand still with this one until i can slow the clock rate down.

Have you tried calling all the setup procedures after SPI.begin()?

void setup() {
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV256);
}

That works just fine for me. How are you checking what speed the SPI bus is running at?

yes. same result. I am using a scope to check it.

Have you tried moving it all from void setup to void loop?

The command for setting the SPI mode is SPI.setDataMode(SPI_MODE0). With the code as it is, you are calling setClockDivider twice and the second call sets an incorrect value.

Also, as @timb indicated, your SPI.set commands should be in setup(). :smile: