travrt travrt

SPI bidirectional

Discussion created by travrt travrt on Nov 29, 2007
Latest reply on Nov 30, 2007 by travrt travrt
I'm trying to understand how SPI works in bidirectional mode using this temp sensor  http://www.futurlec.com/FOST02.shtml

The problem I think is starting a transmission which requires the data line low on a upper SCK and data line high on the upper part of the next pulse SCK.  I can see it sending on a scope, and possiably an ack returned, but I'm not sure.  Anything other than that I don't get anything back from the sensor.  Somes it looks like I get back whatever I put in.

here is what I have code wise so far.


void initSPI0(void)
{
  SPI0CR1 = 0x58;  //set as master and enable SPI
                   //and SPTIE(SPI transmit interrupt enable)
                  
  SPI0CR2 = 0x0B;  //sets bidirectional mode, stop in wait mode, and serial pin control bit(enables bidirectional)
  SPI0BR  = 0x77;  //baud rate; 77 is the slowest baud rate at 12.21kHz
  WOMS    = 0x00;  // pull up pins?
}

void getTemp(void)
{
   SPI0CR2_BIDIROE = 1;

  //initalize transmission start 
  while(!(SPI0SR & SPI0SR_SPTEF_MASK)); /* wait until write is permissible */
     SPI0DR = 0xFA;   /* output the byte to the SPI */

  //send temperature measurement command 
  while(!(SPI0SR & SPI0SR_SPTEF_MASK)); /* wait until write is permissible */
     SPI0DR = 0x03;   /* output the byte to the SPI */

  //clears SPIF flag 
  while(!(SPI0SR & SPI0SR_SPIF_MASK));  /* wait until write operation is complete */
     cx = SPI0DR;            /* clear SPIF flag */
 
  SPI0CR2_BIDIROE = 0; 
  //recieve first byte
  while(!(SPI0SR & SPI0SR_SPTEF_MASK)); /* wait until write is permissible */
     SPI0DR = 0x00; /* trigger 8 SCK pulses to shift in data */

  while(!(SPI0SR & SPI0SR_SPIF_MASK));  /* wait until a byte has been shifted in */
       high = SPI0DR; /* return the character and clear SPIF flag */



Travis

Outcomes