I have some code that I have written trying to get an led to turn on when a switch on my arty z7-10 board is pressed. It builds okay in SDK but doesn't execute.
Can anyone help me trouble shoot please?
#include "xparameters.h"
#include "xgpio.h"
#include "xil_printf.h"
#define LED 0x01
#define SWITCH 0x01 //connects bit 0 of gpio channels to led and switch
#define GPIO_EXAMPLE_DEVICE_ID XPAR_GPIO_0_DEVICE_ID
#define LED_CHANNEL 1
#define SWITCH_CHANNEL 2 //defines the channels they are on
XGpio Gpio,input, output;
int main(void)
{
int Status;
int SWITCH_data = 0;
/* Initialize the GPIO driver */
Status = XGpio_Initialize(&Gpio, GPIO_EXAMPLE_DEVICE_ID);
if (Status != XST_SUCCESS) {
xil_printf("Gpio Initialization Failed\r\n");
return XST_FAILURE;
}
XGpio_SetDataDirection(&input, SWITCH_CHANNEL, SWITCH);
XGpio_SetDataDirection(&output, LED_CHANNEL, LED);
while (1) {
SWITCH_data = XGpio_DiscreteRead(&input, SWITCH);
XGpio_DiscreteWrite(&output, LED, SWITCH_data); /*i think that the third column is the data to write to output.*/
if(SWITCH_data == 0b0000){} //do nothing
else if(SWITCH_data == 0b0001)
xil_printf("switch pressed\n\r");
}
xil_printf("Successfully ran Gpio Example\r\n");
return XST_SUCCESS;
}
Also I have my constraints file written correctly, and I have attatched a picture of my block diagram. Thanks!!
Question
dmeads_10
Hi folks!
New to zynq and programming in C.
I have some code that I have written trying to get an led to turn on when a switch on my arty z7-10 board is pressed. It builds okay in SDK but doesn't execute.
Can anyone help me trouble shoot please?
#include "xparameters.h" #include "xgpio.h" #include "xil_printf.h" #define LED 0x01 #define SWITCH 0x01 //connects bit 0 of gpio channels to led and switch #define GPIO_EXAMPLE_DEVICE_ID XPAR_GPIO_0_DEVICE_ID #define LED_CHANNEL 1 #define SWITCH_CHANNEL 2 //defines the channels they are on XGpio Gpio,input, output; int main(void) { int Status; int SWITCH_data = 0; /* Initialize the GPIO driver */ Status = XGpio_Initialize(&Gpio, GPIO_EXAMPLE_DEVICE_ID); if (Status != XST_SUCCESS) { xil_printf("Gpio Initialization Failed\r\n"); return XST_FAILURE; } XGpio_SetDataDirection(&input, SWITCH_CHANNEL, SWITCH); XGpio_SetDataDirection(&output, LED_CHANNEL, LED); while (1) { SWITCH_data = XGpio_DiscreteRead(&input, SWITCH); XGpio_DiscreteWrite(&output, LED, SWITCH_data); /*i think that the third column is the data to write to output.*/ if(SWITCH_data == 0b0000){} //do nothing else if(SWITCH_data == 0b0001) xil_printf("switch pressed\n\r"); } xil_printf("Successfully ran Gpio Example\r\n"); return XST_SUCCESS; }
Also I have my constraints file written correctly, and I have attatched a picture of my block diagram. Thanks!!
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.