SPI master and slave

Hi Guys, I've been blocked for 3 weeks now searching for a solution to my problem concerning SPI communication,

So, I need to establish a Spi communication between two arduino, the master sends a lettre 'a' for exemple to the slave, and when the slave receives this lettre, he will do some traitements. In my case, he will set one of his 8 pins to high then read all pins and send the repport back to the master.

the part of sending 'a' and the traitement works fine within the slave, but i can't receive the correcte values in the master, i always receive 0.

can any help me please.

here are the codes.

esclave_spi.ino (1.61 KB)

maitre_spi.ino (1.15 KB)

Normally, the SPI bus requires two transfers to get data from the slave. The first transfers the command, and the second just reads the reply.

byte transferAndWait (const byte what)
{
  SPI.transfer (what);
  delayMicroseconds (10);
  byte a = SPI.transfer (0);
  return a;
} // end of transferAndWait