SPI slave echoes MOSI and ignores Slave output

I am implementing a slave sample with an Atmega328p through the Arduino platform. The device communicates with a linux board with SPI. '
The problem is that the Master sends data and after the first response all the data that the slave sends is an echo of the previous byte sent by the master.

Here is the output of the Scope:

The code I am using for the Arduino is the following:

void setup (void)
{

  pinMode(MISO, OUTPUT);
  SPDR=0x90; //First data to send to master
  SPCR |= _BV(SPE);
  SPCR = (1 << SPE) | (1 << SPIE); // slave mode  and SPI interrupt
}  // end of setup

byte SPItransfer(byte value) {
  SPDR = value;
  while(!(SPSR & (1<<SPIF)));

}
volatile uint8_t count=0;
void loop (void)
{

}  // end of loop

// SPI interrupt routine
ISR (SPI_STC_vect)
{

  uint8_t buffer=SPDR;
  SPItransfer(count++);

}

From my test I see that the SPDR register is not being updated on the next calls of the ISR with my variable. Is there anything else that I missed?

Remove the while loop from your SPITransfer().

yudopplyr:
I am implementing a slave sample with an Atmega328p through the Arduino platform. The device communicates with a linux board with SPI. '
The problem is that the Master sends data and after the first response all the data that the slave sends is an echo of the previous byte sent by the master.

Here is the output of the Scope:

The code I am using for the Arduino is the following:

void setup (void)

{

pinMode(MISO, OUTPUT);
SPDR=0x90; //First data to send to master
SPCR |= _BV(SPE);
SPCR = (1 << SPE) | (1 << SPIE); // slave mode and SPI interrupt
} // end of setup

byte SPItransfer(byte value) {
SPDR = value;
while(!(SPSR & (1<<SPIF)));

}
volatile uint8_t count=0;
void loop (void)
{

} // end of loop

// SPI interrupt routine
ISR (SPI_STC_vect)
{

uint8_t buffer=SPDR;
SPItransfer(count++);

}




From my test I see that the SPDR register is not being updated on the next calls of the ISR with my variable. Is there anything else that I missed?

did you have a look at this link:

some really good material there.