Hi,
- First, you should check the mode (0,1,2,3 which is supported)
- Check by oscilloscope
- My code is used to communicate with external flash (w25q16), example:
* Wrong code
CS_CLEAR;
uint8_t temp = 0;
SPI_SendChar(W25X_DeviceID);
SPI_SendAndRecvChar(Dummy_Byte);
SPI_SendAndRecvChar(Dummy_Byte);
SPI_SendAndRecvChar(Dummy_Byte);
temp = SPI_SendAndRecvChar(Dummy_Byte);
CS_SET;
* Right Code
CS_CLEAR;
uint8_t temp = 0;
SPI_SendAndRecvChar(W25X_DeviceID);
SPI_SendAndRecvChar(Dummy_Byte);
SPI_SendAndRecvChar(Dummy_Byte);
SPI_SendAndRecvChar(Dummy_Byte);
temp = SPI_SendAndRecvChar(Dummy_Byte);
CS_SET;
The mistake is the SPI data return wrong (the data is shift to the right one byte so I always see the data is 0x00) so when I fix this code, the data is true
Hope this help