SPI communication between two Ardunios

Hi ... I would like to sent some data from one Arduino (Master) to the second Arduino (Slave). I made a simple program, to transfer the time - how long I was holding a button.

This is the code for Master :

long int time=0;
boolean JE=false;

void setup() {
  pinMode(2, INPUT);    // declare pushbutton as input digital pin 2
  //setting the SPI - the same like in the datasheet for 328
  DDRB=(1<<DDB3)|(1<<DDB5);
  SPCR=(1<<SPE)|(1<<MSTR)|(1<<SPR0);  
}

void loop(){
//checking&counting the time while button is pressed  
if (digitalRead(2)==HIGH) 
   {
    time=millis();
    JE=true;    
    while (digitalRead(2)==HIGH) {}
   }
if (JE) 
   {
    JE=false;
    //sending the result through SPI
    SPDR=(millis()-time)/100;
    while(!(SPSR & (1<<SPIF)));        
   }
}

This is the code for the Slave :

void setup(){
//setting the SPI communication to Slave - like in the datasheet fro 328
DDRB=(1<<DDB4);
SPCR=(1<<SPE);
Serial.begin(9600);
}

void loop(){
int val;val=slave();
Serial.print(val);
Serial.print(" - ");
Serial.print(val,BIN);
Serial.println(val,DEC);
} 

int slave(){
while(!(SPSR & (1<<SPIF)));
return SPDR;
}

Please ... could you tell me what am I missing ??? I'm using digital pin 13, 12, 11,10 for the SPI communication. I have tried this connections :

M13-S13 M13-S13
M12-S12 ... or ... M12-S11
M11-S11 M11-S12
M10-S10 M10-S10

But without any results. thank you for any advice / correction in my codes.

Zholy

I have found the solution. The code is similiar = instead of telling me how long I have pushed the button, it tells me, how many times I've pushed it.

The code is over here :

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=722715#722715

Hope, this will help to someone :slight_smile:

Zholy