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 communication SPI

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







Problem with communication SPI
PostPosted: Fri Dec 19, 2008 3:35 am     Reply with quote

I use 16f877a which is master and another 16f877a is slave.
master:
pin A5 (select)


Code:
//master
#define SS_LOW (output_low(pin_A5)) //pin RA5 conected to nSS in 16F877A
#define SS_HIGH (output_high(pin_A5))
void main()
{
  setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4|SPI_SAMPLE_AT_END);   // TODO: USER CODE!!
  delay_ms(100);

while(1)
{
  int rs;
  SS_LOW;
  while (true)
  {
     spi_write(0x55);
     delay_ms(1);
     rs=spi_read();
     delay_ms(1);
     if(rs==0x33)
     {
        portd=0xff;delay_ms(500);
        portd=0;
     }
  }
}
}

//slave
void main()
{
  int kq;
  setup_spi(SPI_SLAVE | SPI_H_TO_L);
  delay_ms(100);
  while(1)
  {
  kq = spi_read();
  delay_ms(1);
  portd=kq;
  delay_ms(500);
  spi_write(0);

}
}


but when i test with proteus, nothing perform on slave's Portd
please show me what problem i face
Thanks guys
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 19, 2008 4:55 pm     Reply with quote

The SPI master needs to output an SCLK signal when it reads a byte
from the slave. In CCS, this is done by giving the spi_read() function
a parameter. Change your master code to this:
Quote:
rs=spi_read(0);

Now you will get the SCLK in the read operation, and you can continue
working on your design.
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