- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
alt_getchar works fine outside the loop Small C library.
# include "sys/alt_stdio.h"
# include <stdio.h>
# include "altera_avalon_uart_regs.h"
int main(){
char c;
c = alt_getchar();
printf("You entered: %c \n", c);
while (1){
}
return 0;
}
--------------------------------
democode
Check with getchar() using Normal C library. Best Regards, Anand Raj Shankar (This message was posted on behalf of Intel Corporation)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- 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. --- Quote End --- Your code doesn't consume the CR (or CR/LF) you most likely typed after the character. Consequently it's read (and displayed) next round.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks mfro, you are correct I did forget. Many thanks.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page