Implementation of SPI reading and Writing using Same API!

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi,
I am using SPI001 example code for XMC 4500, I am implementing API which should work for writing and reading From EEPROM.
But while reading it just reading 0xFF, I have used the below code.
uint16_t  SPI_TransferByte(uint16_t Data)
{
uint16_t tmp;
uint16_t TData = 0;
uint8_t Status1 = 0;
uint8_t Status2 = 0;

SPI001_Config0.Mode = SPI001_STANDARD_FULLDUPLEX;

/*Change the frame length to 8 for sending
* Write Enable command to flash chip */
SPI001_Config0.FrameLen = 8;

/* Configure the SPI Channel */
SPI001_Configure(&SPI001_Handle0,&SPI001_Config0);

/* Clear Standard receive indication and Alternative receive indication flag */
SPI001_ClearFlag(&SPI001_Handle0,SPI001_RECV_IND_FLAG);
SPI001_ClearFlag(&SPI001_Handle0,SPI001_ALT_RECV_IND_FLAG);

TData = Data;

/* Send Write Enable Command */
SPI001_WriteData(&SPI001_Handle0,&TData,SPI001_STANDARD);

/* Wait till dummy data is received from flash chip */
do
{
Status1 = SPI001_GetFlagStatus(&SPI001_Handle0,SPI001_RECV_IND_FLAG);
Status2 = SPI001_GetFlagStatus(&SPI001_Handle0,SPI001_ALT_RECV_IND_FLAG);
}while(!((Status1 == SPI001_SET) || (Status2 == SPI001_SET)));

/* Do a dummy read*/
SPI001_ReadData(&SPI001_Handle0,&tmp);
return tmp;
}
int main(void)
{
uint16_t RdData = 0x00;
DAVE_Init(); /* Initialize the App */

SPI_TransferByte(0x06);/*Write Enable Command 0x06*/
SPI_TransferByte(0x05);// Read Status Commmand
RdData = SPI_TransferByte(0xFF);/* Writing Dummy Byte for Readind Status*/

}







}
0 Likes
0 Replies