Forum Discussion
Altera_Forum
Honored Contributor
11 years agoThe 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.