AXI quad SPI没有输出
AXI quad SPI沒(méi)有輸出(已解決)
在使用ZYNQ的AXI quad SPI時(shí)遇到以下問(wèn)題:
使用loopback可以成功,但是使用示波器測(cè)量引腳卻沒(méi)有輸出。
問(wèn)題描述:
最近在用ZYNQ的AXI quad SPI拓展接口,卻遇到了這個(gè)問(wèn)題:
添加AXI quad SPI核,編譯完畢后。使用官方例程,loopback模式可以跑通,但是正常輸出模式無(wú)法工作,且用示波器測(cè)試引腳輸出沒(méi)有波形。
IP核AXI quad SPI的設(shè)置如下:
程序?yàn)锳XI quad SPI官方的 xspi_polled_example:
/***************************** Include Files *********************************/#include "xparameters.h" /* XPAR parameters */ #include "xspi.h" /* SPI device driver */ #include "xspi_l.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 12/**************************** Type Definitions *******************************//** The following data type is used to send and receive data on the SPI* interface.*/ typedef u8 DataBuffer[BUFFER_SIZE];/***************** 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[BUFFER_SIZE]; u8 WriteBuffer[BUFFER_SIZE];/*****************************************************************************/ /** * * 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) {xil_printf("Spi polled Example Failed\r\n");return XST_FAILURE;}xil_printf("Successfully ran Spi 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 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;}/** Run loopback test only in case of standard SPI mode.*/if (SpiInstancePtr->SpiMode != XSP_STANDARD_MODE) {return XST_SUCCESS;}/** Set the Spi device as a master and in loopback mode.*/Status = XSpi_SetOptions(SpiInstancePtr, XSP_MASTER_OPTION |XSP_LOOPBACK_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 it can be verified after the read, the* Test value that is added to the unique value allows the value to be* changed in a debug environment.*/Test = 0x10;for (Count = 0; Count < BUFFER_SIZE; Count++) {WriteBuffer[Count] = (u8)(Count + Test);ReadBuffer[Count] = 0;}/** Transmit the data.*/XSpi_Transfer(SpiInstancePtr, WriteBuffer, ReadBuffer, BUFFER_SIZE);/** Compare the data received with the data that was transmitted.*/for (Count = 0; Count < BUFFER_SIZE; Count++) {if (WriteBuffer[Count] != ReadBuffer[Count]) {return XST_FAILURE;}}return XST_SUCCESS; }編譯下載之后,串口提示運(yùn)行成功,
將loopback模式關(guān)閉,設(shè)置為禁止loopback,CPOL = 1 CPHA = 1。
然后,把mosi引腳和miso引腳短接。然后編譯、下載,提示運(yùn)行錯(cuò)誤
使用示波器測(cè)量SCK、mosi引腳,發(fā)現(xiàn)沒(méi)有波形。
原因分析:
然后在Xilinx的論壇上發(fā)現(xiàn)也有人反饋這個(gè)問(wèn)題,最后原因好像是:
因?yàn)镾S0的引腳一直輸出是高電平引起的,我后來(lái)將程序修改為持續(xù)向SPI發(fā)送數(shù)據(jù),發(fā)現(xiàn)確實(shí)是SS0引腳一直是高電平(剛燒寫完程序,SS0也會(huì)持續(xù)一段時(shí)間的高電平)。
個(gè)人認(rèn)為可能是SPI自動(dòng)選擇從機(jī)編號(hào)發(fā)生了問(wèn)題。
解決方案:
參考論壇中的解決方法,具體解決方案:
將從機(jī)選擇設(shè)置為手動(dòng)選擇(XSP_MANUAL_SSELECT_OPTION)
然后再在SPI禁止中斷語(yǔ)句之后,加入選擇從機(jī)編號(hào)的語(yǔ)句。(1號(hào)從機(jī)的選擇引腳就是SS0)
/** Disable Global interrupt to use polled mode operation*/XSpi_IntrGlobalDisable(SpiInstancePtr);XSpi_SetSlaveSelect(SpiInstancePtr, 0x01); //選擇從機(jī)編號(hào)經(jīng)過(guò)以上修改后,再次編譯燒寫,程序運(yùn)行正確。
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的AXI quad SPI没有输出的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: VHDL的数据对象(学习笔记1)
- 下一篇: ZYNQ中断示例修改