SPI not working with connecting two PIC16F877

Discussion in 'Embedded Systems and Microcontrollers' started by icem, Mar 26, 2011.

  1. icem

    Thread Starter New Member

    Nov 15, 2009
    26
    0
    hi

    Im trying to send an byte of data via spi between two PIC16f877.

    I have set one chip as master and other as slave.

    Is there a way to find out if the spi is actually sending data?

    My master chip takes inputs from an accelerometer and computes an value corresponding to the angle a which it is at.

    What i'm trying to do is send that value to another PIC which will output the value onto an LED display.

    Any help would be great

    Thank you very much for your time.
     
  2. icem

    Thread Starter New Member

    Nov 15, 2009
    26
    0
    I'm just I realise that the code for the master is quite long so here is the important bits,

    Code ( (Unknown Language)):
    1.   setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);
    Code ( (Unknown Language)):
    1.          if (((DutyCycleX >=0)&&(DutyCycleX  <= 220))|((DutyCycleX  >265)&&(DutyCycleX  <= 285)))
    2.          {
    3.             lightsX = 0x18;
    4.          }
    5.          else if (((DutyCycleX  >220)&&(DutyCycleX  <= 265)))
    6.          {
    7.             lightsX = 0x40;
    8.          }
    9.          else if (((DutyCycleX  >285)&&(DutyCycleX  <= 320)))
    10.          {
    11.             lightsX = 0x40;
    12.          }
    13.           else if (((DutyCycleX  >320)&&(DutyCycleX  <= 380)))
    14.          {
    15.             lightsX = 0x0f;
    16.          }
    17.          else if (((DutyCycleX  >380)&&(DutyCycleX  <= 1000)))
    18.          {
    19.             lightsX = 0x0f;
    20.          }
    21.          printf("\r\n lightX = %d",lightsX );
    22.          spi_write(lightsX);
    23.          delay_us(100);
    24.          value = spi_read();
    Thank you
     
  3. icem

    Thread Starter New Member

    Nov 15, 2009
    26
    0
    and here are the codes as attachments
     
  4. ahmed899

    New Member

    Apr 8, 2011
    1
    0
    i need a basic spi code to test whether spi is working or not. I am using C18 compiler. I want to establish a simple communication between 2 pic18f452, one as a master and other as a slave..!!

    Please help me out or guide to some resources from where i could eslily manage!!

    thanks
     
Loading...