1. In SPI, I have read simultaneous data is send out & send in.
My question is since processor can handle only one task at a time. How can it work on two registers simulatneoulsy.
2. I successfully send data from master & slave can read it. but when I have to send data back to master, I am not able tyo send byte. Its just garbage value or mostly 0.
Master Code:
void main(void)
{
unsigned char read_byte, i=0;
spi_setting();
ss =0; //enable the slave
while(1)
{
SSPBUF = i++; // write data
while(BF == 0); //wait till complete
read_byte = SSPBUF; // not getting write byte from slave
}
}
void spi_setting(void)
{
ss=1; //set SS pin high, as initial slave module will be
ssio=0;
sckio =0; //setting clock as o/p, data out as outpot &
sdiio =1;
sdoio =0;
SSPSTAT = 0x40; // data is sampled in middle of o/p
SSPCON = 0x31; //spi master mode, fosc/16
}
Slave Code:
void main(void)
{
unsigned char read_byte;
spi_setting();
while(1)
{
while(BF==0);
read_byte = SSPBUF;
SSPBUF = 0x90; // not able to send this byte
}
}
void spi_setting(void)
{
ADCON1 = 0x06;
ssio = 1; // make slave select as input
sckio = 1; //make clock input, data in as input & data out as
sdiio = 1;
sdoio = 0;
SSPSTAT = 0x40; // data is sampled in middle of o/p
SSPCON = 0x34; //spi alve mode mode, fosc/16
}
My question is since processor can handle only one task at a time. How can it work on two registers simulatneoulsy.
2. I successfully send data from master & slave can read it. but when I have to send data back to master, I am not able tyo send byte. Its just garbage value or mostly 0.
Master Code:
void main(void)
{
unsigned char read_byte, i=0;
spi_setting();
ss =0; //enable the slave
while(1)
{
SSPBUF = i++; // write data
while(BF == 0); //wait till complete
read_byte = SSPBUF; // not getting write byte from slave
}
}
void spi_setting(void)
{
ss=1; //set SS pin high, as initial slave module will be
ssio=0;
sckio =0; //setting clock as o/p, data out as outpot &
sdiio =1;
sdoio =0;
SSPSTAT = 0x40; // data is sampled in middle of o/p
SSPCON = 0x31; //spi master mode, fosc/16
}
Slave Code:
void main(void)
{
unsigned char read_byte;
spi_setting();
while(1)
{
while(BF==0);
read_byte = SSPBUF;
SSPBUF = 0x90; // not able to send this byte
}
}
void spi_setting(void)
{
ADCON1 = 0x06;
ssio = 1; // make slave select as input
sckio = 1; //make clock input, data in as input & data out as
sdiio = 1;
sdoio = 0;
SSPSTAT = 0x40; // data is sampled in middle of o/p
SSPCON = 0x34; //spi alve mode mode, fosc/16
}