SPI problem: Arduino as Slave, data is echoed back via MISO

I'm trying connected an embedded PC with an arduino (Mega 2560) via SPI. In my application the embedded is the master and the arduino is the slave.
My problem is that the arduino doesn't seem to respond to data input (I' have tried example programs from several authors) - the arduino program doesn't respond to data input.
However, employing a logic analyzer I found that the input data is being echoed back via MISO (with a short time delay). Really strange! This is not a software problem. If I upload a program that is not related to SPI communication I see the same behaviour.

If I disconnect the SPI on the arduino side MISO remains constantly high.

MOSI is connected to SSPTxD and MISO is connect to SSPRxD
I am using a level shifter between the 3.3 V embedded PC and the 5 V arduino - this seems to be working fine.

Do you have any idea what might be going wrong?

Best Regards
Tom

SPI is always bi-directional. Think of each side as a single shift register. On each clock transition a bit is shifted out through one pin and in through the other. For the Master it out through MOSI and in through MISO. Opposite for the Slave. At the end of 8 clocks a byte has been sent in each direction.

Typically the Master will send a command byte and receive a byte it doesn't care about:

SPI.transfer(command);

And then it will send out a byte of with no specific value and receive the result of the command:

result = SPI.tranfer(0);

Just ignore the garbage byte you receive when you are sending commands just as the receiver will ignore the unwanted received data wen it is sending results.

You are right, it seems that I can ignore the data sent back to the master.

Problem solved: Using the code below I also managed to read the data on the arduino slave.

//Don't use a Logic Analyzer (USB-Module) in parallel - this can cause a lot of corrupted data bytes
#include <stdio.h>
#include <avr/io.h>
#include <stdlib.h>

#define SPI_SCK 52
#define SPI_MISO 50
#define SPI_MOSI 51
#define SPI_SS 53

char data;
unsigned char scrap;
int counter = 0;

void setup()
{

pinMode(SPI_SCK,INPUT);
pinMode(SPI_MOSI,INPUT);
pinMode(SPI_SS,INPUT);
pinMode(SPI_MISO,OUTPUT);

Serial.begin(57600);
Serial.println("Enabling SPI in slave mode");
SPCR = 0x40; // Enable SPI in slave mode
delay(500);
Serial.println("Initialisation complete.");
}

void loop()
{
char buffer[8];
//Serial.println("Entering loop");
data = SPI_SlaveReceive();
//itoa(data, buffer, 10);
//Serial.println(buffer);
Serial.println(data);
// Serial.println(counter);

}

unsigned char SPI_SlaveReceive()
{
while(!(SPSR & (1<<SPIF)));
return SPDR;
}

You shouldn't need to go to all that trouble. The slave won't echo back what is being sent to it, except perhaps via capacitance if the line is high-impedance.

See my posts about SPI:

SPI is a two-way protocol. You don't need to discard incoming bytes, except that the very first transfer from the master to the slave is likely to result in an undefined result coming back (the slave doesn't know what to send back). After that, it should all be well-defined.