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

SPI timing issue

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



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

SPI timing issue
PostPosted: Sun Oct 04, 2009 9:02 am     Reply with quote

Hi I have two PICs trying to communicate a few bytes over SPI.

Master:
Code:

while(1)
{
   while(!input(flag));
   while(input(flag));

   spi_write(a);
   spi_write(b);
}


Slave:
Code:

while(1)
{
   output_high(flag);
   delay_ms(1);
   output_low(flag);

   a = spi_read(0);
   b = spi_read(0);
}


Now, this code all works fine. But when I add delays to after the WRITE in the master, like this:

Code:

while(1)
{
   while(!input(flag));
   while(input(flag));

   spi_write(a);
   delay_ms(1);
   spi_write(b);
   delay_ms(1);
}


the PIC seems to hang.. is there something I'm not seeing??

Any help appreciated. Thanks.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Oct 04, 2009 9:26 am     Reply with quote

Basically, performing spi_read() on the slave side doesn't synchronize receipt of multiple bytes. If you consult the CCS examples, they perform something like
Code:
      while(!spi_data_is_in());
      data = spi_read();

Utilisation of SPI receive interrupt would be the most versatile option in my opinion.
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