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

void loop(){
//checking&counting the time while button is pressed  
if (digitalRead(2)==HIGH) 
    while (digitalRead(2)==HIGH) {}
if (JE) 
    //sending the result through SPI
    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

void loop(){
int val;val=slave();
Serial.print(" - ");

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.


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 :


Hope, this will help to someone :)