arduino as SPI slave

Hello there

I'm trying to hook up my gumstix to the my arduino using spi. The gumstix parts done but I'm a bit stuck on the arduino side. after having a look at the tutorial example for spi it shows an example for being the master but there's no example code for slave set up.

I can figure out how the example works and how to change most of it e.g. changing directions of the pins and the reg set up. But the only bit of real code shifts the bits out. I think SPDR = data just puts data in a reg and the hard does the rest is this true?

char spi_transfer(volatile char data){
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) {}; // Wait the end of the transmission
return SPDR; // return the received byte
}

So how do I shift bits in, is there any built in commands or does the program have to wait for the slave to go high then do a loop looking for clk and data changes. Is there a biult in reg like SPDR?

thanks bren

After looking through the doc's I found the following bit of code.

void SPI_SlaveInit(void) {
DDR_SPI = (1<<DD_MISO); /* Set MISO output, all others input /
SPCR = (1<<SPE); /
Enable SPI */
}

char SPI_SlaveReceive(void) {
while(!(SPSR & (1<<SPIF))) ; /* Wait for reception complete /
return SPDR; /
Return Data Register */
}

I had the first bit done any way but it's nice to see that my code match there's. The second bit was the same as master but there's the return reg. So now to try and get this in to some code. The doc also says that once ss goes low that the reg's empty. Does this mean That I have to more the data out. how do I set up "if the data's this then do that or send this data back".

thanks bren