cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
yuey
Newbie
Newbie
3,891 Views
Registered: ‎01-14-2010

SPI FLASH M25P16 @ spartan3e starter kit

I met a problem when i try to use the flash on the kit.

I could not even read the id from the device.

The processer is Microblaze V7.10c. Spi ip core is xps_spi V2.0.0b.

The software i used is EDK V10.1 with sp2.

When I try to read the id of the device, return value is oxFF.

 

Also, when I set the loop_back option, the return value was equal to the send value, what I thought was right.

 

where could I be wrong? 

 

thx 

 

#include "xparameters.h"
#include "xbasic_types.h"
#include "xspi.h"

#define SPI_DEVICE_ID       XPAR_SPI_0_DEVICE_ID
// SF One-byte Op-Codes
#define  WREN    0x06  // Write Enable
#define  WRDI    0x04  // Write Disable
#define  RDID    0x9F  // Read Identification
#define  RDSR    0x05  // Read Status Register
#define  WRSR    0x01  // Write Status Register
#define  READ    0x03  // Read Data Bytes
#define  FAST    0x0B  // Read Data Bytes at Higher Speed
#define  PP      0x02  // Page Program
#define  SE      0xD8  // Sector Erase
#define  BE      0xC7  // Bulk Erase
#define  DP      0xB9  // Deep Power-down
#define  RES     0xAB  // Read 8-bit Electronic Signature and/or Release from Deep power-down

void main(void)
{
 Xuint8   send_data[16], recv_data[16];
 int    Status;
 XSpi     Spi;

 xil_printf("Serial Flash Test\n\r");

 //*******************************************************************
 //Initial the spi
 //*******************************************************************
 //XSpi_Reset(&Spi);
 Status = XSpi_Initialize(&Spi, SPI_DEVICE_ID);
 xil_printf("BaseAddr= : %x \n\r", Spi.BaseAddr);
 xil_printf("HasFifos= : %d \n\r", Spi.HasFifos);
 if (Status == XST_SUCCESS)
 {
  xil_printf("Spi Initialize success!\n\r");
 }
 else
 {
  xil_printf("Spi Initialize failed!\n\r");  
 }
 //*******************************************************************
 //Test the spi
 //*******************************************************************
 Status = XSpi_SelfTest(&Spi);
 if (Status == XST_SUCCESS)
 {
  xil_printf("Spi test success! \n\r");
 }
 else
 {
  xil_printf("Spi test failed!\n\r");  
 }

 //*******************************************************************
 //Start the spi
 //*******************************************************************
 //XSpi_SetOptions(&Spi,XSP_MASTER_OPTION);
 XSpi_SetOptions(&Spi,(XSP_MASTER_OPTION|XSP_MANUAL_SSELECT_OPTION));
 //XSpi_SetOptions(&Spi,XSP_MASTER_OPTION|XSP_LOOPBACK_OPTION);
 Status = XSpi_Start(&Spi);
 if (Status == XST_SUCCESS)
 {
  xil_printf("Spi start success! \n\r");
 }
 else
 {
  xil_printf("Spi start failed! \n\r");  
 }
 //*******************************************************************
 //Use polled mode and disable interrupt
 //*******************************************************************
 XSpi_mIntrGlobalDisable(&Spi);
 
 //check control reg
 Status = XSpi_mGetControlReg(&Spi);
 xil_printf("XSpi_mGetControlReg = : %x \n\r", Status);

 //*******************************************************************
 //Select the slave spi flash and read ID
 //******************************************************************* 
 //XSpi_mSetSlaveSelectReg(&Spi, 0xFE);
 XSpi_SetSlaveSelect(&Spi,0x01);//~SPI_FLASH_SELECT);

 send_data[0] = RDID;
 send_data[1] = RDID;
 send_data[2] = RDID;
 send_data[3] = RDID;
 Status = XSpi_Transfer(&Spi, send_data, recv_data, 4);
 
 do
 {
  Status = XSpi_mGetStatusReg(&Spi);
  xil_printf("XSpi_mGetStatusReg = : %x \n\r", Status);
 }
 while ((Status & 0x04) == 0);
 xil_printf("Manufacturer Code = : %x \n\r", recv_data[1]);
 xil_printf("Memory Type       = : %x \n\r", recv_data[2]);
 xil_printf("Memory Capacity   = : %x \n\r", recv_data[3]);

 xil_printf("M25P16 = 20, 20, 15\n\r");
 
 
 //*******************************************************************
 //Deselect the slave spi flash and abort the spi
 //******************************************************************* 
 XSpi_SetSlaveSelect(&Spi,0);//~SPI_NONE_SELECT);
 XSpi_Abort(&Spi);
 xil_printf("Serial Flash Test End!\n\r");
}

0 Kudos
2 Replies
ggancio
Visitor
Visitor
3,207 Views
Registered: ‎05-13-2010

Hi I just test your code and some times it works and others it freezes, did you find any solution?


Best regards.

0 Kudos
sha@hys
Explorer
Explorer
1,420 Views
Registered: ‎05-31-2015

Hi,

 

I am also facing same problem. Just getting FF instead of device ID. How did you solve it ?? Kindly reply . Thanks in advance.

 

 

Tags (2)
0 Kudos