Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12589 Discussions

help on rs232 communication niosII

Altera_Forum
Honored Contributor II
2,020 Views

How do I get to communicate with the Nios II via serial pc? 

Basically I would like nios II sends a string to the serial port. 

 

I use The Nios® II Software Build Tools (SBT) for eclipse.  

 

I wrote the following code: 

# include<stdio.h> 

int main(){ 

printf("Hello world"); 

 

and then I tried to change the standard input and output to UART1 standart but nothing is written to the serial. 

 

 

you could tell me some tutorials on the serial communication between the PC and nios II? 

 

 

thanks in advance for help
0 Kudos
13 Replies
Altera_Forum
Honored Contributor II
482 Views

First Add the RS232 on system using SOPC  

 

Then Open RS232 Port on Eclips. 

 

then use std. fprintf for sending the data on RS232
0 Kudos
Altera_Forum
Honored Contributor II
482 Views

kaushal's answer is right, you do it in according with his answer.

0 Kudos
Altera_Forum
Honored Contributor II
482 Views

I added the RS232 on system using SOPC. 

 

How to open RS232 Port on eclipse? If I use jtaguart as stdin and stdout the code works but if I use RS232 don't work.... 

 

Thanks in advance for help
0 Kudos
Altera_Forum
Honored Contributor II
482 Views

 

--- Quote Start ---  

I added the RS232 on system using SOPC. 

 

How to open RS232 Port on eclipse? If I use jtaguart as stdin and stdout the code works but if I use RS232 don't work.... 

 

Thanks in advance for help 

--- Quote End ---  

 

write down below code in your main file. 

 

 

 

FILE *fp; 

 

fp = fopen("----copy past path of your RS232 file from system .h-----","rb"); 

if(fp==NULL) 

printf("\nFile /RS232 not open for writing...."); 

 

else 

 

fprintf(fp,"%d",---data (int)which you want to write on RS232---); 

 

 

fclose(fp);
0 Kudos
Altera_Forum
Honored Contributor II
482 Views

Solved thanks.

0 Kudos
Altera_Forum
Honored Contributor II
482 Views

Could you post what you did to solve the problem in case others have the same issue?

0 Kudos
Altera_Forum
Honored Contributor II
482 Views

I solved it using the code posted by Kaushal. I was wrong path of my RS232 file from system .h ...  

 

I opened the file system.h, and I put the right path.  

 

Note: if you use a serial sniffer like Hyperterminal you check that you have it set up correctly.. 

 

Sorry for my english but I am Italian if there are any problems please do not hesitate to ask. :D
0 Kudos
Altera_Forum
Honored Contributor II
482 Views

fopen("/dev/uart/","w") returns NULL for me, do you know what could fix this?

0 Kudos
Altera_Forum
Honored Contributor II
482 Views

 

--- Quote Start ---  

fopen("/dev/uart/","w") returns NULL for me, do you know what could fix this? 

--- Quote End ---  

 

go to the system.h and find out the exact path for rs232 and then use that path for fopen
0 Kudos
Altera_Forum
Honored Contributor II
482 Views

Hi there. 

I'm new with Nios SBT for Eclipse and I'm facing a problem with the rs232. 

Just like ermanno.tedeschi, I need to use the serial port but, despite I have added the RS232 on my system using SOPC, I cannot make the 'fopen' and the 'fclose' commands works... 

Does anybody has some tip/hint...something to tell me? 

 

Cheers
0 Kudos
Altera_Forum
Honored Contributor II
482 Views

make sure you have add the correct header files ....for fopen and fclose

0 Kudos
Altera_Forum
Honored Contributor II
482 Views

Hi guy, 

I figured out what was wrong with the project. 

Firstly, I setted up the wrong pins on quartus. 

Then, instead of using 'fopen' and 'fclose' commands, I used "IOWR_ALTERA_AVALON_UART_RXDATA(UART_0_BASE, (data-to-be-send))". 

It worked!
0 Kudos
Altera_Forum
Honored Contributor II
482 Views

I am Italian let me know what is your problem.

0 Kudos
Reply