SPI how it works.

Thread Starter

gusmas

Joined Sep 27, 2008
239
Ok i am using msp430 micro controller and a temp sensor, and i am trying to understand how spi works and how to program it.

Now from what i understand is this:

1.MOSI - Master (temp sensor) sends data(temperature) to slave (mirco controller)

2.Setting the clock phase to 1 or 0 determines if the data is written or read on the falling edge or the rising edge of the clock.

3. CS(Active Low). When pulled low the data will start to send.

What I am trying to understand is:

1.Lets say my temp is 10(Binary) and i want to send that to my micro controller. And my SPI is configured to write on the rising edge of the clock and read on the falling edge of the clock. Will the MOSI go high when the first rising edge of the clock pulse arrives, then go low as soon as the 2nd clock pulse rising edge arrives? and then send a zero along the MOSI line until they byte is succesfully read?

---------------------------------------------------------------------------------

I hope I am making sense , its difficult to explain.
 

Papabravo

Joined Feb 24, 2006
21,159
SPI is a really simple way for a micro and a peripheral device to exchange bytes of data. Both sides have to agree about the data format which is selected by deciding on "CLOCK PHASE" and "CLOCK POLARITY". The datasheet for your sensor will tell you wha the device expects and you setup the micro to be compatible. When you write a byte to the data register, the hardware in the micro will generate the clocking for you and send out the data. At the same time the micro is send 8 bits it is also receiving 8 bits. Sometimes these bits are meaningless and the micro should throw them on the floor. Sometimes they are meaningful and you want to save them.

You did not mention the MISO line. This stands for Master In Slave Out. This is the data coming from the sensor back to the micro. This is where the temperature data will be. The other line MOSI is the command going to the sensor.
 

Thread Starter

gusmas

Joined Sep 27, 2008
239
ah ok i understand
so tell me if i am on the correct path:

1. Mico controller - Master
2. Temp Sensor - Slave
3. MISO will carry the temp in binary (checked that on my datasheet for my temp sensor) from the temp sensor to the micro controller
4.About the MOSI line im not to sure?
 
Last edited:
Top