Forum Discussion
Altera_Forum
Honored Contributor
13 years agoRX and TX UART with NIOS2/e
Hello all, i am beginner in NIOS2 programming and I try to use UART_0 in my system, where i have 22kB RAM on chip. So I have used the hello_world_small template. I tryed to blink with led, setti...
Altera_Forum
Honored Contributor
13 years agoHi! May I know what do you receive on your HyperTerminal? I keep receiving a 7 look alike thing at hyperterminal and when I copy and paste it in here , it become a ª.
How may I solve it? And at the Nios II Console, Random number are coming out. Example I type in... 3 and the result is 33 a and the result is 61 s and the result is 73 May I know where ran wrong? I am suppose to test by sending something to uart and read from it then display it on Nios II console. Can anyone tell me what does the 0xFF,0xAA, count/256 and count%256 are for? Sorry for all these questions... --- Quote Start --- 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 --- Quote End ---