Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Unable to read all information from Nios II UART

Hello All,

I am using Nios II cyclone development kit as part of my research.

I am listening to uart1 in order to receive character-based information from another device. My code is simple. However, I am always getting the following error after 4 characters:

Starting process.

Waiting for a new character.

~

Still open the UART 2 file.

Waiting for a new character.

B

Still open the UART 2 file.

Waiting for a new character.

ÿ

Still open the UART 2 file.

Waiting for a new character.

ÿ

Still open the UART 2 file.

Waiting for a new character.

nios2-terminal: exiting due to ^D on remote

Any help to fix this issue is very appreciated.

Best Regards,

Julia.

PS: that the communication between the device and PC is working perfectly when through the com port.

CODE:

# include <stdio.h># include <string.h># include <stdlib.h>

int main ()

{

FILE* fp1;

char prompt = &#39;L&#39;;

fp1 = fopen("/dev/uart1", "r+");

printf("Starting process.\n");

if (fp1)

{

for(;;) // Loop forever

{

printf("Waiting for a new character.\n");

prompt = getc(fp1); // Get a character from the UART1.

printf("%c \n", prompt);

printf("Waiting for a new character.\n");

}

printf("Closing the UART 1 file.\n");

fclose (fp1);

}

return 0;

}

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Julia,

    What kind of data is the other device transmitting? Your source suggests you expect to get printable characters only. If so, looking at what appears on your console I&#39;d guess the UART isn&#39;t configured correctly.

    Banx.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Julia,

    What we mean by &#39;printable&#39; is characters that have a vaule in the range 0x20 to 0x7f, these values are represented by characters like &#39;A&#39; to &#39;Z&#39;, &#39;a&#39; to &#39;z&#39;, &#39;0&#39; to &#39;9&#39; and all the other punctuation symbols. The other &#39;unprintable&#39; characters are usually reserved for controlling data flow (XON/XOFF), data verification (ACK/NACK) and other stuff. Do a search for "ASCII table" and you&#39;ll find something that explains it better than I could.

    Although some characters are &#39;unprintable&#39; Hyperterminal intercepts them and attaches symbols to them. For example, 0x01 becomes the white smiley face and 0x04 becomes the diamond (both seen in your screenshot).

    To get back to the point, if your dev kit is transmitting &#39;printable&#39; data such as "Hello World, this is a test of the UART.\n" and Hyperterminal is typically displaying the garbage shown in your screenshot then I would say that the dev kit and the PC are working with differently configured serial ports.

    You need to find out how the UART on your dev kit is configured (excalibur.h or system.h) and edit the hyperterminal settings to suit. The fact that you are getting garbage at least means the hardware appears to be connected correctly.

    Good luck.

    Banx.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Julia,

    I think your problem is a little bit more easy to solve then you think. Try not to print the characters on terminal. The terminal breaks when it receives a CTRL + D (^D), so, your program on NIOS probably is receiving the characters fine, but when it prints this specific character on terminal, the terminal aborts.

    I hope this information was useful

    Alair
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    four years to late :D but i had a problem that i was also just able to receive four chars all the time!

    The reason was that i had a printf in the while loop! This printf was just to slow for receiving all the chars! :)

    greetings