Altera_Forum
Honored Contributor
20 years agoprob. in accessing UART
Hello ...
i have written the following prog. to access my uart in my design it is named as "uart_0" in the SOPC builder.... while running this prog. in NIOSII IDE i was simulataneously running a c-prog in the PC which continuosly transmits character 't'. i even chkd the o/p from the com port to which it was sending the character……it was correctly sending the data 't'. but the prog. On the board is giving the wrong results... can anyone plz tell what is wrong in my prog.... # include <stdio.h># include <string.h># include "unistd.h"# include "nios2.h"# include "system.h"# include "io.h"# include "altera_avalon_uart.h" int main () { int i,j,k=0; char *ch; i = open("/dev/uart_0",2); //i==file descriptor printf("file opened ::%d",i); if (i!=-1) { while(k!=20) //i am just reading continuosly for 20times { j=read(i,ch,2); printf("char read::%c and j=%d\n",*ch,j); k++; } if (j==-1) printf("did not read\t"); else printf("char read::%c ",*ch); } else { printf("Can’t open uart device\n"); } close(i); return 0; } the o/p for the prog. was as follows........ file opened with descriptor::3 char read::. char read::à char read::à char read::. char read::à char read: :à char read::. char read::à char read::à char read::. char read::à char r ead::à char read::. char read::à char read::à char read::. char read::à ch ar read::à char read::. char read::à char read::à