element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
FPGA
  • Technologies
  • More
FPGA
Forum Zynq PS Spi and Quad Spi referance design tutorial Help
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join FPGA to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 0 replies
  • Subscribers 544 subscribers
  • Views 468 views
  • Users 0 members are here
  • c
  • zedboard
  • xilinx
  • spi
  • fpga
  • vivado
  • vitis
Related

Zynq PS Spi and Quad Spi referance design tutorial Help

brhn
brhn 8 months ago

I'm trying to make communicate between ps7_spi_0 and axi_quad_spi. This is block diagram. FCLK_CLK0 is 100 Mhz. SPI_0 is 166.666666 Mhz


image 

image


C code :

/*
 * helloworld.c: simple test application
 *
 * This application configures UART 16550 to baud rate 9600.
 * PS7 UART (Zynq) is not initialized by this application, since
 * bootrom/bsp configures it to baud rate 115200
 *
 * ------------------------------------------------
 * | UART TYPE   BAUD RATE                        |
 * ------------------------------------------------
 *   uartns550   9600
 *   uartlite    Configurable only in HW design
 *   ps7_uart    115200 (configured by bootrom/bsp)
 */

#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xspips.h"
#include "xspi.h"
#include "sleep.h"

#define SPI_DEVICE_ID		XPAR_XSPIPS_0_DEVICE_ID
#define QSPI_DEVICE_ID		XPAR_SPI_0_DEVICE_ID

static XSpiPs SpiInstance;
static XSpi 	Spi;

u16 TxBuffer[4];
u16 RxBuffer[4];

int main()
{
	XSpiPs_Config *SpiConfig;
	int Status,i;
	init_platform();
	int NumBytesRcvd;

    printf("SPI Example\n");

	SpiConfig = XSpiPs_LookupConfig(SPI_DEVICE_ID);
	if (NULL == SpiConfig) {
		return XST_FAILURE;
	}

	Status = XSpiPs_CfgInitialize(&SpiInstance, SpiConfig,SpiConfig->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	Status = XSpiPs_SelfTest(&SpiInstance);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	XSpiPs_SetOptions(&SpiInstance, XSPIPS_MASTER_OPTION | XSPIPS_FORCE_SSELECT_OPTION);

	XSpiPs_SetClkPrescaler(&SpiInstance, XSPIPS_CLK_PRESCALE_64);


	XSpi_Initialize( &Spi, QSPI_DEVICE_ID );
    Status = XSpi_SelfTest( &Spi );
    if (Status != XST_SUCCESS) {
    	return XST_FAILURE;
    }
    XSpi_Reset(&Spi);


    XSpi_Start(&Spi);
    XSpi_IntrGlobalDisable(&Spi);



	TxBuffer[0] = 0xa0a0;
	TxBuffer[1] = 0x0505;
	TxBuffer[2] = 0xa0a0;
	TxBuffer[3] = 0x0505;

	while (1) {
			XSpiPs_SetSlaveSelect(&SpiInstance, 0x00);
			Status = XSpiPs_Transfer(&SpiInstance, (u8*)&TxBuffer, (u8*)&RxBuffer, 8);
			if(Status != XST_SUCCESS) {
				printf("XSpiPs_Transfer failed\n")
			}


			NumBytesRcvd = 0;
			
			//XSpi_SetControlReg(&Spi,0x60);
			XSpi_WriteReg((SpiInstance.SpiConfig.BaseAddr), XSPIPS_TXD_OFFSET, TxBuffer[0]);
			XSpi_WriteReg((SpiInstance.SpiConfig.BaseAddr), XSPIPS_TXD_OFFSET, TxBuffer[1]);
			//XSpi_SetControlReg(&Spi,0x02);
			XSpi_WriteReg((SpiInstance.SpiConfig.BaseAddr), XSPIPS_TXD_OFFSET, TxBuffer[2]);
			XSpi_WriteReg((SpiInstance.SpiConfig.BaseAddr), XSPIPS_TXD_OFFSET, TxBuffer[3]);

			while (!(XSpi_ReadReg(Spi.BaseAddr, XSP_SR_OFFSET) & XSP_SR_TX_EMPTY_MASK));

			while ((XSpi_ReadReg(Spi.BaseAddr, XSP_SR_OFFSET) & 	XSP_SR_RX_EMPTY_MASK) == 0) {
				printf("In While\n");
				RxBuffer[NumBytesRcvd++] = XSpi_ReadReg((Spi.BaseAddr), XSP_DRR_OFFSET);
			}

			for(i=0;i<4;i++){
				printf("rx %04x \n", RxBuffer[i]);
			}
			usleep(1000000);
	}


    cleanup_platform();
    return 0;
}






Console (uart) out:

SPI Example
In While
In While
In While
In While
In While
In While
rx a0a0
rx 0505
rx a0a0
rx 0505
XSpiPs_Transfer failed
rx a0a0
rx 0505
rx a0a0
rx 0505
XSpiPs_Transfer failed
In While
In While
In While
In While
rx a005
rx a005
rx a005
rx a005
XSpiPs_Transfer failed
rx a005
rx a005
rx a005
rx a005
XSpiPs_Transfer failed
In While
In While
In While
In While
rx a005
rx a005
rx a005
rx a005

  • Sign in to reply
  • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube