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 */ }
After some thought, and much reading on SPI it did seem that it was not compatible. This being the first SPI I’ve ever tried, I was at a lost. I asked my teacher to help me out on it, but he hasn’t had time to look at it.
The communications protocol for the FOST02 device is not directly compatible with the SPI module, particularly with respect to the special transmission start sequence, and the need to monitor the data line for the completion of the measurement, before data can be returned. It will probably be simpler to "bit-bang" the whole transmission sequence, using GPIO. This will avoid the need to frequently enable and disable the SPI module, with possible side effects.