Altera_Forum
Honored Contributor
20 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.. byehi
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
--- quote start ---
<!--quotebegin-sandybhai@Oct 15 2006, 04:08 PM 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
<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 String[i] = *UartData; i++; } } 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 <div align='right'><{post_snapback}> (index.php?act=findpost&pid=18775)</div> [/b] --- Quote End ---
Assume your system is based on Nios II:
>map your UART into stdin and stdout >then check with stdio command then you can verify hardware implementation. After doing that you can play with HAL driver.>map your uart into stdin and stdout
>then check with stdio command then you can verify hardware implementation.
after doing that you can play with hal driver.
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19145)
--- quote end ---
--- Quote End --- Hi ledendbb, Could you please elaborate how to map UART into stdin and stdout so that stdio command can be used? Thanks, yjp
--- quote start ---
<!--quotebegin-legendbb@Nov 3 2006, 07:15 AM assume your system is based on nios ii:
>map your uart into stdin and stdout
>then check with stdio command then you can verify hardware implementation.
after doing that you can play with hal driver.
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19145)
--- quote end ---
--- Quote End --- Hi ledendbb, Could you please elaborate how to map UART into stdin and stdout so that stdio command can be used? Thanks, yjp <div align='right'><{post_snapback}> (index.php?act=findpost&pid=19195)</div> [/b] --- Quote End --- Just take a look at the System Library properties page and you'll see the option there. Alternately, you can modify the system.stf file (in the syslib project's top-level directory) to point stdin/stdout/stderr to whichever device you'd like to use. The system.stf is mostly used for holding persistence for GUI settings on the syslib properties page. Cheers, - slacker