chipKIT® Development Platform

Inspired by Arduino™

Using SPI.h >>> HELP!

Created Thu, 03 May 2012 20:25:50 +0000 by xray_drifter


xray_drifter

Thu, 03 May 2012 20:25:50 +0000

Hello I am trying to use SPI libaray to send and receive data between two UNOs I have the following setup:

Uno 1 Uno2 Pin 10 <--> Pin 10 PIn 11 <--> Pin 11 Pin 12 <--> Pin 12 Pin 13 <--> Pin 13 JP4-->RD4 JP4-->RG9 JP5-->Master JP5-->SLAVE JP7-->Master JP7-->SLAVE

At the master side I have the following code (simpified):

#include &lt;SPI.h&gt;

void setup(){
    TRISD &amp;= ~(0x0010); //RD4 as output
    TRISG |= 0x0080;   //RG7 as input, rest are output
    SPI.begin()
}

void loop(){
     for (int i=1;1&lt;100;i++){
          digitalWrite(10,LOW);  //Set ss to low
          SPI.transfer(100);    //I just want to transfer 100 as a test
          digitalWrite(10,HIGH); //Set ss back to high
    }
}

At the [color=#FF0000]slave[/color] side I have the following code (simpified):

#include &lt;SPI.h&gt;

void setup(){
    TRISG |= 0280;       //RG9 as ss input, RG7 as MOSI hence input, rest output
    SPI.begin();
    Serial.begin(115200);
}

void loop(){
    byte rx_stuff;
    rx_stuff = SPI.transfer(0x00);
    Serial.println(rx_stuff,DEC);
}

The printed out data from the slave seems be a "shifting" version of 100. I would be getting 3, 6, 12, 25,50, 100, 200. I seems to me the SPI.transfer() function is shifting out few bits at a time, but I couldn't tell how many bits it is shifting.

What do you think guys? Do you think I am using SPI library correctly for my application? Can I assume slave will only fetch value from SPI1BUF when ss is low, and I should have to setup any statement to catch that right?

I have tried writing SPI1BUF and checking SPI1TBE, SPI1TBF directly, but no lucky sending anything across.....