Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

operate UART w/ NIOS wo/ HAL

Honored Contributor II

The following code should make a loopback between UART RX and TX (echo). 

However, it seems that first N typed chars (from PC towards the board) are not successfully absorbed. 

After N characters (few dozens, I guess), it works correctly (I get an echo for each character I type). 

Any ideas? 



# include "altera_avalon_uart_regs.h"# include "system.h" typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; # define UART_BASE UART_0_BASE int main () { u8 uart_rx_char; u16 uart_st_reg; while (1) { uart_st_reg = (u16)IORD_ALTERA_AVALON_UART_STATUS(UART_BASE); if (uart_st_reg & ALTERA_AVALON_UART_STATUS_RRDY_MSK) { uart_rx_char = (u8)IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE); IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, uart_rx_char); } } return 0; }
0 Kudos
1 Reply
Honored Contributor II


try to check if transmit is ready before you write in your txdata, and clear the status register in the begining of your while.