Forum Discussion
Altera_Forum
Honored Contributor
15 years agoHey Guys .
Have been doing some of RS232 uart work . I've successfully written data to computer via RS232 uart but having some problems reading data through serial isr. I've configured the# defined the uart base address and uart irq that was shown in sopc builder and used some of code posted by some person . Here's the code : # include <stdio.h># include <unistd.h># include <sys/alt_irq.h># include "sys/alt_stdio.h"# include "system.h"# include "alt_types.h"# include "altera_avalon_uart_regs.h" # define Switches (volatile char *) 0x00011040# define LEDs (char *) 0x00011050# define UART0_BASE (char *) 0x00011000# define UART0_IRQ 1# define TIMER0_BASE (char *) 0x00011020 void uart0_put_char(unsigned char ch) { while((IORD_ALTERA_AVALON_UART_STATUS(UART0_BASE) & 0x040) != 0x040){ ;} IOWR_ALTERA_AVALON_UART_TXDATA(UART0_BASE,ch); } void uart0_put_str(unsigned char * str){ while(*str){ uart0_put_char(*str); str++; } } void uart_handle(void *context,alt_u32 interrupt) { unsigned short int data,status; //status = IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE); //while (!(status & ALTERA_AVALON_UART_STATUS_RRDY_MSK)) status = IORD_ALTERA_AVALON_UART_STATUS(UART0_BASE); data =IORD_ALTERA_AVALON_UART_RXDATA(UART0_BASE); /* //write status reg; status = ALTERA_AVALON_UART_STATUS_TRDY_MSK; IOWR_ALTERA_AVALON_UART_STATUS(UART0_BASE, status); IOWR_ALTERA_AVALON_UART_TXDATA(UART0_BASE, data); IOWR_ALTERA_AVALON_UART_STATUS(UART0_BASE, 0); */ } void uart_init() { alt_u32 control; volatile unsigned long uart_capture; // int divisor; alt_putstr("Debug 1\n"); control = ALTERA_AVALON_UART_CONTROL_TRDY_MSK | ALTERA_AVALON_UART_CONTROL_RRDY_MSK | ALTERA_AVALON_UART_CONTROL_E_MSK; IOWR_ALTERA_AVALON_UART_CONTROL(UART0_BASE, control); alt_putstr("Debug 2\n"); // divisor = (int)(50000000/9600+0.5); // IOWR_ALTERA_AVALON_UART_DIVISOR(UART0_BASE, divisor); alt_putstr("Debug 3\n"); if (alt_irq_register(UART0_IRQ, (void*)uart_capture, uart_handle)){ alt_putstr("Debug 4\n"); }else{ alt_putstr("Debug 5\n"); } } int main(){ printf("Hello from NIOS II \n"); uart_init(); //usleep(1000000); printf("Hello from NIOS III \n"); uart0_put_str("Hello World"); while(1){ *LEDs = *Switches; } return 0; } i only get output upto : Hello from NIOS II Debug 1 Debug 2 Debug 3 There seems to be problem while registering for irq in statement: alt_irq_register(UART0_IRQ, (void*)uart_capture, uart_handle) Can anyone plz tell me what's the actual way to do it ? And why my code is hanging on this statement.