Hi all,
I finally found some examples and make program, which work - it sends 4 bytes via uart0 and receives max.16 bytes via uart0. It works in hello world small template and when i compile, it take only 1852bytes (i run this on DE0_NANO development board).
--------------------------------------------------
# include <stdio.h>
# include <unistd.h>
# include <fcntl.h>
# include "sys/alt_stdio.h"
# include "system.h"
# include "altera_avalon_pio_regs.h"
# include "altera_avalon_uart_regs.h"
# include "altera_avalon_uart.h"
// global variables
int count = 0,ch,n,status,led=0xff;
int rx_cnt,rx_buf[16];
int main()
{
alt_printf("1.Hello from Nios II!\n");
while(1)
{ // printf("Hello from Nios II!\n");
IOWR_ALTERA_AVALON_PIO_DATA(DATA_BUS_BASE, count );
IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, count);
count++;
// send 4 bytes via UART0 (with waiting 100us)
IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE,0xFF);
usleep(100);
IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE,0xAA);
usleep(100);
IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE,count/256);
usleep(100);
IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE,count%256);
usleep(100);
// read bytes from UART and wait 20ms
rx_cnt=0;
for(n=0;n<1000;n++)
{ usleep(20);
ch = IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE);
// if received some byte, read it
if ((ch&0x80)==0x80)
{ ch = IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE);
rx_buf[rx_cnt]= ch;
rx_cnt++;
}
}
// print the bytes to terminal
if (rx_cnt>0)
{ alt_printf("rx_data:");
for(n=0;n<rx_cnt;n++)
{ alt_printf("%x ",rx_buf[n]);
}
alt_printf("\n");
}
}
return 0;
}
------------------------
Jan Naceradsky, Czech Republic