cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
manimpa
Visitor
Visitor
10,069 Views
Registered: ‎02-04-2016

How to Program GPIO Interrupts on Artix 7 with microblaze

Hi, im student and i have some problems with the SDK on VIVADO

I`m trying to do a GPIO Interrupt on Artix 7. This is my desing on Vivado.

1.PNG

I have programed correctly the GPIO ports using the dipswitches on the SDK but when i program the interrupts, especially initializing the REGISTER INTERRUPT HANDLER, ENABLING INTERRUPTS.

The Gpio_0 are the dipswitches, the dipswitches and the leds work perfectly in the code.

 

this is my code, the blue words is the code that i have problems:


#include "platform.h"
#include <stdio.h>
#include "xio.h"
#include "xil_types.h"
#include "xparameters.h"
#include "mb_interface.h"
#include "xil_exception.h"
#include "xintc.h"
#include "xgpio.h"
#include "xgpio_l.h"

//declare an XGpio and XGpio instance
XGpio GPIO_0;
XGpio_Config GPIO_0_conf;

unsigned X=0;

XIntc Intc;
XGpio Gpio;

void interrupcion(void *InstancePtr); //__attribute__((fast_interrupt));

 

int main(void)
{
init_platform();

 

////-------------------------------------------------------
// Inizilalizar GPIO
//----------------------------------------------------
GPIO_0_conf.BaseAddress = XPAR_AXI_GPIO_0_BASEADDR;
GPIO_0_conf.DeviceId = XPAR_AXI_GPIO_0_DEVICE_ID;
GPIO_0_conf.InterruptPresent = XPAR_GPIO_0_INTERRUPT_PRESENT;
GPIO_0_conf.IsDual = XPAR_GPIO_0_IS_DUAL;

//----------------------------------------------------
// REGISTER INTERRUPT HANDLER
//----------------------------------------------------
print(" - Registering interrupt handler\r\n");
XIntc_Initialize(&Intc, XPAR_MICROBLAZE_0_AXI_INTC_BASEADDR);
XIntc_Connect(&Intc, XPAR_MICROBLAZE_0_AXI_INTC_AXI_GPIO_0_IP2INTC_IRPT_INTR,
(XInterruptHandler)interrupcion, &Gpio);

 

print("Hello World\n\r");

u32 input;

//----------------------------------------------------
// ENABLE INTERRUPTS
//----------------------------------------------------
print(" - Enabling interrupts\r\n");

XGpio_InterruptEnable(&GPIO_0,0X000001);//BUTTON_INTERRUPT
XGpio_InterruptGlobalEnable(&GPIO_0);

print("paso");

 

XIntc_Enable(&Intc, XPAR_GPIO_0_INTERRUPT_PRESENT);

 

//Enable Microblaze interrupts
microblaze_enable_interrupts();

 

while(1){

//Read the switches values
input = XGpio_DiscreteRead(&GPIO_0, 1);
xil_printf("\n%X",input);
//if SW0 is 1
if(input == 0x00000001){
//Set all LEDs to 1
XGpio_DiscreteWrite(&GPIO_0, 2, 0x0000FFF0);
//Set the MicroBlaze to sleep for 1 second
//MB_Sleep(1000);
//Set all LEDs to 0
//XGpio_DiscreteWrite(&GPIO_0, 1, 0x00000000);
//MB_Sleep(1000);
}
if(input==0x00000000){XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000000);}
xil_printf("\n%X OPS",X);
}

cleanup_platform();
return 0;
}


void interrupcion(void *InstancePtr)
{
XGpio *GpioPtr = (XGpio *)InstancePtr;
/*
* Disable the interrupt
*/
// XGpio_InterruptDisable(GpioPtr,0X000001);
X = X + 1;
xil_printf("\n%X",X);
/*
* Enable the interrupt
*/
// XGpio_InterruptEnable(GpioPtr,0X000001);
return;
}

 

 
I appreciate your help, also if you could provide me an example using GPIO and interrupts.
0 Kudos
2 Replies
pvenugo
Moderator
Moderator
9,774 Views
Registered: ‎07-31-2012

Hi,

 

What is the issue you are encountering as it is not mentioned in your post?

The example for GPIO interrupts is attached. Please refer to it.

 

Regards

Praveen


-------------------------------------------------------------------------
Don’t forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
0 Kudos
manimpa
Visitor
Visitor
9,527 Views
Registered: ‎02-04-2016

I have some trouble in the part where i defined the GPIO_DEVICED_ID in the sdk it appear as undeclared, and i have searched a similar declaration on xparameters.h but i cant find one that could be useful for the push bottons.

 

This is my hardware:

Captura.PNG

This is the line where is the problem on my code:

Captura2.PNG 

0 Kudos