Forum Discussion

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

Problem with reading data from UART

Hi!

Below are my C codes using NIOS 2 IDE to send and read data using DE2 board through UART by RS232 port.

Also, I build my own GUI to receive and send data to UART. After I read the data from my GUI and store the data in array prompt [10], I decide to display the array prompt [10] to my GUI by using several type of function calling, as shown coding below in bold style. However, from my GUI I cannot read the data sending. may i know how to solve it? Thanks!

int main ()

{

FILE* fp1;

char prompt[10] ;

fp1 = fopen(UART_0_NAME , "r+");

if (fp1)

{

while (1)

{

//I get the data from my GUI

fgets(prompt, 8, fp1);

// I send data to be displayed in my GUI

fwrite (prompt , 1 , sizeof(prompt) , fp1 );

cout<< prompt;

fputs (prompt,fp1);

}

fclose (fp1);

}

return 0;

}

1 Reply

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

    Hi,

    Maybe test the reception and transmission separatly to be sure where the problem comes from.

    1. Put only the code to send data (with a basic loop to wait between sendings)

    2. Put only the code to receive data, and display the value on LEDs or something else