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++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

printf("Hello World \n\r")

Altera_Forum
Honored Contributor II
1,499 Views

To get nios2 to print a line and start a new at left boarder I find it necessary to do 

 

printf(" Hello world \n\r"); 

 

\n alone only advances the line. \r gives the carriage return. 

In the hello_world examples \n is used, not \n\r. 

Have you seen the same? Why is this so? All the windows programs I have encountered needed only \n. 

 

I have tried it in the nios Eclipse debug console for serial IO and in the Hyper Terminal. My system is running in internal initialized ram and with "Small C library" and "Reduced device drivers". 

 

thanks,
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
796 Views

\n means different things depending on the OS. In linux you don't get the carriage return when you use \n so if you don't have that then you'll end up on a new line but spaced over to where the last line stopped. So the \r makes it return to the beginning of the line and \n does the actual line feed (think of a typewritter where you turn the knob and pull the lever to start the next line). 

 

And if I got everything completely backwards I'm sorry (I haven't program much in linux I just remember this being a formatting issue I ran into a while back). The reason why the hello world program probably didn't have them was it was probably intended to be received on a Windows machine, if you try to receive the data in Cygwin or any other linux type system then you will not get the data formatted properly depending on the system used. 

 

Cheers
0 Kudos
Altera_Forum
Honored Contributor II
796 Views

If you're using Hyperterminal ... ugghh! ;-) Try: 

 

File->properties, Settings tab, ASCII setup button: 

check "Append line feeds to incoming line ends" box. 

 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
796 Views

Hyperterminal is a pretty old and generic program so it was created assuming the same format as linux (back in the old days even on an intel machine you had to do LF and CR when outputting). 

 

Don't worry about the \r being in there, windows won't mind (it'll either ignore it or do it twice but you'll still be at the right spot).
0 Kudos
Altera_Forum
Honored Contributor II
796 Views

Tried, but it doesn´t work. 

 

Since Hyperterminal comes with Windows (...), and is suggested also by Altera docs to start playing with UART, if someone has a workaround to obtain the carriage return would be very appreciated. 

 

Thanks 

 

 

 

--- Quote Start ---  

originally posted by smcnutt@Sep 20 2004, 09:29 PM 

if you're using hyperterminal ... ugghh! ;-) try: 

 

file->properties, settings tab, ascii setup button: 

check "append line feeds to incoming line ends" box. 

 

--scott 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=1675) 

--- quote end ---  

 

--- Quote End ---  

0 Kudos
Altera_Forum
Honored Contributor II
796 Views

Try using nios2-terminal with the -U option. I&#39;m not sure which Altera docs you&#39;re referring to, but there&#39;s a solution which recommends against using Hyperterminal, so I&#39;d tend to agree with that. 

 

There are a lot of other serial comm applications for Windows....any of them would be better than Hyperterminal. 

 

Cheers, 

 

- slacker
0 Kudos
Reply