- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I´ve built the folowing code: while (1) { fprintf(fp, "%c", B_PACK); for (j = 0; j < 10000000; j++) { //testadado = (testadado | tembyte()); // tem dado http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif if(IORD_ALTERA_AVALON_UART_STATUS(ENDSERIAL) & 0x080) { printf("I got data"); testadado = 1; getchar(); break; } } } Where fp is a pointer to my uart1. Well, I´m testing this code with Hyperterminal. I can receive the B_PACK byte there with no problems. But when I send one byte thru the Hyperterminal, the code keeps running and it do not enter in the if(IORD_ALTERA_AVALON_UART_STATUS(ENDSERIAL) & 0x080) condition. If I send a lot of data, then sometimes it enters in the condition. But it do not work to the first data. Can someone help me? And isn´t there another way to detect if there is data on the serial? Thanks!Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- originally posted by hoffpistolao@Dec 21 2005, 08:27 AM hello,
i´ve built the folowing code:
while (1)
{
fprintf(fp, "%c", b_pack);
for (j = 0; j < 10000000; j++)
{
//testadado = (testadado | tembyte()); // tem dado http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/smile.gif
if(iord_altera_avalon_uart_status(endserial) & 0x080)
{
printf("i got data");
testadado = 1;
getchar();
break;
}
}
}
where fp is a pointer to my uart1.
well, i´m testing this code with hyperterminal.
i can receive the b_pack byte there with no problems. but when i send one byte thru the hyperterminal, the code keeps running and it do not enter in the
if(iord_altera_avalon_uart_status(endserial) & 0x080)
condition.
if i send a lot of data, then sometimes it enters in the condition. but it do not work to the first data.
can someone help me?
and isn´t there another way to detect if there is data on the serial?
thanks!
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=11692)
--- quote end ---
--- Quote End --- Hello, maybe the problem here is that you are using high-level HAL functions with low-level macros (driver level) to access your UART. If you only use one of these methods, it should work. May be if you fclose() the UART before using the low-level macros could help. We had a similar problem because we wanted to use the high-level HAL functions only, but then the getchar() function blocked until there was data received. So we decided to write our own UART driver with a non-blocking read() function. I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I got that.
And is there a way to detect if there is data on serial using High level functions? Because if I use getc to read a data the program stops until the data comes. So I would like to be sure that there is data, and then use the getc(). Thank you for replying! =]- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I haven't found a way to detect if there is a byte in the receive buffer of the UART with high-level HAL functions (like read(), getc()...) only. This was the reason why we created our own low-level driver for the UART which has a different read() function which returns immediately even if there was no data received. If this is the case, our function simply returns a value which indicates that 0 bytes are received and the calling code can continue.
Unfortunately I cannot give you the code of our driver because there is some other functionality in this driver which is very application-specific.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
try this code , it check how much char are in the uart buffer
# include "altera_avalon_uart.h"# include <fcntl.h># include <unistd.h># include "priv/alt_file.h" int getUartBufferCnt() { //alt_fd* fd=&alt_fd_list[fdterm]; //fd is the uart's file discreptor alt_avalon_uart_dev* dev = (alt_avalon_uart_dev*) fd->dev; int bufferCnt=dev->rx_end-dev->rx_start; if(bufferCnt<0) bufferCnt+=ALT_AVALON_UART_BUF_LEN; return bufferCnt; }
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