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 support@ccsinfo.com

SPI PIC to PIC question
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Birdasaur



Joined: 07 Oct 2003
Posts: 29

View user's profile Send private message

Here is the code that works like a dream!
PostPosted: Fri Dec 12, 2003 6:57 am     Reply with quote

//master
setup_spi(spi_master | spi_l_to_h | spi_clk_div_16 );
delay_ms(100);

spi_write(byte1); //to wake up the slave
byte1 = spi_read(); //to read in what the slave has to say
delay_ms(1); //delay for slave vectoring
byte2 = spi_read(byte2); //start swapping bytes
delay_ms(1); //way more than I needed
byte3 = spi_read(byte3);
delay_ms(1);
//slave

setup_spi(spi_slave | spi_l_to_h | spi_clk_div_16 );

while(1)
{
spi_write(byte1); //the trick was to load the buffer ahead of time
if(spi_data_is_in()) //becareful with this, it sucks up clocks
{
byte1 = spi_read();
byte2 = spi_read(byte2);
byte3 = spi_read(byte3);
}
}

The delays in between the master spi_read() calls are needed, however 1 ms is FOREVER. I haven't bothered to experiment with reducing that but I'm sure a delay_us(50) or something like that would be more than sufficient. Thanks for all your help and good luck guys.

BTW... I didn't use any interrupts. I had the slave CS grounded at all times. To test this, I logged an overnight while(1) loop of this code, with a 1 second delay between packets, and it was flawless.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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