cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
4,730 Views
Registered: ‎11-13-2017

How to configure UART Interrupt in Microblaze?

Hi there,

Am using SP601 EVK, I need to set the UART interrupt handler while I receive the character from the Teraterm in PC. Am new microblaze. can any one give me suggestion how to set the UART receive interrupt in microblaze?

 

Thanks in advance. 

0 Kudos
6 Replies
Highlighted
Scholar
Scholar
4,713 Views
Registered: ‎08-07-2014

0 Kudos
Highlighted
Visitor
Visitor
4,703 Views
Registered: ‎11-13-2017

i want to communicate between PC and microblaze processor using builtin UART 

i can send and receive byte from PC and microblaze in normal way.

but now i want to use interrupts. i want to generate interrupt when microblaze receives byte from UART

i have explored much and tried different C syntaxes but did not get success.

i have refered xilinx documents like "Embedded System Tools Reference Manual" and xapp7778 application note for interrupt handling but not succeeded.

please help me to configure uart interrupt in XPS and how to write its C program in SDK to handle UART interrupt.

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
4,692 Views
Registered: ‎08-01-2008

use this c code
#include <xuartlite_l.h>
#include <xintc_l.h>
#include <xparameters.h>

/* uartlite interrupt service routine */
void uart_int_handler(void *baseaddr_p) {
char c;
/* till uart FIFOs are empty */
while (!XUartLite_IsReceiveEmpty(XPAR_AXI_UARTLITE_0_BASEADDR)) {
/* read a character */
c = XUartLite_RecvByte(XPAR_AXI_UARTLITE_0_BASEADDR);
/* print character on hyperterminal (STDOUT) */
xil_printf ("Character: %c \r\n", c);
}
}

int main(void)
{

/* Enable MicroBlaze exception */
microblaze_enable_interrupts();

/* Connect uart interrupt handler that will be called when an interrupt
* for the uart occurs*/
XIntc_RegisterHandler(XPAR_INTC_0_BASEADDR,XPAR_AXI_INTC_0_AXI_UARTLITE_0_INTERRUPT_INTR,(XInterruptHandler)uart_int_handler,(void *)XPAR_AXI_UARTLITE_0_BASEADDR);

/* Start the interrupt controller */
XIntc_MasterEnable(XPAR_INTC_0_BASEADDR);

/* Enable uart interrupt in the interrupt controller */
XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, XPAR_AXI_UARTLITE_0_INTERRUPT_MASK);

/* Enable Uartlite interrupt */
XUartLite_EnableIntr(XPAR_AXI_UARTLITE_0_BASEADDR);

/* Wait for interrupts to occur */
while (1);
}
Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
0 Kudos
Highlighted
Visitor
Visitor
4,676 Views
Registered: ‎11-13-2017

Hi BalKrishan,

 

Thanks for the reply. Am using SP601 Evaluation board with spartan 6 FPGA family. I tried your code but i got error while including  #include <xuartlite_l.h> header file. I think am not using uartlite IP. I seen in the BSP source files and found one API "XIOModule_SetRecvHandler"  to set the callback function while receiving the byte from the UART. Is it right API?

 

 

Thanks in advance.

0 Kudos
Highlighted
Moderator
Moderator
4,408 Views
Registered: ‎09-12-2007

What UART are you using in your system? 

0 Kudos
Highlighted
568 Views
Registered: ‎12-23-2019

Hi,

I am currently using snippet of code to trigger the interrupt and seem to be working and triggering the interrupt when new data is available. However, I am currently using 3 uarts on the same board and initiate the same handler. I am trying to read out the void * baseaddres however the void * data is not valid and doesnt match with any of my uart baseaddresses.

Inside the init I send the regbaseaddress which is 0x40610000 for one of the uarts

XIntc_RegisterHandler(XPAR_INTC_0_BASEADDR, vec_id,(XInterruptHandler)uart_int_handler, (void *)InstancePtr->RegBaseAddress);

Later inside the handler I perform the following transformation to get the address:

void uart_int_handler(void *ref)
{
	u32 *reg_addr;
	reg_addr = (u32 *)ref;
}

However, when I debug I see a value of 0x80041300 and the pointer has a value of 0x41200000 (INTC ADDRESS where all uart interrupt blocks are connected to)

Moreover is there some way to read more than 16 bytes as it seems the hardware discards the rest after 16bytes?

0 Kudos