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

nios rs232 uart reads only last byte

Altera_Forum
Honored Contributor II
2,224 Views

Hi, 

 

I'm using rs232 uart in nios. 

I'm using the open and read functions to recive data from the uart. 

I'm using the serial port monitor in order to send data on rs232 from the computer to the board. 

The thing is when using the read function I only get the last byte from the string. 

For example, if sending "abcd" from the serial port the read function will return only "d". 

Any idea what could be the problem? 

 

Thanks, 

Merabi
0 Kudos
9 Replies
Altera_Forum
Honored Contributor II
1,148 Views

Amost certainly the uart has no receive fifo so the bytes are being overwritten before being read.

0 Kudos
Altera_Forum
Honored Contributor II
1,148 Views

Yeah I thought of that but when adding the RS232 UART in SOPC there is no such option as FIFO so I thought it's automatically. 

maybe this kind of UART has no FIFO at all?
0 Kudos
Altera_Forum
Honored Contributor II
1,148 Views

There is a fifo'd uart available somewhere. 

Might not be from Altera, check the wiki. 

 

The other option is taking interrupts and using a software fifo. 

But that probably uses more code than the hardware fifo! 

The other option would be a uarth that with an avalon master interface using external memory for its fifo - but I doubt that exists.
0 Kudos
Altera_Forum
Honored Contributor II
1,148 Views

I will try that, thanks.

0 Kudos
Altera_Forum
Honored Contributor II
1,148 Views

Problem solved, thanks! 

I was working with breakpoints and was sending the data to the uart while stopped at breakpint so the hardware went on and the software was stopped. 

My guess is that the counter of the buffer in the uart is precended in the software so when stopped at the breakoint the UART thought we were at the same place as before eventhough a new character was recieved into the rx register.
0 Kudos
Altera_Forum
Honored Contributor II
1,148 Views

 

--- Quote Start ---  

Problem solved, thanks! 

I was working with breakpoints and was sending the data to the uart while stopped at breakpint so the hardware went on and the software was stopped. 

My guess is that the counter of the buffer in the uart is precended in the software so when stopped at the breakoint the UART thought we were at the same place as before eventhough a new character was recieved into the rx register. 

--- Quote End ---  

 

I have met the same problem. Can you explain more detail or share your code? Thank you!!
0 Kudos
Altera_Forum
Honored Contributor II
1,148 Views

Hi, yes. 

The problem I had is that I used breakpoints. My guess is that in that case when the first byte arraived the software stopped at the breakpoint while the hardware kept on recieving additional bytes. So, the counter of the software did not go on but the hardware updated the current byte as new bytes arrived so only the last byte was kept at the register in the end of the process. 

The code is the usual code that is shared usually here, I just can't copy it at the moment. 

Just don't use breakpoints and you'll be fine. If you want to "samplew" the progress of your software then try writing somethings to the uart.
0 Kudos
Altera_Forum
Honored Contributor II
1,148 Views

 

--- Quote Start ---  

Hi, yes. 

The problem I had is that I used breakpoints. My guess is that in that case when the first byte arraived the software stopped at the breakpoint while the hardware kept on recieving additional bytes. So, the counter of the software did not go on but the hardware updated the current byte as new bytes arrived so only the last byte was kept at the register in the end of the process. 

The code is the usual code that is shared usually here, I just can't copy it at the moment. 

Just don't use breakpoints and you'll be fine. If you want to "samplew" the progress of your software then try writing somethings to the uart. 

--- Quote End ---  

 

where is the code that you have mentioned?
0 Kudos
Altera_Forum
Honored Contributor II
1,148 Views

Here is an example to detect some characters: 

 

char* msg = "Detected the character 't'.\n"; 

FILE* fp; 

char prompt = 0; 

fp = fopen ("/dev/uart1", "r+"); //Open file for reading and writing 

if (fp) 

while (prompt != 'v')  

{ // Loop until we receive a 'v'. 

prompt = getc(fp); // Get a character from the UART. 

if (prompt == 't') 

{ // Print a message if character is 't'. 

fwrite (msg, strlen (msg), 1, fp); 

fprintf(fp, "Closing the UART file.\n"); 

fclose (fp); 

return 0;
0 Kudos
Reply