Forum Discussion
Altera_Forum
Honored Contributor
11 years ago --- Quote Start --- Yes you have to use interrupts for accurate transmission. I had the same issue you have when using polling (the while loop in your code). This is because the while loop prevents the nios from doing other tasks. In other words, you are bottlenecking yourself. Interrupts allow you to receive and transmit messages exaclty when you want to, by temporarily pausing the nios to perform the uart task. To do interrupts, you must connect the interrupt (IRQ) column in qsys (that is a hardware enable). Then you must do a software enable (alt_ic_isr_register and alt_ic_irq_enable) --> this is slightly different than in the code provided. He uses alt_irq_register and alt_irq_enable which are outdated... Here is what I suggest: The code i linked to is using 2 uarts - because they are talking to each other. You only need 1. So you must go through the provided code and delete one of the uarts (UART2). To make life easy, make sure your uart module in qsys is named UART1. This is because his code expects system.h names to be Uart1 and Uart2. You can give it a different name, but you will have to scrub through the code to make the appropriate changes. Include InterruptHandlerforUart.h in your code. Now in main you want to initialize the uart and enable the software interrupts: int context_uart; InitUart1( <put in a baud rate if uart module did not have fixed baud rate... see the linked code>); alt_ic_isr_register(Uart1_IRQ_INTERRUPT_CONTROLLER_ID, Uart1_IRQ,IsrUart1,&context_uart,0x0); alt_ic_irq_enable(Uart1_IRQ_INTERRUPT_CONTROLLER_ID, Uart1_IRQ); finally to transmit, you just write: PutUart1( <some character> ); The C code provided takes care of the rest (uart statuses, fifoing, etc.) If you have lots of characters - which you do - then put the PutUart1 into a loop. --- Quote End --- Thank you very much for your kind reply, krasner... I am now trying to implement the code and need some time to troubleshoot the errors here and there, keep you updated