cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dimpy
Adventurer
Adventurer
295 Views
Registered: ‎06-05-2020

AXI Quad SPI as Slave

Hello Support team,

I am new to AXI quad spi. I have make the design for SPI slave. I am trying to get data from the external device which is master. Please find the below attached block diagram for same. 

dimpy_0-1618209567354.png

I have following the below process steps:

1) create block diagram in vivado for AXI quad spi with debug core.

2) Synthesized and implemented the design successfully.

3) Open the implemented design and route the four spi signal to FPGA J58 PMOD header.

4) Generate the bitstream successfully.

5) Export the hardware and launch the SDK.

6) Create the application project as hello world and paste the below code for SPI.

 

/***************************** Include Files *********************************/

#include "xparameters.h" /* XPAR parameters */
#include "xspi.h" /* SPI device driver */
#include "stdio.h"
#include "xil_printf.h"

/************************** Constant Definitions *****************************/

/*
* The following constants map to the XPAR parameters created in the
* xparameters.h file. They are defined here such that a user can easily
* change all the needed parameters in one place.
*/
#define SPI_DEVICE_ID XPAR_SPI_0_DEVICE_ID

/*
* This is the size of the buffer to be transmitted/received in this example.
*/
#define BUFFER_SIZE 2

/**************************** Type Definitions *******************************/


/***************** Macros (Inline Functions) Definitions *********************/


/************************** Function Prototypes ******************************/

static int SpiSlavePolledExample(XSpi *SpiInstancePtr, u16 SpiDeviceId);

/************************** Variable Definitions *****************************/

/*
* The instances to support the device drivers are global such that they are
* initialized to zero each time the program runs. They could be local but
* should at least be static so that they are zeroed.
*/
static XSpi SpiInstance; /* The instance of the SPI device */

/*
* The following variables are used to read from the Spi device, these are
* global to avoid having large buffers on the stack.
*/
u8 ReadBuffer[BUFFER_SIZE];
u8 WriteBuffer[BUFFER_SIZE];

/*
* The following variable allows a test value to be added to the values that
* are sent in reflection to the Master transmission such that unique values can
* be generated to guarantee the transfer from Slave to Master is successful.
*/
int Test;

/*****************************************************************************/
/**
*
* Main function to call the Spi Slave example in polled mode.
*
* @param None
*
* @return XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note None
*
******************************************************************************/
int main(void)
{
int Status;

/*
* Run the Spi Slave polled example.
*/
Status = SpiSlavePolledExample(&SpiInstance, SPI_DEVICE_ID);
if (Status != XST_SUCCESS) {
xil_printf("Spi slave polled Example Failed\r\n");
return XST_FAILURE;
}

xil_printf("Successfully ran Spi slave polled Example\r\n");
return XST_SUCCESS;
}

/*****************************************************************************/
/**
*
* This function does a minimal test on the Spi device and driver as a design
* example. The purpose of this function is to illustrate the device slave
* functionality in polled mode. This function receives data from a master and
* prints the received data.
*
* @param SpiInstancePtr is a pointer to the instance of Spi component.
*
* @param SpiDeviceId is the Device ID of the Spi Device and is the
* XPAR_<SPI_instance>_DEVICE_ID value from xparameters.h.
*
* @return XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note This function contains an infinite loop such that if the Spi
* device doesn't receive any data, it may never return.
*
******************************************************************************/
int SpiSlavePolledExample(XSpi *SpiInstancePtr, u16 SpiDeviceId)
{
XSpi_Config *ConfigPtr;
int Status;
u32 Count;

xil_printf("\r\nEntering the Spi Slave Polled Example.\r\n");
xil_printf("Waiting for data from SPI master\r\n");

/*
* Initialize the SPI driver so that it's ready to use, specify the
* device ID that is generated in xparameters.h.
*/
ConfigPtr = XSpi_LookupConfig(SpiDeviceId);
if (ConfigPtr == NULL) {
return XST_FAILURE;
}
Status = XSpi_CfgInitialize(SpiInstancePtr, ConfigPtr,
ConfigPtr->BaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

/*
* The SPI device is a slave by default and the clock phase and polarity
* have to be set according to its master. In this example, CPOL is set
* to active low and CPHA is set to 1.
*/
Status = XSpi_SetOptions(SpiInstancePtr, XSP_CLK_PHASE_1_OPTION |
XSP_CLK_ACTIVE_LOW_OPTION);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

/*
* Start the SPI driver so that the device is enabled.
*/
XSpi_Start(SpiInstancePtr);

/*
* Disable Global interrupt to use polled mode operation.
*/
XSpi_IntrGlobalDisable(SpiInstancePtr);


/*
* Initialize the write buffer with pattern to write, initialize the
* read buffer to zero so that it can be verified after the read.
*/
Test = 0xF0;
for (Count = 0; Count < BUFFER_SIZE; Count++) {
WriteBuffer[Count] = (u8)(Count + Test);
ReadBuffer[Count] = 0;
}

/*
* Prepare the data buffers for transmission and to send/receive data
* when the SPI device is selected by a master.
*/
XSpi_Transfer(SpiInstancePtr, WriteBuffer, ReadBuffer, BUFFER_SIZE);

/*
* Print all the data received from the master so that it can be
* compared with the data sent by the master.
*/
xil_printf("\r\nReceived data is:\r\n");
for (Count = 0; Count < BUFFER_SIZE; Count++) {
xil_printf("0x%x \r\n", ReadBuffer[Count]);
}

xil_printf("\r\nExiting the Spi Slave Polled Example.\r\n");

return XST_SUCCESS;
}

 

7) After it i have program the FPGA and debug the configuration.

I am able see the correct output on the UART terminal.

9) Go to vivado design suite and open the hardware manager and connect the hardware there i am able to see hw_ILA window. 

Here i am not getting any clock on the ILA window not even any data.

My questions is:

1) Am i following the right approach?

2) If yes how can i check the spi signal on the debug core?

3) Even i am not getting any output on the oscilloscope what is the problem here?

Please reply as soon as possible.

Thank you.

 

0 Kudos
2 Replies
dimpy
Adventurer
Adventurer
230 Views
Registered: ‎06-05-2020

Hello @sabankocal 

Please guide me.

Thank you.

0 Kudos
sabankocal
Voyager
Voyager
225 Views
Registered: ‎08-02-2019

Hi @dimpy ,

Unfortunatelly I have never used AXI Quad SPI Ip Core before, but I'll try to help you.

If you are really sure if (WriteBuffer[Count] != ReadBuffer[Count]) all incoming and outgoing data is equals then I can say SPI works.

To be sure you can set a breakpoint at this line and look content of 2 arrays.(WriteBuffer, ReadBuffer)

You say, I can not see any clock on ILA. It is completely ILA related issue.
If you see only black screen and you can not add any probes on ILA you have ILA related problem and you can find a lot of thread related with ILA can not show anything...

To Solve that issue, I can suggest:

- Firstly be sure you are adding probes by using + button

- Remove hw folder contents on your project folder.(project1.hw ...)
- Re program fpga, be sure really there is bit file and debug file(.ltx) at related folder and check its date to be sure.

...
Saban

 

<--- If reply is helpful, please feel free to give Kudos, and close if it answers your question --->