- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
UART Problem missing characters at 115200
Quartus 4.2 and NIOS 1.1 I want to make ymodem download, so I want use 115200 baud, blocksize is 1026 byte. I copied altera_avalon_uart.h and altera_avalon_uart.c in the syslib directory and changed the uart buffersize: # define ALT_AVALON_UART_BUF_LEN (2048) I use Cyclone Dev. Board and standard design, so hardware should be ok. I made a small testprogram and a loop at Tx-Rx. I set stdout,stderr to lcd,stdin=null. I get different results if I make my testoutputs to jtag uart or lcd. case 1: - tx testoutput to jtag - rx testoutput to lcd result: always read back 1023 characters, instead of 1024 errorcount=no of packets sometimes after some time I get "nios2-terminal: exiting due to I/O error communicating with target" after this error uart1 receives correct packets with 1024 byte case 2: - tx testoutput to jtag - rx testoutput to jtag result: about 25% of the packets wrong, (only 1023 byte) case 3: - tx testoutput to lcd - rx testoutput to lcd result: about 100% of the packets are ok (1024 byte) the critical is the tx testoutput, because in this time the uart1 transmit and receive interrupts are running. on my custom board I also loose characters, even I don't us the jtag uart. please, can someone verify the program and test results, what's wrong ??? thanks ...# include <stdio.h># include <stdlib.h># include <time.h># include <alt_types.h># include <unistd.h># include <fcntl.h># include <sys/alt_alarm.h> # define BYTE alt_u8# define WORD alt_u16# define DWORD alt_u32 # define UART0_RXBUFFERSIZE 2048 int uart0_rxcount; char uart0_rxbuffer[UART0_RXBUFFERSIZE]; char uart0_txbuffer[UART0_RXBUFFERSIZE]; FILE *jtfp; int fd0_nonblocked; // FILEDESCRIPTOR RETURNED BY OPEN FILE * fp0_nonblocked; // FILE pointer returned by fdopen int fd0_blocked; // FILEDESCRIPTOR RETURNED BY OPEN FILE * fp0_blocked; // FILE pointer returned by fdopen int com_fill_testbuffer(char *buffer,int count); char hextoa(BYTE val); void lcd_gotoxy(int x,int y); int main() { int packetcount=0; int txcount; int res; int packeterror=0; jtfp = fopen ("/dev/jtag_uart","w"); if(jtfp) { fprintf(jtfp,"JTAG UART OPEN FOR DEBUG\n"); } // BAUDRATE IS 115200,8,N,1 fd0_nonblocked = open("/dev/uart1",O_RDWR | O_NONBLOCK | O_NOCTTY); fp0_nonblocked=fdopen(fd0_nonblocked,"rw+"); fd0_blocked = open("/dev/uart1",O_RDWR | O_NOCTTY); fp0_blocked=fdopen(fd0_blocked,"rw+"); // txcount = 512; txcount = 1024; // dummy read uart0_rxcount=read(fd0_nonblocked,uart0_rxbuffer,UART0_RXBUFFERSIZE); while(1) { com_fill_testbuffer(uart0_txbuffer,txcount); res=write(fd0_nonblocked,uart0_txbuffer,txcount); // TX TESTOUTPUT TO JTAG-UART // fprintf(jtfp,"%04d UART1:TX:%d: \r\n",packetcount,res); // TX TESTOUTPUT TO LCD lcd_gotoxy(1,1); printf("TX:%04d",res); usleep(500000); // wait to complete trannsmit and receive uart0_rxcount=read(fd0_nonblocked,uart0_rxbuffer,UART0_RXBUFFERSIZE); if(uart0_rxcount!=txcount) packeterror++; // RX TESTOUTPUT TO JTAG UART // fprintf(jtfp,"UART1:RX:%d: PACKETS:%d ERRORS:%d\r\n",uart0_rxcount,packetcount++,packeterror); // RX TESTOUTPUT TO LCD lcd_gotoxy(1,9); printf("RX:%04d",uart0_rxcount); lcd_gotoxy(2,1); printf("PA:%04d ERR:%04d",packetcount++,packeterror); } return 0; } int com_fill_testbuffer(char *buffer,int count) { int i,k; unsigned int seed; seed=clock(); srand(seed); for(i=0;i<(count/2);i++) { k=rand()&0xff; k=i; buffer[i<<1]=hextoa((i>>4)&0x0f); buffer[(i<<1)+1]=hextoa(i&0x0f); } return 0; } char hextoa(BYTE val) { char hexchar=0; if(val<=9) hexchar='0'+val; if(val>=0x0a && val<=0x0f) hexchar='A'+val-0x0a; return(hexchar); } void lcd_gotoxy(int x,int y) { printf("\x1b[%d;%dH",x,y); } ...Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the uart have a buffer of 64 bytes defualt size.
when HW syncronization is not used, if you write more then 64 chars to the buffer before the receving side reed them , chars will be lost
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