Hi Amit,
SPI silicon IPs work differently from those of the serial ports. In SPI writes and reads occur according to one CLK signal, this signal must be generated by the Master device. It's odd, but needed, you have to 'write' for 'reading', but only in the master device.
In the code for the master device, after writing, you have to keep checking wheter it is busy or not before trying to read:
- WriteBlock();
- while (busy()) { do something or nothing };
- ReadBlock( n bytes );
- call inmediately WriteBlock( same n bytes ); for generating the clock, it doesn't matter what you send.
One more thing, take into account the time it takes to the slave device to be ready to return data, it must setup the SPI driver before the master calls for return data. In some cases you could use one HW handshake signal to make the master aware of data availability in the slave device (one interrupt line).
There's a thread where you'll find some info about several issues with the SPI master drivers: Is anyone really using PE Generated SPI driver with MQXLite? How?.
Hope it's usefull for you.
--Victor