cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
llqk
Visitor
Visitor
3,432 Views
Registered: ‎08-14-2012

Call for help on UartLite Interrupt: Handler called but couldn't receive the input

Jump to solution

Hi, Experts:

Please help to take a look at the following code.

I intended to show 1 char of the input string every time the handler was called.

But it didn't work the way as I expected.

Could you please tell me what's the problem?

Is that because the interrupt was not acknowledged in the handler?

But even if I added the acknowledgment it still behave the same way.

Thanks,

Abraham

 

****************************************************************************

#include "xparameters.h"
#include "xintc.h"
#include "xil_exception.h"
#include <stdio.h>
#include "xbasic_types.h"
#include "xuartlite.h"
#include "xuartlite_l.h"

void *CtrUartLite_ISR(void);

static XIntc intc;

static XUartLite CtrUartLite;

static int i=0;

int main(void)
{
int Status;

Status = XIntc_Initialize(&intc, XPAR_XPS_INTC_0_DEVICE_ID);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

Status = XIntc_SelfTest(&intc);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

Xil_ExceptionInit();

Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)XIntc_DeviceInterruptHandler,
(void*) 0);

Xil_ExceptionEnable();

Status = XIntc_Start(&intc, XIN_REAL_MODE);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}


//start UartLite code from here;

Status = XUartLite_Initialize(&CtrUartLite, XPAR_UARTLITE_0_DEVICE_ID);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

Status = XUartLite_SelfTest(&CtrUartLite);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

Status = XIntc_Connect(&intc, XPAR_INTC_0_UARTLITE_0_VEC_ID,
(XInterruptHandler)XUartLite_InterruptHandler,
(void *)&CtrUartLite);
if (Status != XST_SUCCESS) {
xil_printf("FATAL: Interrupt Controller Control connection failure\n\r");
return XST_FAILURE;
}

XUartLite_SetRecvHandler(&CtrUartLite, (void *)CtrUartLite_ISR, &CtrUartLite);

XUartLite_EnableInterrupt(&CtrUartLite);

XIntc_Enable(&intc, XPAR_XPS_INTC_0_CONTROL_UART_INTERRUPT_INTR);

while(1){}

return 0;
}

void *CtrUartLite_ISR()
{
u8 StatusRegister, temp;

xil_printf("..Enter ISR..\n\r");

if (i<3){
StatusRegister = XUartLite_GetStatusReg(&CtrUartLite.RegBaseAddress);

xil_printf("StatusReg----%X\n\r",StatusRegister);

temp = XUartLite_ReadReg(&CtrUartLite.RegBaseAddress,
XUL_RX_FIFO_OFFSET);
xil_printf("Recvd Char: %d\n\r\n\r",temp);

i++;
}
}

 

*******************************************************

 

Testing result shown in the console:

 

Input: A (and Enter )

 

A
..Enter ISR..
StatusReg----64
Recvd Char: 0

..Enter ISR..
StatusReg----64
Recvd Char: 0

..Enter ISR..
StatusReg----64
Recvd Char: 0

..Enter ISR..
..Enter ISR..
..Enter ISR..
..Enter ISR..

......more

 

*********************************************

0 Kudos
1 Solution

Accepted Solutions
llqk
Visitor
Visitor
4,310 Views
Registered: ‎08-14-2012

Finally I figured out the reason.

Even if I claimed the UartLite instance CtrUartLite,

the data I sent via the com port still goes to this address: XPAR_UARTLITE_0_BASEADDR

Don't understand the detail how it works.

But when I changed the code of the handler to the following it works well as I expected.

Wish this experience would help some other new learners.

 

 

*******************************************

 

void *CtrUartLite_ISR()
{

u8 StatusRegister, temp;

xil_printf("..Enter ISR..\n\r");


//while (XUartLite_IsReceiveEmpty(XPAR_UARTLITE_0_BASEADDR));

temp = (u8)XUartLite_ReadReg(XPAR_UARTLITE_0_BASEADDR, XUL_RX_FIFO_OFFSET);

xil_printf("Recvd Char: %c\n\r\n\r",temp);

}

 

 

View solution in original post

0 Kudos
2 Replies
llqk
Visitor
Visitor
4,311 Views
Registered: ‎08-14-2012

Finally I figured out the reason.

Even if I claimed the UartLite instance CtrUartLite,

the data I sent via the com port still goes to this address: XPAR_UARTLITE_0_BASEADDR

Don't understand the detail how it works.

But when I changed the code of the handler to the following it works well as I expected.

Wish this experience would help some other new learners.

 

 

*******************************************

 

void *CtrUartLite_ISR()
{

u8 StatusRegister, temp;

xil_printf("..Enter ISR..\n\r");


//while (XUartLite_IsReceiveEmpty(XPAR_UARTLITE_0_BASEADDR));

temp = (u8)XUartLite_ReadReg(XPAR_UARTLITE_0_BASEADDR, XUL_RX_FIFO_OFFSET);

xil_printf("Recvd Char: %c\n\r\n\r",temp);

}

 

 

View solution in original post

0 Kudos
tibacou
Explorer
Explorer
3,375 Views
Registered: ‎02-17-2013

Hey

Your Uart lite is a custom peripheral that you add with the create or import peripheral of the Xilinx platform Studio ? 

0 Kudos