Altera_Forum
Honored Contributor
21 years agoHAL&Uart example ?
Hi all
I cant find example for uart with HAL http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif I have two RS232 uarts (uart232,uart0) 1'st i connect to stdin stdout and use it for debuging (uart232) 2'nd i try to make workable (uart0) My goal is : create interrupt for uart0 which execute when uart0 recive data and in interrupt function i want transsmit received data from uart0 to uart232 data->uart0->uart232 I can't understand why that code hang's void isr_uart0(void* context, alt_u32 id) // uart0 interrupt handler { alt_u32 status; // status = IORD_ALTERA_AVALON_UART_STATUS(base); printf("%s",IORD_ALTERA_AVALON_UART_RXDATA(UART0_BASE));//read data from uart0 and write to uart232 } void ALEX_UART_TRY() //uart routines (initialization , irq register ) { void *puart0 = (void*) UART0_BASE; // set pointer to uart0 alt_u32 divisor = (ALT_CPU_FREQ/115200)-1; // calculate divisor IOWR_ALTERA_AVALON_UART_DIVISOR(UART0_BASE, divisor); // assign bbrate IOWR_ALTERA_AVALON_UART_CONTROL(UART0_BASE, // enable interrupt ALTERA_AVALON_UART_CONTROL_RRDY_MSK // Enable interrupt for a read ready ); alt_irq_register(UART0_IRQ, puart0, isr_uart0); //register irq (nios2 hangs after that ) char* msg = "hello world"; // test uart0 by sending "Hello wold" (it work fine ) FILE* fp; fp = fopen (UART0_NAME, "w"); if (fp) { fprintf(fp, "%s",msg); fclose(fp); } } void main() { ALEX_UART_TRY(); }