beginner_EDA
Full Member level 4
Hi,
How to configure Xilinx SPI IP as Slave.
https://www.xilinx.com/support/docu...tion/axi_quad_spi/v3_2/pg153-axi-quad-spi.pdf
As mentioned in page 84, I unchecked "Enable master mode" and using standard configuration. See Block diagram in attachment.
I don't want to write SPI flash but just to communicate with external spi Master.
and use following code.
It is also not clear to me, what is difference between
XSpi_Transfer(SpiInstancePtr, WriteBuffer, ReadBuffer, 1);
XSpi_Transfer(SpiInstancePtr, ReadBuffer, ReadBuffer, 1);
and
XSpi_WriteReg(BaseAddress, RegOffset, RegisterValue);
XSpi_ReadReg(BaseAddress, RegOffset);
to read and write?
When we use which one?
How to configure Xilinx SPI IP as Slave.
https://www.xilinx.com/support/docu...tion/axi_quad_spi/v3_2/pg153-axi-quad-spi.pdf
As mentioned in page 84, I unchecked "Enable master mode" and using standard configuration. See Block diagram in attachment.
I don't want to write SPI flash but just to communicate with external spi Master.
and use following code.
Code:
******************************************************************************/
/***************************** Include Files *********************************/
#include "xparameters.h" /* XPAR parameters */
#include "xspi.h" /* SPI device driver */
#include "xspi_l.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
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
int SpiPolledExample(XSpi *SpiInstancePtr, u16 SpiDeviceId);
/************************** Variable Definitions *****************************/
/*
* The instances to support the device drivers are global such that the
* are initialized to zero each time the program runs.
*/
static XSpi SpiInstance; /* The instance of the SPI device */
/*
* The following variables are used to read and write to the Spi device, they
* are global to avoid having large buffers on the stack.
*/
u8 ReadBuffer;
u8 WriteBuffer;
/*****************************************************************************/
/**
*
* Main function to call the Spi Polled example.
*
* @param None
*
* @return XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note None
*
******************************************************************************/
int main(void)
{
int Status;
/*
* Run the Spi Polled example.
*/
Status = SpiPolledExample(&SpiInstance, SPI_DEVICE_ID);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
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 how to use
* the XSpi component using the polled mode.
*
* This function sends data and expects to receive the same 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 is not
* working it may never return.
*
******************************************************************************/
int SpiPolledExample(XSpi *SpiInstancePtr, u16 SpiDeviceId)
{
int Status;
u32 Count;
u8 Test;
XSpi_Config *ConfigPtr; /* Pointer to Configuration data */
/*
* Initialize the SPI driver so that it is ready to use.
*/
ConfigPtr = XSpi_LookupConfig(SpiDeviceId);
if (ConfigPtr == NULL) {
return XST_DEVICE_NOT_FOUND;
}
Status = XSpi_CfgInitialize(SpiInstancePtr, ConfigPtr,
ConfigPtr->BaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
/*
* Perform a self-test to ensure that the hardware was built correctly.
*/
Status = XSpi_SelfTest(SpiInstancePtr);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
//xil_printf("xyz\n\r");
}
/*
* Run loopback test only in case of standard SPI mode.
*/
if (SpiInstancePtr->SpiMode != XSP_STANDARD_MODE) {
return XST_SUCCESS;
//xil_printf("xyz\n\r");
}
/*
* Set the Spi device as salve see page 25 and 26
*/
XSpi_SetControlReg(&Spi, 0x02);
/*
* Start the SPI driver so that the device is enabled.
*/
XSpi_Start(SpiInstancePtr);
/*
* Disable Global interrupt to use polled mode operation
*/
XSpi_IntrGlobalDisable(SpiInstancePtr);
/*
/*
* Transmit/receive the 1 byte of data.
*/
XSpi_Transfer(SpiInstancePtr, WriteBuffer, ReadBuffer, 1);
It is also not clear to me, what is difference between
XSpi_Transfer(SpiInstancePtr, WriteBuffer, ReadBuffer, 1);
XSpi_Transfer(SpiInstancePtr, ReadBuffer, ReadBuffer, 1);
and
XSpi_WriteReg(BaseAddress, RegOffset, RegisterValue);
XSpi_ReadReg(BaseAddress, RegOffset);
to read and write?
When we use which one?