2011-11-17 03:20 AM
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 likespi << commandspi >> resultIt does not work. But if I do something likewhile (1) spi << command spi >> valueIt always work at the second iteration.Now I'm wondering when is the clock actually sent? Is it always sent after the controlleris enabled until I disabled it?2011-11-17 06:13 AM
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.2011-11-18 01:05 AM
Thanks a lot. That explain what I was experiencing. Now it seems to work just fine.
Thanks again.S.