0% found this document useful (0 votes)
24 views2 pages

GPIO Initialization and Data Transfer Code

The document is a C program that initializes GPIO drivers for PMOD A and PMOD B on a hardware platform. It sets up a PS GPIO pin for input and runs a loop that writes values to PMOD A while reading from PMOD B and the PS GPIO. The program outputs the values to the console for each iteration of the loop.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

GPIO Initialization and Data Transfer Code

The document is a C program that initializes GPIO drivers for PMOD A and PMOD B on a hardware platform. It sets up a PS GPIO pin for input and runs a loop that writes values to PMOD A while reading from PMOD B and the PS GPIO. The program outputs the values to the console for each iteration of the loop.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include "xparameters.

h"
#include "xgpio.h"
#include "xgpiops.h"
#include "xil_printf.h"

static XGpioPs psGpioInstancePtr;


#define PS_GPIO_bank 2

int main(void)
{
XGpio pmoda_o, pmodb_i;

XGpioPs_Config *PSConfigPtr;

int val, psval;


int Status;

xil_printf("--- Start the Program ---");

/* Initialize the GPIO drivers */


Status = XGpio_Initialize(&pmoda_o, XPAR_PMOD_A_O_BASEADDR);

if (Status != XST_SUCCESS) {
xil_printf("Gpio PMODA Initialization Failed\r\n");
return XST_FAILURE;
}

Status = XGpio_Initialize(&pmodb_i, XPAR_PMOD_B_I_BASEADDR);

if (Status != XST_SUCCESS) {
xil_printf("Gpio PMODB Initialization Failed\r\n");
return XST_FAILURE;
}

/* PS GPIO Initialization */

PSConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_BASEADDR);
if (PSConfigPtr == NULL)
return XST_FAILURE;

Status = XGpioPs_CfgInitialize(&psGpioInstancePtr,
&PSConfigPtr,
PSConfigPtr->BaseAddr);
if (Status != XST_SUCCESS) {
xil_printf("PS GPIO Initialization Failed\r\n");
return XST_FAILURE;
}

/* PS GPIO pin setting to Input */


XGpioPs_SetDirection(&psGpioInstancePtr, PS_GPIO_bank, 0);

/*Starting a counter */
for (int i=0; i<=255; i++){
/*Discreate Write pmoda_o*/
XGpio_DiscreteWrite(&pmoda_o, 1, i);
/*Discreate read pmodb*/
val=XGpio_DiscreteRead(&pmodb_i, 1);
psval=XGpioPs_Read(&psGpioInstancePtr, PS_GPIO_bank);
xil_printf("PMODA Output: %d, PMODB Receive: %d PSGPIO Receive
%d\n\r",i,val, psval);
}

You might also like