Altera_Forum
Honored Contributor
7 years agoHandling data with alt_getchar()
Hi,
I've written a short program for a nios ii (e) with a uart rs232 core, to echo a character I send from a serial terminal on a PC. I have managed to get it to work, however it appears to 'receive' a character of its own after every echo. My main is as follows, delay() is just a simple counter;# include "sys/alt_stdio.h"# include <stdio.h># include "altera_avalon_uart_regs.h"
int main(){
char c;
while (1){
printf("Hello from Nios II!\n");
c = alt_getchar();
printf("You entered: %c \n", c);
delay(1);
}
return 0;
} However, after every time I send a character, I will get "You entered x" followed by "hello...." then another "you entered" which is blank, before it sends another "hello..", this time waiting for another character. Is there something I'm missing here? Many thanks in advance.