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 never occurs

Altera_Forum
Honored Contributor II
1,338 Views

Hi all, 

 

I am trying to use UART with interrupt on a NIOS II/e system but it seems like the interrupt never occurs.  

 

 

Before main(), I declare the pointer and the ISR: 

 

alt_fd* fd="/dev/uart_0"; void get_response(void*, alt_u32); // UART ISR declaration  

Inside main(), I have the following instructions: 

 

fd = open("/dev/uart_0", O_RDWR | O_NOCTTY); alt_irq_register(UART_0_IRQ,NULL,get_response); IOWR_ALTERA_AVALON_UART_CONTROL(uart_0, 0x80);  

 

And this is the definition of the ISR: 

 

void get_response(void* context, alt_u32 id){ char tmp; int status; status = IORD_ALTERA_AVALON_UART_STATUS(uart_0); printf("Status = %d ",status); /* clear any error flags */ IOWR_ALTERA_AVALON_UART_STATUS(uart_0, 0); tmp = IORD_ALTERA_AVALON_UART_RXDATA(uart_0); printf("Received char %c\n",tmp); ... } 

 

--- 

 

This is what I have in the alt_sys_init.c file 

 

void alt_irq_init ( const void* base ) { ALTERA_NIOS2_IRQ_INIT ( CPU_0, cpu_0); alt_irq_cpu_enable_interrupts(); } /* * Initialize the non-interrupt controller devices. * Called after alt_irq_init(). */ void alt_sys_init( void ) { ALTERA_AVALON_JTAG_UART_INIT ( JTAG_UART_0, jtag_uart_0); ALTERA_AVALON_SYSID_INIT ( SYSID, sysid); ALTERA_AVALON_UART_INIT ( UART_0, uart_0); }  

 

And here's the UART configuration from system.h file: 

 

/* * uart_0 configuration * */ # define ALT_MODULE_CLASS_uart_0 altera_avalon_uart# define UART_0_BASE 0x1009000# define UART_0_BAUD 9600# define UART_0_DATA_BITS 8# define UART_0_FIXED_BAUD 1# define UART_0_FREQ 50000000u# define UART_0_IRQ 0# define UART_0_IRQ_INTERRUPT_CONTROLLER_ID 0# define UART_0_NAME "/dev/uart_0"# define UART_0_PARITY 'N'# define UART_0_SIM_CHAR_STREAM ""# define UART_0_SIM_TRUE_BAUD 0# define UART_0_SPAN 32# define UART_0_STOP_BITS 1# define UART_0_SYNC_REG_DEPTH 2# define UART_0_TYPE "altera_avalon_uart"# define UART_0_USE_CTS_RTS 0# define UART_0_USE_EOP_REGISTER 0 

 

 

Is there anything I am missing? Why does the UART interrupt never occur?
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
381 Views

BUMP 

 

Anyone?
0 Kudos
Altera_Forum
Honored Contributor II
381 Views

Is UART actually working? 

I mean, can you operate it in polling mode?  

RRDY bit in status register should change to 1 whenever rx data is ready. If this doesn't happen, the irq won't trigger either.
0 Kudos
Altera_Forum
Honored Contributor II
381 Views

Which NIOS II version do you use ? 12.x ? 

 

You use uart in an 'interrupt' mode, you have also 'polled' mode. 

You must be sure that you don't use 'small driver' or sometheing like this. It is explained in altera PDF. 

 

Do you build with Qsys ? 

You must be sure that your uart is understood as a serial port. 

When you generate BSP in BSP editor, in "driver" tab you should see "uart driver" or "serial..." or something like this for your uart component. 

 

You shouldn't use 'printf' in your ISR (because high memory footprint and long time execution). Keep ISR as short as possible. 

 

I may add that if you use printf, system will hang if you don't read back (= if you don't use nios-terminal to you board)
0 Kudos
Reply