Problem Getting SPI clock to work

Dear all,

I'm trying, for the first time, to use the SPI library. Please could someone confirm whether SPI.begin and/or SPI.beginTransaction should start the clock pin oscillating?

I have disconnected everything from the Uno apart from my oscilloscope which is connected to pin 13 (have also tried others) but don't see any voltage change on the pin. It is just sitting at 0V.

I've also tried measuring it whilst transferring data (or at least trying to) and similarly see no voltage change.

Yours frustratedly,
Rocket

I would start by going here: Basics of the SPI Communication Protocol to get a basic idea of what you are trying to do. Then go here: SPI Tutorial – Serial Peripheral Interface Bus Protocol Basics this will explain the many modes of the SPI interface. Then find a small sketch that uses the SPI and play with it. By that time you will have a good understanding of it and how to use it. This response is to help you get started in finding the problem, not solve it for you.
Good Luck & Have Fun!
Gil

Thanks but I had already googled those links. I specifically wanted to avoid half a day of experimenting to figure out when the clock is expected to oscillate - is it when .beginTransaction is called or .transfer and whether the clock would also run when all the SPI wires are floating.

Cheers.

Rocket888888:
Please could someone confirm whether SPI.begin and/or SPI.beginTransaction should start the clock pin oscillating?

The clock is only active when there is data to send or receive.

1. Connect an oscilloscope at DPin-13 of Fig-1 of Step-4.

2. Try the following sketch; you will be able to see pulses at the SCK-pin/Osc of Master-SPI.

#include<SPI.h>

void setup()
{
    Serial.begin(9600);
    SPI.begin();
}

void loop()
{
   SPDR = 0x23;
   while(bitRead(SPSR, SPIF) !=HIGH)
   {
       ;
   }
   byte x = SPDR
   delay(1000);
}

3. SCK is automatically generated when something is written into SPDR Register or byte x = SPI.transaction(0x23); code is executed.

4. This is the SPI Connection between Master and Slave
spi328x.png
Figure-1:

spi328x.png

Thanks. I get the clock pulses doing that. Still not sure what I was doing wrong but it gets me further along the path knowing that when I do get it right, I do get a 4MHz clock from your code.

Rocket888888:
Thanks. I get the clock pulses doing that. Still not sure what I was doing wrong but it gets me further along the path knowing that when I do get it right, I do get a 4MHz clock from your code.

You should get 125 KHz ckock (default SPI bit transfer speed) from my codes and not 4 MHz. Check that the bit period is: 1/125000 = 8 us.