Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,079 Views

Using rs232 HAL in Nios II IDE

Hello,  

I hope someone could give me a hint to unblock my situation: I have troubles in using HAL for university program RS232 in Nios2 IDE.  

I included "altera_up_avalon_rs232.h", I spent days trying to use the macros without any result. I followed the specifications in the Nios Software Handbook and RS232 documentation I get errors when calling the write and read macros. I post you some functions I made: 

 

void uart_write(unsigned char ch) 

alt_up_rs232_write_data(RS232_BASE, ch); 

unsigned char uart_read() 

unsigned char character; 

int* addr_parity=&parity; 

error = alt_up_rs232_read_data(RS232_BASE, &character, addr_parity); 

return character; 

void uart_open() 

{alt_up_rs232_open_dev(RS232_NAME);}  

 

I red that "alt_up_rs232_open_dev(RS232_NAME);" shuld return a alt_up_rs232_dev* type...what should I write to get things work? 

 

Thank you a lot 

 

rollingringhio
Tags (1)
0 Kudos
7 Replies
Altera_Forum
Honored Contributor I
76 Views

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.pd... 

 

Thanks!
Altera_Forum
Honored Contributor I
76 Views

 

--- 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.pd... 

 

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.
Altera_Forum
Honored Contributor I
76 Views

Hello!  

 

&#12288; 

I made some change in my code, but it still very similar to yours... I'm geting no response of the data that Im sending throught Rs232... I can send some data, using the Altera U.P. write function, but the data that I receive, is "not what i send", i think the problem maybe is the type of the data (alt_u8), but i already tried char value, hexa value and bin value, and I never get success, I only receive strange values. 

 

I'm using Tera Term, and another simple terminal. None of them worked. 

Thank you!  

 

# 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"); //  

printf(" start\n"); 

alt_u8 data; 

unsigned int space; 

alt_u8 error; 

//data = 0x42; //- letra

alt_u8 temp; 

//alt_u8 RS232_dev; 

alt_up_rs232_dev* RS232_dev = alt_up_rs232_open_dev (RS232_NAME); 

for(c=1; c<=1000000; c++) //delay 

{} 

space = alt_up_rs232_get_available_space_in_write_FIFO(RS232_dev); 

printf("%d\n", space); 

while (1) 

temp = alt_up_rs232_read_data(RS232_dev, &data, &error); 

printf("feddbackREAD:%d ", temp); 

printf("errosREAD: %d\n", error); 

temp = alt_up_rs232_write_data(RS232_dev, data); 

printf("feedbackWRITE: %d ", temp); 

printf("valorDATA: %d\n", data); 

for(c=1; c<=1000000; c++) //delay 

{} 

&#12288; 

return 0; 

 

&#12288; 

Altera_Forum
Honored Contributor I
76 Views

Hi, 

Now I see I have the same problems with RS232...I assigned the alt_u8 value red from RS232 to the DE1 green leds and also sent it to JTAG UART. I only get always the same strange symbol and nothing varies if different characters are sent from the terminal. I noted that in my BSP config table there isn't the choice to select RS232 as stdout device in place of JTAG UART...maybe the things are related, does it happen to you too?
Altera_Forum
Honored Contributor I
76 Views

The same is happening with me, in BSP editor I only can choise the jtag as a stdout... Im trying to edit and understand the rs232 verilog component generated by altera U.P.

Altera_Forum
Honored Contributor I
76 Views

 

--- Quote Start ---  

The same is happening with me, in BSP editor I only can choise the jtag as a stdout... Im trying to edit and understand the rs232 verilog component generated by altera U.P. 

--- Quote End ---  

 

 

Hi Gp150,  

sorry, I was away from keyboard for some time.  

Did you get something interesting?
Altera_Forum
Honored Contributor I
76 Views

I could send some data to PC, using your code. I had some problems with clock, but I could solve it.  

But I couldn't receive data in the FPGA when I send it from PC!
Reply