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");

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,



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

  • \$\begingroup\$ Nice catch.. +1 \$\endgroup\$ – m.Alin Nov 28 '12 at 1:21
  • \$\begingroup\$ 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 \$\endgroup\$ – cr4zypt Nov 28 '12 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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