Hello, and welcome to the forum.
Firstly, to clarify some terminology -
The SPI module may be configured as either a master, or a slave. Both configurations are capable of handling data flow in both directions simultaneously. For the master, data is sent via MOSI, and received via MISO. For the slave end, the roles are reversed. The master end always initiates each data transfer, and generates the clock pulses required.
The code snippet that you have shown is suitable for the SPI master, where a send byte is initiated, and the received value is available once the SPIF flag becomes set.
For the SPI slave, the operation is quite different. Any data to be returned to the master on the next transfer needs to be loaded to the buffer prior to SS becoming active. Following the receipt of data from the master (and the return of the data already within the buffer), the SPIF flag will become set. If data is to be returned in response, this will commence on the next transfer. This may require that the master allow adequate time for the slave to process the data, before initiating the transfer (usually with "dummy" send bytes). Alternatively, the slave might signal back to the master when it is ready, or requires some attention, using an extra GPIO line.
To minimize the delay within the master, SPI interrupts are freqently used for the SPI slave. If the response requires a sequence of more than one byte, the double bufferering capability of the SPI module can be put to use. A second byte can be loaded to the buffer, prior to the first byte being returned.
For communications between two MCUs, it is also possible for each MCU to default to slave mode, and only become a master when it requires to initiate an action (a multi-master situation). But this method requires more complex code to handle potential conflicts.
Regards,
Mac