Jump to content

harrisjd

Digilent Staff
  • Posts

    7
  • Joined

  • Last visited

About harrisjd

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

1,535 profile views

harrisjd's Achievements

Newbie

Newbie (1/4)

2

Reputation

  1. hi can you help me to integrate PMODad1 to cora z7,   i wrote program 

    #include <stdio.h>
    #include <xparameters_ps.h>
    #include "platform.h"
    #include "xil_printf.h"

    #include "xparameters.h"
    #include "xspi.h"
    #include "xspi_l.h"
    #include "sleep.h"

    #define SPI_DEVICE_ID  XPAR_AXI_QUAD_SPI_0_BASEADDR
    #define SPI_CLOCK_HZ 1000000 // 1 MHz
    #define AXI_CLOCK_FREQ_HZ 100000000 // 100 MHz, typical for Zynq

    #define BUFFER_SIZE 2
    #define CS 0x01 // Assuming single SPI slave

    XSpi SpiInstance; // SPI device instance

    int SpiInit(u16 DeviceId);
    int SpiReceiveData(u8 *ReceiveBuffer, int ByteCount);


    int main()
    {
        init_platform();
     
        int Status;
        u8 ReceiveBuffer[BUFFER_SIZE];
        int X;

        xil_printf("Starting SPI Data Reception from Pmod AD1\r\n");

        // Initialize the SPI driver
        Status = SpiInit(SPI_DEVICE_ID);
        if (Status != XST_SUCCESS) {
            xil_printf("SPI Initialization Failed\r\n");
            return XST_FAILURE;
        }

        while (1) {
            // Receive data from ADC
            Status = SpiReceiveData(ReceiveBuffer, BUFFER_SIZE);
            if (Status != XST_SUCCESS) {
                xil_printf("SPI Reception Failed\r\n");
                return XST_FAILURE;
            }

            // Convert received bytes to 12-bit ADC value
            X = (ReceiveBuffer[0] << 8) | ReceiveBuffer[1];

            // Print the received data
            xil_printf("X = %d\r\n", X);

            // Add a delay to avoid overwhelming the console
            usleep(100000); // 100 ms delay
        }

        return XST_SUCCESS;

        cleanup_platform();
        return 0;
    }

    int SpiInit(u16 DeviceId)
    {
        XSpi_Config *Config;
        int Status;

        // Lookup configuration for the SPI device
        Config = XSpi_LookupConfig(DeviceId);
        if (NULL == Config) {
            return XST_FAILURE;
        }

        // Initialize the SPI driver
        Status = XSpi_CfgInitialize(&SpiInstance, Config, Config->BaseAddress);
        if (Status != XST_SUCCESS) {
            return XST_FAILURE;
        }

        // Perform a self-test to check hardware build
        Status = XSpi_SelfTest(&SpiInstance);
        if (Status != XST_SUCCESS) {
            return XST_FAILURE;
        }

        // Set the SPI device as master
        XSpi_SetOptions(&SpiInstance, XSP_MASTER_OPTION | XSP_CLK_PHASE_1_OPTION | XSP_CLK_ACTIVE_LOW_OPTION);

        // Set the SPI clock frequency
        XSpi_SetOptions(&SpiInstance, AXI_CLOCK_FREQ_HZ);

        // Start the SPI device
        XSpi_Start(&SpiInstance);

        // Disable global interrupt
        XSpi_IntrGlobalDisable(&SpiInstance);

        return XST_SUCCESS;
    }

     
    int SpiReceiveData(u8 *ReceiveBuffer, int ByteCount)
    {
        int Status;
        u8 SendBuffer[BUFFER_SIZE] = {0, 0}; // Send dummy bytes to read data

        // Assert the SPI chip select
        XSpi_SetSlaveSelect(&SpiInstance, CS);

        // Transfer data over SPI
        Status = XSpi_Transfer(&SpiInstance, SendBuffer, ReceiveBuffer, ByteCount);
        if (Status != XST_SUCCESS) {
            return XST_FAILURE;
        }

        // Deassert the SPI chip select
        XSpi_SetSlaveSelect(&SpiInstance, 0x00);

        return XST_SUCCESS;
    }

    with flowing HW design 

    image.thumb.png.f21e583f8567b01aebdc14a333f40e21.png

     

    ## Pmod Header JA
    set_property -dict { PACKAGE_PIN Y18   IOSTANDARD LVCMOS33 } [get_ports {shield_spi_ss_io }]; #IO_L17P_T2_34 Sch=ja_p[1]
    set_property -dict { PACKAGE_PIN Y19   IOSTANDARD LVCMOS33 } [get_ports { shield_spi_io1_io  }]; #IO_L17N_T2_34 Sch=ja_n[1]
    set_property -dict { PACKAGE_PIN Y16   IOSTANDARD LVCMOS33 } [get_ports {shield_spi_io0_io }]; #IO_L7P_T1_34 Sch=ja_p[2]
    set_property -dict { PACKAGE_PIN Y17   IOSTANDARD LVCMOS33 } [get_ports {shield_spi_sck_io }]; #IO_L7N_T1_34 Sch=ja_n[2]

     

     

     

    image.thumb.png.01bf7862021bfa6c9437b95f50990653.png

     

     

    But it does not work 

     

    result 

    image.png.cec96f8ae5b5e9c78635dced71ae9622.png

     

×
×
  • Create New...