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 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; }