Electronic – PIC uno32 SPI communication with sensor

picspi

So, i'm trying to communicate with a heat sensor using SPI with a chipkit pic uno32.

I connected Pin 10 (SS), Pin 11 (DIN), Pin 12 (DOUT), and Pin 13 (CLK) on the Uno32 board to the sensor

SS-Chip Select
DIN – Data Input
DOUT – Data Output
CLK – Clock


int i;
IEC0CLR=0xFFFFFFFF; // disable all interrupts

SPI1CON=0; //desliga SPI

SPI1BUF=0; //limpa buffer

SPI1BRG=0x1; // use FPB/4 clock frequency

SPI1STATCLR=0x40; //limpa bit SPIROV

SPI1CONSET=0x0520; // 16 BITS | FALLING EDGE | Master Mode

SPI1CONSET=0x8000; //liga SPI

SPI1BUF=0x10; // transmit an A characte
while(SPI1STAT & BUSY)
{
    write_str("A receber\n\r");
}
printf("%d\n\r",SPI1BUF);   

The printf and write_str function works and sends data trough serial port (UART).
So when i put something in the buffer its supposed to transmit that data and receive the data from the sensor, in this case the temperature (value with 10 bits). However i always get the value 0 (which corresponds to 0 degress celcius which is incorrect).

Need help,

Thanks

Best Answer

Look up the && operator in your C reference manual, and how it differs from &.