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
Posted: Fri Dec 19, 2008 4:55 pm
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.
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