--- Quote Start ---
Hello!
I'm have the same doubt... Im using the altera RS232 university program, and I use the functions described in the datasheet of the RS232 core.
I was trying to send some data with nios 2 to the rs232... but I could't get any success yet.
Here's the code:
# include <stdio.h># include <system.h># include <string.h># include <stdlib.h># include <unistd.h># include "altera_up_avalon_rs232.h";
int main()
{
int c;
printf("\033[2J"); //clean screen
printf(" Start.\n");
alt_u8 data;
unsigned int space;
alt_u8 temp;
alt_u8 RS232_dev;
data = 2; //just some data to send...
RS232_dev = alt_up_rs232_open_dev (RS232_NAME);
space = alt_up_rs232_get_available_space_in_write_FIFO(RS232_dev);
printf("%d\n", space);
while (1)
{
temp = alt_up_rs232_write_data(RS232_dev, data);
printf("%d", temp); //if temp is =0, the data was send...
for(c=1; c<=100000; c++) //delay
{}
}
return 0;
}
The function "alt_up_rs232_write_data" is returning "0", that means success... but I'm geting nothing through RS232, which I'm reading with a software (like Hyperterminal) in a computer.
Link to the datasheet of the RS232 core:
ftp://ftp.altera.com/up/pub/altera_material/11.1/university_program_ip_cores/communications/rs232.pdf Thanks!
--- Quote End ---
This is my test code, a simple program to test the NIOSII functionality. It works, the only problem is that my terminal (Teraterm) shows strange delays and crashes very often. Anyway the RS232 works:
# include "sys/alt_stdio.h"# include "alt_types.h"# include "system.h"# include "altera_up_avalon_rs232.h"# include "altera_avalon_pio_regs.h"# define CLOCK_MHz 27
static void delay_us(int us);
int i;
int times;
alt_u16 sw;
alt_u8 data;
alt_u8 error;
int e;
/**************INITIAL MESSAGE*************/
static void initial_message()
{
alt_putstr("\n*****************************\n");
alt_putstr("* Hello from Nios II! *\n");
alt_putstr("*****************************\n");
}
/****************DELAY*********************/
static void delay_us(int us)
{
times=CLOCK_MHz*us;
for(i=0;i<times;i++){;}
}
/*****************MAIN**********************/
int main()
{
initial_message();
alt_up_rs232_dev* serialPort = alt_up_rs232_open_dev(RS232_0_NAME);
delay_us(100);
while(1)
{
sw=IORD_ALTERA_AVALON_PIO_DATA(PIO_SWITCHES_BASE);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LEDR_BASE,sw);
e=alt_up_rs232_read_data(serialPort, &data, &error);
delay_us(1000);
e=alt_up_rs232_write_data(serialPort, data );
}
}
Try with another terminal and be shure to set the right configuration.