Forum Discussion
Altera_Forum
Honored Contributor
19 years agoan 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 pr...
Altera_Forum
Honored Contributor
19 years ago --- Quote Start --- originally posted by cicizhang@Dec 18 2006, 08:07 PM 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;
}
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=20090)
--- quote end ---
--- Quote End ---