Forum Discussion
Altera_Forum
Honored Contributor
11 years ago --- Quote Start --- The easiest way was to get the ALTERA university program (UP) IP cores. I added a RS232 UART component (from the UP) to a Qsys system and then used the HAL drivers (#include <altera_up_avalon_rs232.h>) supplied with the UP to receive and send data with a simple nios ii program. Open up the uart device: alt_up_rs232_dev *rs232_0_dev; rs232_0_dev=alt_up_rs232_open_dev("/dev/rs232_0"); I then wait for data from the UART: while((alt_up_rs232_get_used_space_in_read_FIFO(rs232_0_dev))==0) { //wait for a character from the UART } Once a byte of data is ready i read it: alt_up_rs232_read_data(rs232_0_dev, &in_buffer[index1], &parity_read1) Writing data is similar, wait for free space in the UART outgoing buffer and send data: while(alt_up_rs232_get_available_space_in_write_FIFO(rs232_0_dev)==0) { //printf("waiting for space in out fifo\n"); } //printf("after waiting for space in out fifo\n"); if(alt_up_rs232_write_data(rs232_0_dev,temp1[index2])==0) { } A MUCH more elegant solution would be using nios ii interrupts, this simple example "blocks" the program until a specific amount of data is read (you have to wait for data before the program can do other things). In the university program folder you can find more examples using the UART core. --- Quote End --- Hi Fred, Thanks for your reply. What I want to do is Nios processor reads data from FPGA, Nios transmits the data to serial port and plot graph real time using Maltab,using de0 nano. I do not need to read data from serial port. 1. I used the following code to access the UART component I created in Qsys, I connected the txdata pin to the oscilloscope and it shows nothing, i am wondering why couldn't I use IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, txdata); to transmit data to UART? 2. Quate "Writing data is similar, wait for free space in the UART outgoing buffer and send data:" When you said, send data, do you mean IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, txdata)? I really hope to get some hints from you, been struggling for a while, thanks for your kind help. # include "altera_avalon_uart_regs.h" # define UART_BASE 0x00002000 int main (void) {alt_u16 status, rxdata=0,aa=0, txdata=0; while (! (status & 0x0040)) // Wait for transmission completion status = IORD_ALTERA_AVALON_UART_STATUS (UART_BASE); printf("status= %.2f V \r\n", (float) status); rxdata = 5; // assuming I get this data by accessing sdram in Nios txdata = rxdata; IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, txdata); printf("txdata= %.2f V \r\n", (float) txdata); return 0;}