- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hello everyone.
I am trying to send and receive data between UART on UP3 and hyperterminal. But am not able to set the interrupts properly and as a result my program goes in an infinite loop. here is a part of my code....could u plz tell me what else needs to be added to the code so that an interrupt is generated when some data comes on the serial port.. int main(void) { int led = 0x01; int ch = 0; FILE *fd; /* Initialise the interrupt controller. */ alt_irq_init (ALT_IRQ_BASE); IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,led); // write initial value to pio /* initialise the device drivers/software components*/ alt_sys_init(); # ifdef UART_BASE fd = fopen("/dev/uart", "r+"); # endif if(fd){ while(1){ if(FLAG_READ){ /* it is set inside the alt_avalon_uart_rxirq() function when some data is received */ alt_avalon_uart_read(fd,ch,sizeof(int)); break; } // end of if } // end of while } // end of if if(ch == 'a') led = 0x02; else led = 0x04; IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,led); // write new value to pio fclose(fd); } whenever i run this code it doesnt come out of the while loop even when i type something on the hyperterminal. Plz helo me out thnx sourabh goelLink Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- originally posted by sourabhgoel83@Sep 9 2005, 07:41 PM hello everyone.
i am trying to send and receive data between uart on up3 and hyperterminal. but am not able to set the interrupts properly and as a result my program goes in an infinite loop.
here is a part of my code....could u plz tell me what else needs to be added to the code so that an interrupt is generated when some data comes on the serial port..
int main(void)
{
int led = 0x01;
int ch = 0;
file *fd;
/* initialise the interrupt controller. */
alt_irq_init (alt_irq_base);
iowr_altera_avalon_pio_data(led_pio_base,led); // write initial value to pio
/* initialise the device drivers/software components*/
alt_sys_init();
# ifdef uart_base
fd = fopen("/dev/uart", "r+");
# endif
if(fd){
while(1){
if(flag_read){ /* it is set inside the alt_avalon_uart_rxirq() function when some data is received */
alt_avalon_uart_read(fd,ch,sizeof(int));
break;
} // end of if
} // end of while
} // end of if
if(ch == 'a')
led = 0x02;
else
led = 0x04;
iowr_altera_avalon_pio_data(led_pio_base,led); // write new value to pio
fclose(fd);
}
whenever i run this code it doesnt come out of the while loop even when i type something on the hyperterminal.
plz helo me out
thnx
sourabh goel
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=9658)
--- quote end ---
--- Quote End --- Hi sourabh goel, Why don't you try an284 on www.altera.com ? Note : This application note was written for NIOS system. If you are using NIOSII , you would have to convert some of the functions to be NIOSII-compatible. You can reference to an350 to do it. Good luck, Quan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a reason you're not using the HAL provided routines? Even if they're not exactly what you need, at least you can test the initial functionality...and they might provide a decent starting point for your own code.
See the Software User's Guide in the documents directory for more info. Cheers, - slacker- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
See discussions
http://forum.niosforum.com/forum/index.php?showtopic=3749 (http://forum.niosforum.com/forum/index.php?showtopic=3749) http://forum.niosforum.com/forum/index.php?showtopic=4609 (http://forum.niosforum.com/forum/index.php?showtopic=4609) http://forum.niosforum.com/forum/index.php?showtopic=477 (http://forum.niosforum.com/forum/index.php?showtopic=477) http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/rolleyes.gif- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey all,
Here is some working code for an UART RX interrupt: A interrupt function which takes the data from the serial port (and put it into for example in a char array) 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: // UART1 interrupt routine declaration alt_irq_register(UART1_IRQ,NULL,UartReceiver1); IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE, 0x80); Kind regards Karel
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page