it looks as though the code is writing the value 0x11 into the control register (0x80) of a TC72 digital temperature sensor
the statements
Code:
dummy = SSPBUF;
reads the value in the SPI serial transmit/receive register (and then appears to discard it) before the next write. I don't think you need to do this but we have to see the rest of the code.
I tend to write the SPI buffer, wait for it to complete and then read it in a function so (this is for a PIC24)
Code:
// send one byte of data and receive one back at the same time
unsigned char writeSPI1( unsigned char i )
{
SPI1BUF = i; // write to buffer for TX
while(!SPI1STATbits.SPIRBF) Nop(); // wait for transfer to complete
return SPI1BUF; // read the received value
}
hi horace1
thx for your response..in reality i want to connect two pic microcontollers using the spi protocol can you give me more details about this kind of connection with an example c code...
thx in advance
hi horace1
thx for your response..in reality i want to connect two pic microcontollers using the spi protocol can you give me more details about this kind of connection with an example c code...
thx in advance
should be no problem so long as the SPI configuration is the same in terms of baud rate and other parameters.
make one the master the other a slave? have a look at Microchip's sample code
**broken link removed**
hi horace1
i've read the codes from microship but i still didn't understand how to write to a microcontroller and get the response...for example in my case i want to perform a simple mathematical operation and send the comands from the first microcontroller to perform that operation in the second one , but the results will be displayed in LCD connected to the first microcontroller , so the question is how i can proceed to send the write and read commands , like we use to do in the TC72 digital sensor .
another question can you tell me please which registers in the SLAVE microcontroller should i work?
cheers..