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++

uart

Altera_Forum
Honored Contributor II
1,623 Views

Iam using NiosII development kit cyclone edition. I would like to write an application program wherein i can use the uart and also send some data over hyperterminal. Is that possible. If so please tell me how to set the baud rate ,etc. I want to write in c-lang.  

 

please help me
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
484 Views

If you write the application you will not need hyperterminal. 

 

Which OS is your application targetting (I know for windows 2000 and xp this is not too difficult). If you use Visual Studio, they have a bunch of function calls for you which makes it pretty simple (grab a handle to the device, set up some arrays for buffers, then send your packets across). 

 

If you are using .NET this should be a good source --> http://support.microsoft.com/default.aspx?...179&product=vb6 (http://support.microsoft.com/default.aspx?scid=kb;en-us;823179&product=vb6

I have only done this in version 6 of visual studio, but at a quick glance it looks very similar. 

 

If that doesn't help then a google search should lead you on the right path (there are a bunch of sample codes out there for the UART).
0 Kudos
Altera_Forum
Honored Contributor II
484 Views

opposite problem here-- 

 

I would like to have a GUI running on a seperate computer sending commands to the processor using rs232.  

 

i've figured out how to print out to the serial port easy enough, but can not find how i read in data. Any help would be much appreciated. 

 

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif
0 Kudos
Altera_Forum
Honored Contributor II
484 Views

I could send the data from the keyboard and then displayed it on the hyperterminal using uart .That was quite easy. I did not try the other way round. I will try it out soon.

0 Kudos
Altera_Forum
Honored Contributor II
484 Views

Hyperterminal is just showing you the data that is returned from the Uart (from your Nios software), and allows you to send data over the Uart (to your Nios software). It is very easy to do indeed, however I though that you were going to write C code to talk to the Uart on the PC side directly. If you need to do simple debug then I would stick to Hyperterminal to do communication back and forth, however if this is something that needs to be in a final design, then it&#39;s worth it to create a C application that handles the Uart instead of hyperterminal. 

 

sdp. It sounds like if you were able to write to the serial port then the reading part shouldn&#39;t be too bad. What compiler/OS are you targetting with your app? To keep things simple for now you can test your app on it&#39;s own but taking the serial cable out of your PC and shorting pins 2 and 3 together (make sure you short the correct ones). What this will allow you to do is send data out (which you have already figured out) and see if it comes back properly (you are shorting tx and rx together to do a loopback). If your serial cable has a male connector (pins sticking out) on the side you want to short, then I find most PC jumpers (or shunts whatever you want to call them) happen to fit over those pins just nicely http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif (sometimes with hardware you have to be like the A-Team) 

 

If I can find some software I made a while back that does a really simple read and write I&#39;ll email it to the both of you and save you the trouble. If I find it make sure you run it on a machine that&#39;s windows 2000 or xp because I don&#39;t know what will happen on other platforms (the joys of MFC and C++).
0 Kudos
Altera_Forum
Honored Contributor II
484 Views

That&#39;s really nice of u. I will be really happy if u mail those sample programs.  

 

Thankyou
0 Kudos
Altera_Forum
Honored Contributor II
484 Views

In windows (vc6), I believe you have to create a file with the name COM1, then you can use ReadFile and WriteFile to communicate. 

 

 

Initialise serial comms : (f and hcom must be global variables defined somewhere in the project in this example) 

extern HANDLE hcom; extern FILE * f; extern unsigned char page; BOOL InitSerCom(char comport, int baudrate) { //    return true;     page = 255;     char s;     sprintf(s,"COM%d",comport);     if ((hcom = CreateFile(s,GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,       FILE_ATTRIBUTE_NORMAL, NULL)) != NULL)     {  DCB dcb;  sprintf(s,"baud=%d parity=O data=8 stop=1",baudrate);    GetCommState(hcom, &dcb);    BuildCommDCB(s, &dcb);  SetCommState(hcom, &dcb);  COMMTIMEOUTS comt;  comt.ReadIntervalTimeout = 20;  comt.ReadTotalTimeoutMultiplier = 20;  comt.ReadTotalTimeoutConstant = 20;  comt.WriteTotalTimeoutMultiplier = 20;  comt.WriteTotalTimeoutConstant = 20;      SetCommTimeouts(hcom, &comt);  GetCommState(hcom, &dcb);  GetCommTimeouts(hcom, &comt);  return true;     }     else  return false; } 

 

Sending: 

DWORD nrsend; char senddata = &#39;q&#39;;      WriteFile(hcom,&senddata,1,&nrsend, NULL); //check nrsend variable to check it was actually sent 

 

Receive : 

 

DWORD nrrecd; char recdata;      ReadFile(hcom, &recdata, 100, &nrrecd, NULL);   //100 is the buffersize! //nrrecd will be the number of characters actually received 

 

Hope this helps. 

 

Stefaan
0 Kudos
Altera_Forum
Honored Contributor II
484 Views

thanks stefaan and badomen http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif

0 Kudos
Altera_Forum
Honored Contributor II
484 Views

Not sure where my code went, but svhb&#39;s code looks very similar to mine from what I can remember. If you want to know more about the function calls listed in that code check out MSDN.

0 Kudos
Reply