SIp with Two PIC16F877A

Discussion in 'General Electronics Chat' started by aamirali, May 16, 2012.

  1. aamirali

    Thread Starter Member

    Feb 2, 2012
    415
    1
    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

    }
     
  2. aamirali

    Thread Starter Member

    Feb 2, 2012
    415
    1
    any help :)
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    The SPI is impemented in hardware. Think of it as a pipe with an inlet and an outlet, or a room with an IN-door and an OUT-door. Data goes in one door and out the other. This is done by the hardware and all the MCU has to do is read the contents of the room.
     
  4. aamirali

    Thread Starter Member

    Feb 2, 2012
    415
    1
    thanks for that
    any comments/help in source code??????
     
Loading...