Altera_Forum
Honored Contributor
19 years agoUART - 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
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