Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

uart interrupt not working

Altera_Forum
Honored Contributor II
1,015 Views

Hi everyone, 

 

I'm using the Altera DE2 board. I am trying to setup a serial link between PC and UART, but UART doesn't seem to be receiving anything. Here's the code that I have. Could anyone tell me what's wrong with it? Thanks. I'm using hyper terminal to send the data and I have jtag_uart mapped as stdin/stdout/stderr to display the char I received through the UART. 

# include <stdio.h># include "system.h"# include "sys/alt_irq.h"# include "altera_avalon_uart_regs.h" 

# define RRDY_MSK 0x0080 

 

/* Declare a global variable to hold the uart data value */ 

unsigned char uart_data; 

 

//ISR for receiving 

static void IsrRxUart0(void* context, alt_u32 id) 

{  

/* cast the context pointer to an character pointer.*/ 

unsigned char* uart_data_ptr = (unsigned char*) context; 

 

//if RRDY bit of status register is clear 

if((IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE) & RRDY_MSK) == 0x0000) 

//IOWR_ALTERA_AVALON_UART_STATUS(UART_0_BASE, 0x0000); 

*uart_data_ptr = IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE); 

// enable UART interrupt for read ready (setting IRRDY bit) 

IOWR_ALTERA_AVALON_UART_CONTROL(UART_0_BASE, 0x0080); 

 

/* Initialize the uart */ 

static void InitUart0() 

/* Recast the uart_data pointer to match the 

* alt_irq_register() function prototype.  

*/ 

void* uart_data_ptr = (void*) &uart_data; 

 

//enable UART interrupt for read ready (setting IRRDY bit) 

IOWR_ALTERA_AVALON_UART_CONTROL(UART_0_BASE, 0x0080); 

 

//register UART receiver ISR 

alt_irq_register(UART_0_IRQ, uart_data_ptr, IsrRxUart0); 

 

 

int main() 

{  

InitUart0(); 

while(1) 

if(uart_data) 

printf("This is the character received: %c \n", uart_data); 

return 0; 

}
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
290 Views
0 Kudos
Reply