Forum Discussion

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

an UART programme

Hi there,I'm trying to delievering and recieving charactors by UART:while I recieve a charactor(for example:0x00),I delieve 0x01.Below is my C programme,could anyone tell me if there's any problems ?Thank you!

# include <unistd.h># include <string.h># include "system.h"# include "sys/alt_irq.h"# include "altera_avalon_uart_regs.h"# include "alt_types.h"# include "altera_avalon_uart.h"# include "altera_avalon_uart_regs.h"# define RRDY_MSK 0x0080# define TRDY_MSK 0x0080

//ISR for receiving and delievering

static void uart_isr(void* context, alt_u32 id)

{

/*

* Read the status register in order to determine the cause of the

* interrupt.

*/

alt_u32 status;

alt_u8 rxdata;

status = IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE);

/* Clear any error flags set at the device */

IOWR_ALTERA_AVALON_UART_STATUS(UART_0_BASE, 0);

/* process a read irq */

if (status&ALTERA_AVALON_UART_STATUS_RRDY_MSK)

{

rxdata=IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE);

}

/* process a write irq */

if (status&ALTERA_AVALON_UART_STATUS_TRDY_MSK)

{

IOWR_ALTERA_AVALON_UART_TXDATA(UART0_BASE, 0x01);

}

}

int main()

{

//enable the uart_0 interrupt

IOWR_ALTERA_AVALON_UART_CONTROL(UART_0_BASE,ALTERA_AVALON_UART_CONTROL_RRDY_MSK|

ALTERA_AVALON_UART_CONTROL_TRDY_MSK);

//Register the interrupt handler

alt_irq_register(UART_0_IRQ,0,uart_isr);

if(rxdata)

{

IOWR_ALTERA_AVALON_UART_TXDATA(UART0_BASE, 0x01);

}

return 0;

}

4 Replies

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

    --- Quote Start ---

    originally posted by cicizhang@Dec 18 2006, 08:07 PM

    hi there,i&#39;m trying to delievering and recieving charactors by uart:while i recieve a charactor(for example:0x00),i delieve 0x01.below is my c programme,could anyone tell me if there&#39;s any problems ?thank you!

    # include <unistd.h># include <string.h># include "system.h"# include "sys/alt_irq.h"# include "altera_avalon_uart_regs.h"# include "alt_types.h"# include "altera_avalon_uart.h"# include "altera_avalon_uart_regs.h"# define rrdy_msk 0x0080# define trdy_msk 0x0080

    //isr for receiving and delievering

    static void uart_isr(void* context, alt_u32 id)

    {

    /*

    * read the status register in order to determine the cause of the

    * interrupt.

    */

    alt_u32 status;

    alt_u8 rxdata;

    status = iord_altera_avalon_uart_status(uart_0_base);

    /* clear any error flags set at the device */

    iowr_altera_avalon_uart_status(uart_0_base, 0);

    /* process a read irq */

    if (status&altera_avalon_uart_status_rrdy_msk)

    {

    rxdata=iord_altera_avalon_uart_rxdata(uart_0_base);

    }

    /* process a write irq */

    if (status&altera_avalon_uart_status_trdy_msk)

    {

    iowr_altera_avalon_uart_txdata(uart0_base, 0x01);

    }

    }

    int main()

    {

    //enable the uart_0 interrupt

    iowr_altera_avalon_uart_control(uart_0_base,altera_avalon_uart_control_rrdy_msk|

    altera_avalon_uart_control_trdy_msk);

    //register the interrupt handler

    alt_irq_register(uart_0_irq,0,uart_isr);

    if(rxdata)

    {

    iowr_altera_avalon_uart_txdata(uart0_base, 0x01);

    }

    return 0;

    }

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

    --- quote end ---

    --- Quote End ---

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

    Please explain again what would you like to accomplish, and what do you get instead.

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

    Thank you .I tried to make an interrupt of receiving charactors,and then delievering what I&#39;ve received.I had problems with baud rate,it was because I forgot to change the property to baut rate changeable,now it&#39;s OK.Thank you again.

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

    <div class='quotetop'>QUOTE (cicizhang @ Dec 20 2006, 08:00 PM) <{post_snapback}> (index.php?act=findpost&pid=20140)</div>

    --- Quote Start ---

    Thank you .I tried to make an interrupt of receiving charactors,and then delievering what I&#39;ve received.I had problems with baud rate,it was because I forgot to change the property to baut rate changeable,now it&#39;s OK.Thank you again.[/b]

    --- Quote End ---

    I try the programme accoring to which you provided,I meet the same question as you, But I understand how you resolve it

    Can you describe concretely!!!