Forum Discussion

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

UART - problem

hi

i am having problems in wrting a C function that can read data streams from the UART and returning it to a buffer .

can some body help me out with this..

bye

5 Replies

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

    --- Quote Start ---

    originally posted by sandybhai@Oct 15 2006, 04:08 PM

    hi

    i am having problems in wrting a c function that can read data streams from the uart and returning it to a buffer .

    can some body help me out with this..

    bye

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

    --- quote end ---

    --- Quote End ---

    Hey Sandybhai,

    I suggest to receive data coming from the UART under interrupt. This means that your program will jump to the interrupt function (which will receive the uart data)

    from RX data is received.

    You can then place the data into a buffer (an array string) so you can handle the data afterwards.

    Here is an example code:

    void UartReceiver1(void * content,alt_u32 id)

    {

    // get the uart data

    unsigned char * UartData = (unsigned char*)(UART1_BASE);

    // UART1_BASE is defined in system.h

    }

    }

    Setting up the interrupt: enter this into your main code

    // UART1 interrupt routine declaration

    alt_irq_register(UART1_IRQ,NULL,UartReceiver1);

    IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE, 0x80);

    This is an easy way to receive UART data without the need of specific NIOS instructions for UART handling.

    Kind regards

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

    --- Quote Start ---

    originally posted by karel van haver+oct 18 2006, 01:27 pm--><div class='quotetop'>quote (karel van haver @ oct 18 2006, 01:27 pm)</div>

    --- quote start ---

    <!--quotebegin-sandybhai@Oct 15 2006, 04:08 PM

    hi

    i am having problems in wrting a c function that can read data streams from the uart and returning it to a buffer .

    can some body help me out with this..

    bye

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

    --- quote end ---

    --- Quote End ---

    Hey Sandybhai,

    I suggest to receive data coming from the UART under interrupt. This means that your program will jump to the interrupt function (which will receive the uart data)

    from RX data is received.

    You can then place the data into a buffer (an array string) so you can handle the data afterwards.

    Here is an example code:

    void UartReceiver1(void * content,alt_u32 id)

    {

    // get the uart data

    unsigned char * UartData = (unsigned char*)(UART1_BASE);

    // UART1_BASE is defined in system.h

    String[i] = *UartData;

    i++;

    }

    }

    Setting up the interrupt: enter this into your main code

    // UART1 interrupt routine declaration

    alt_irq_register(UART1_IRQ,NULL,UartReceiver1);

    IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE, 0x80);

    This is an easy way to receive UART data without the need of specific NIOS instructions for UART handling.

    Kind regards

    Karel

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

    [/b]

    --- Quote End ---

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

    Assume your system is based on Nios II:

    >map your UART into stdin and stdout

    >then check with stdio command then you can verify hardware implementation.

    After doing that you can play with HAL driver.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by legendbb@Nov 3 2006, 07:15 AM

    assume your system is based on nios ii:

    >map your uart into stdin and stdout

    >then check with stdio command then you can verify hardware implementation.

    after doing that you can play with hal driver.

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

    --- quote end ---

    --- Quote End ---

    Hi ledendbb,

    Could you please elaborate how to map UART into stdin and stdout so that stdio command can be used?

    Thanks,

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

    --- Quote Start ---

    originally posted by yanjiapan+nov 5 2006, 05:40 pm--><div class='quotetop'>quote (yanjiapan @ nov 5 2006, 05:40 pm)</div>

    --- quote start ---

    <!--quotebegin-legendbb@Nov 3 2006, 07:15 AM

    assume your system is based on nios ii:

    >map your uart into stdin and stdout

    >then check with stdio command then you can verify hardware implementation.

    after doing that you can play with hal driver.

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

    --- quote end ---

    --- Quote End ---

    Hi ledendbb,

    Could you please elaborate how to map UART into stdin and stdout so that stdio command can be used?

    Thanks,

    yjp

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

    [/b]

    --- Quote End ---

    Just take a look at the System Library properties page and you&#39;ll see the option there. Alternately, you can modify the system.stf file (in the syslib project&#39;s top-level directory) to point stdin/stdout/stderr to whichever device you&#39;d like to use. The system.stf is mostly used for holding persistence for GUI settings on the syslib properties page.

    Cheers,

    - slacker