Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

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

share|improve this answer
    
Nice catch.. +1 –  m.Alin Nov 28 '12 at 1:21
    
I forgot about that, so i fixed it and updated my code. Now i get the SPI1BUF register completely filled with 1's. Also i cheked the wiring and correted it, i had Din connected to the sensor's DIn and should be PIC DOUT to the Sensor's DIN –  cr4zypt Nov 28 '12 at 10:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.