cancel
Showing results for 
Search instead for 
Did you mean: 

when is SPI clock sent?

salvatore
Associate II
Posted on November 17, 2011 at 12:20

Unfortunately I do not own an oscillope nor a logic analyzer to see this.

I'm having some problem using the SPI controller to communicate with a sensor.

I've managed to get some data, but not in a consistent way.

In particular, when I do something like

spi << command

spi >> result

It does not work. But if I do something like

while (1)

  spi << command

  spi >> value

It always work at the second iteration.

Now I'm wondering when is the clock actually sent? Is it always sent after the controller

is enabled until I disabled it?

2 REPLIES 2
Posted on November 17, 2011 at 15:13

A full duplex SPI master generates the clock as it send data to the slave, the same clocks allow the slave to return data. In most cases therefore you need to be sending some data to a slave in order to receive back, the outgoing data can be undefined/junk if the master doesn't care about it. When there is no data to be sent, and it has completed sending the last byte, the clock will stop.

The SPI receive register hold the data coming back, but reading the register does not cause any data to be returned. You should probably read the receive register prior to sending anything to ensure the RXNE flag is cleared, and then wait for it to go high after placing data in the transmit register.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
salvatore
Associate II
Posted on November 18, 2011 at 10:05

Thanks a lot. That explain what I was experiencing. Now it seems to work just fine.

Thanks again.

S.