Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

prob. 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::à

12 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hello mr wolf

    i am using EP1C6 UP3 BOARD supplied by altera(i.e sls corp. in turn)

    so the cd given by altera did not include any examples related to ep1c6 board so i had to go to sls example...

    plz help me out ..or can u give some info about ur bdf file(i,e ur example ) where this uart prog worked...

    plz help me

    http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif

    --- Quote Start ---

    originally posted by pfab@Dec 1 2005, 04:03 AM

    unless it is absolutly necessary to use the sls example wich is, if i am not wrong, an example for the up3 development kit, you should use the altera examples for your development kit.

    using the altera examples you will have a fpga configuration that is tested to work with your board, including the uart.

    i am quite sure that the problem is not your code but the fpga design.

    --wolf

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=11284)

    --- quote end ---

    --- Quote End ---

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hi ramesh,

    I used the standard NIOS II design for a stratix development kit that comes with the NIOS II IDE. You can find a demo version on the altera homepage.

    In the next few weeks I will not have time to get into the sls example you are using.

    You might want to start a new topic that asks for assistant with the up3 board.

    There might be somebody who is familiar with it.

    SORRY,

    --wolf