Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21611 Discussions

Problem with reading data from UART

Altera_Forum
Honored Contributor II
1,232 Views

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; 

}
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
555 Views

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
0 Kudos
Reply