CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with Slave SPI

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Thomas
Guest







Problem with Slave SPI
PostPosted: Sun Mar 16, 2003 10:46 pm     Reply with quote

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
PostPosted: Tue Mar 18, 2003 12:10 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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