cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
geraldo16
Visitor
Visitor
3,954 Views
Registered: ‎08-31-2016

External Interrupt problem with microblaze

Hi,

I am trying to build a proyect in Vivado 2016.2, able to troggle a led from my Basys 3 board, trough an external interrupt. I am using a microblaze and writing my code in SDK. I am not pretty sure whats the problem, I am able to handle de led GPIO but I cant generate the interrupt. 

I am attaching an image of my desing and below is my code in sdk. I am building an empty project in sdk.

 

/*
* main.c
*
* Created on: 31/08/2016
* Author: condorito
*/
/*
* main.c
*
* Created on: 31/08/2016
* Author: condorito
*/
//#include <stdio.h>
#include "xparameters.h"
#include <xgpio.h>
#include <xintc.h>
#include <xil_exception.h>

static XIntc myIntc;

//declare an XGpio and XGpio instance
//leds
//XGpio GPIO_1;
//XGpio_Config GPIO_1_conf;

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


void pb_int_handler(void *baseaddr_p) {
//u32 dsr;
XGpio_InterruptDisable(&GPIO_0, 0xFFFFFFFF);
//DSR contains the INFORMATION of which button was depressed, so we can switch
//on its value.
//dsr = XGpio_DiscreteRead(&GPIO_0, 1);
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
/*switch(dsr) {

case 0x01:
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
break;

case 0x02:
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000002);
break;

case 0x03:
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000003);
break;

//case 0x08:
//XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000004);
//break;

default : {}

}*/
//Clear the interrupt both in the Gpio instance as well as the interrupt controller

XIntc_Acknowledge(&myIntc, XPAR_MICROBLAZE_0_AXI_INTC_AXI_GPIO_0_IP2INTC_IRPT_INTR);
XGpio_InterruptEnable(&GPIO_0, 0xFFFFFFFF);
}

int main(void) {
int status = 0;
//******************************************************************************
//Configuración 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;

//Initialize the XGpio instance
XGpio_CfgInitialize(&GPIO_0, &GPIO_0_conf, GPIO_0_conf.BaseAddress);
//******************************************************************************

//******************************************************************************
//Configuración interrupción
//XGpio_SetDataDirection(&GPIO_0,1,0); //declara el canal 2 como salida
XGpio_InterruptGlobalEnable(&GPIO_0);
XGpio_InterruptEnable(&GPIO_0, 0xFF);

//XIntc_Initialize(&myIntc, GPIO_0_conf.BaseAddress);
status = XIntc_Initialize(&myIntc, GPIO_0_conf.DeviceId);
if (status != XST_SUCCESS)
{
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
}

status = XIntc_Connect(&myIntc, XPAR_MICROBLAZE_0_AXI_INTC_DEVICE_ID,(XInterruptHandler)pb_int_handler,&GPIO_0);
if (status != XST_SUCCESS)
{
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
}

//XIntc_EnableIntr(&myIntc,GPIO_0_conf.DeviceId);
XIntc_EnableIntr(&myIntc,0xFFFFFFFF);

status = XIntc_Start(&myIntc, XIN_REAL_MODE);
if (status != XST_SUCCESS)
{
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
}
XIntc_MasterEnable(&myIntc);
microblaze_enable_interrupts();
//******************************************************************************

//******************************************************************************
Xil_ExceptionInit();

Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_M_AXI_I_EXCEPTION,
(XExceptionHandler)XIntc_InterruptHandler,
&myIntc);
Xil_ExceptionEnable();

while(1)
{
//XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
//delay = 1;
}
//******************************************************************************
return 0;
}

Esquema.jpg
0 Kudos
3 Replies
austin
Scholar
Scholar
3,908 Views
Registered: ‎02-27-2008

g,

 

Hard to read, but it looks like you are using the dip switch for interrupt?

 

Have you tried simply reading the switch and connecting it to the led (no MicroBlaze, no software, just the hardware itself)?

 

 

Austin Lesea
Principal Engineer
Xilinx San Jose
0 Kudos
geraldo16
Visitor
Visitor
3,901 Views
Registered: ‎08-31-2016

Sorry about that, I am a beginer and my coding habilities are not that good. What I am trying to do is to generate an interruption from the dip switches, and reflect that in the leds. Now I am able to trigger the interrupt, but just once. I have made some modifications to my code based on this example.

 

https://forums.xilinx.com/xlnx/attachments/xlnx/EMBEDDED/17456/1/xgpio_intr_tapp_example.c

 

Now my code looks like this

 

//#include <stdio.h>
#include "xparameters.h"
#include <xgpio.h>
#include <xintc.h>
#include <xil_exception.h>

static XIntc myIntc;
int control = 1;

//declare an XGpio and XGpio instance
//leds
//XGpio GPIO_1;
//XGpio_Config GPIO_1_conf;

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


void pb_int_handler(void *baseaddr_p) {
u32 dsr;
//XGpio_InterruptDisable(&GPIO_0, 1);
//XIntc_Disable(&myIntc,XPAR_INTC_0_GPIO_0_VEC_ID);
//XGpio_DiscreteWrite(&GPIO_0, 2, control);
//control++;
dsr = XGpio_DiscreteRead(&GPIO_0,1);
XGpio_DiscreteWrite(&GPIO_0, 2, dsr);
/*if(control == 1)
{
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
control = 0;
}
else
{
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000000);
control = 1;
}*/
//XIntc_Acknowledge(&myIntc, XPAR_MICROBLAZE_0_AXI_INTC_AXI_GPIO_0_IP2INTC_IRPT_INTR);
//XGpio_InterruptEnable(&GPIO_0, 1);
//XIntc_Enable(&myIntc,XPAR_INTC_0_GPIO_0_VEC_ID);
}

int main(void) {
int status = 0;
//******************************************************************************
//Configuración 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;

//Initialize the XGpio instance
XGpio_CfgInitialize(&GPIO_0, &GPIO_0_conf, GPIO_0_conf.BaseAddress);
XGpio_SetDataDirection(&GPIO_0,2,0); //declara el canal 2 como salida
//******************************************************************************

//******************************************************************************
//Configuración interrupción


//Inicialización
status = XIntc_Initialize(&myIntc, XPAR_INTC_0_DEVICE_ID);
if (status != XST_SUCCESS)
{
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
}

//Conexión
status = XIntc_Connect(&myIntc, XPAR_INTC_0_GPIO_0_VEC_ID,(XInterruptHandler)pb_int_handler,&GPIO_0);
if (status != XST_SUCCESS)
{
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
}

//Habilitación Interrupción
//XIntc_EnableIntr(&myIntc,GPIO_0_conf.DeviceId);
XIntc_Enable(&myIntc,XPAR_INTC_0_GPIO_0_VEC_ID);

//Arranque controlador
status = XIntc_Start(&myIntc, XIN_REAL_MODE);
if (status != XST_SUCCESS)
{
XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
}
XIntc_MasterEnable(&myIntc);
microblaze_enable_interrupts();

//******************************************************************************
//Habilitar interrupción en GPIO
XGpio_InterruptGlobalEnable(&GPIO_0);
XGpio_InterruptEnable(&GPIO_0, 1);
//******************************************************************************
Xil_ExceptionInit();

Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_M_AXI_I_EXCEPTION,
(XExceptionHandler)XIntc_InterruptHandler,
&myIntc);
Xil_ExceptionEnable();

while(1)
{
//XGpio_DiscreteWrite(&GPIO_0, 2, 0x00000001);
//delay = 1;
}
//******************************************************************************
return 0;
}

 I also attach a picture of my design, I am using a GPIO for controling the dip switches in GPIO_0 and two leds (0 and 1) from my Basys 3 board. The idea is move any dip switch and turn the leds on and of. Thnaks for the reply.

Diagram.jpg
0 Kudos
geraldo16
Visitor
Visitor
3,900 Views
Registered: ‎08-31-2016

Sorry i forgot to answer the question, what I am looking for is to handle the interrupt, so I am trying to develop a simple example with dip switches and leds, but the real problem is handle the interrupt. 

0 Kudos