|
|
View previous topic :: View next topic |
Author |
Message |
Thomas Guest
|
Problem with Slave SPI |
Posted: Sun Mar 16, 2003 10:46 pm |
|
|
Hello,
I have two PICs, one as master and one as slave. The master continously sends out data to the slave. The slave saves the data to a register and puts the same copy back to SSPBUF for the master the double-check the echo data.
Below is a simple code for the slave. Somehow, I can't get any data coming in or out of the slave device. I verified that the CS, Clk, Data signal are connected to the slave. Hardware wise, I don't see any problem. I think the problem is with the software. Would someone help please?
Regards,
Thomas
void InitSPI()
{
setup_spi(SPI_SLAVE | SPI_L_TO_H);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
}
#byte SSPBUF=0x13
#INT_SSP
SPI_ISR()
{
spiTemp = SSPBUF;
SSPBUF = spiTemp;
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12755 |
|
|
Warren Massey Guest
|
Re: Problem with Slave SPI |
Posted: Tue Mar 18, 2003 12:10 pm |
|
|
I think you need to check out the SPI_READ() and SPI_WRITE() functions. The setup function does not auto-magically direct the hardware to use your SSPBUF.
Also know that by the very nature of the SPI bus, when your slave device is reading in the bits of data going to the slave, it is also clocking out bits back to the master.
Your echo back of the data byte will require a second separate SPI transaction/transmission back to the master which will cause the master, as it is reading the bits in from the slave, to again transmit a byte back to the slave. You could build yourself an endless loop here if you are not careful.
The alternative is to ignore the SPI SETUP/READ/WRITE functions and write your own slave routine for monitoring and driving the I/O pins. That way as a bit arrives, you can immediately echo the bit back so that when the transmission of the byt to the slave is complete, the echo of the byte back to the master is complete as well.
Search this forum for SPI and see how others are using it.
:=Hello,
:=
:=I have two PICs, one as master and one as slave. The master continously sends out data to the slave. The slave saves the data to a register and puts the same copy back to SSPBUF for the master the double-check the echo data.
:=
:=Below is a simple code for the slave. Somehow, I can't get any data coming in or out of the slave device. I verified that the CS, Clk, Data signal are connected to the slave. Hardware wise, I don't see any problem. I think the problem is with the software. Would someone help please?
:=
:=Regards,
:=Thomas
:=
:=void InitSPI()
:={
:= setup_spi(SPI_SLAVE | SPI_L_TO_H);
:= enable_interrupts(INT_SSP);
:= enable_interrupts(GLOBAL);
:=}
:=
:=#byte SSPBUF=0x13
:=#INT_SSP
:=SPI_ISR()
:={
:= spiTemp = SSPBUF;
:= SSPBUF = spiTemp;
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12798 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|