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 Core with CTS/RTS

Altera_Forum
Honored Contributor II
3,113 Views

In a working design I configured my UART core so that it uses CTS/RTS. 

 

But I do not get a simple design running that shall only send integers from a Windws hyperterminal to via the Nios core and back to the hyperterminal.  

 

I have double-checked that the CTS/RTS-pins are connected as stated in the Stratix II development board, which I am using. Also I have the same baud rate (115200). On the hyperterminal I have selected "Flow Control: Hardware". However, nothing happens. 

 

Can somebody help?  

 

Below is the code of my program, which works without CTS/RTS - Hardware Flow Control. 

# include <stdio.h># include "system.h"# include "alt_types.h"# include <time.h># include <sys/alt_timestamp.h> 

 

int main() 

int x; 

 

FILE* infile; 

FILE* outfile; 

 

infile = fopen("/dev/uart1", "r"); 

outfile = fopen("/dev/uart1", "w"); 

 

printf("System ready!\n"); 

fprintf(outfile, "System ready!\n\r");  

while(1) 

// fprintf(outfile,"New Number: "); 

if (fscanf(infile, "%d", &x)) 

fprintf(outfile, "Received: %d\r\n", x); 

printf("Received: %d\r\n", x); 

 

 

return 0; 

}
0 Kudos
10 Replies
Altera_Forum
Honored Contributor II
1,212 Views

One deviec shall not be open twice before it was closed. 

 

Maybe, 

io_file = fopen("/dev/uart1", "rw"); 

.... 

 

I just reply it without confirming anything, so please look up some DATASHEET.
0 Kudos
Altera_Forum
Honored Contributor II
1,212 Views

use a terminal program (e.g. BRAY&#39;s TERMINAL) where you can switch on/off 

RTS and where you can see the state of CTS. 

 

see file altera_avalon_uart_regs.h 

 

you can check CTS at nios side with... 

 

uartstatus=IORD_ALTERA_AVALON_UART_STATUS(UART_1_BASE); 

if(uartstatus&ALTERA_AVALON_UART_STATUS_CTS_MSK) { 

... // cts is set (low) 

 

you can set RTS with ... 

 

ctrl=IORD_ALTERA_AVALON_UART_CONTROL(UART_1_BASE); 

ctrl|=ALTERA_AVALON_UART_CONTROL_RTS_MSK; 

// ctrl&=~ALTERA_AVALON_UART_CONTROL_RTS_MSK; // to clear 

IOWR_ALTERA_AVALON_UART_CONTROL(UART_1_BASE,ctrl) 

 

if CTS is not set, the fast driver will not send any byte, 

RTS is ignored by the driver, you have to handle it by yourself.
0 Kudos
Altera_Forum
Honored Contributor II
1,212 Views

Sorry there was something wrong in my last answer, 

 

the commands to set/reset RTS conflict with the fast  

driver of the uart. 

 

After checking the documetation, 

 

There is no information how RTS and CTS is used by the HAL ! 

There is no description, which flags of the termios structure  

are supported. 

 

How can I set/reset RTS from application ???
0 Kudos
Altera_Forum
Honored Contributor II
1,212 Views

Anyway Fischer, 

 

thanks for your reply that helped me to find Bray&#39;s terminal. At least I no now that my NiosCore works with "clean" CTS/RTS mode.  

 

But in many applications (hyperterminal, matlab) there is the option "FlowControl = Hardware" and this seems not to be clean CTS/RTS, because the communication is simply dying... 

 

Alchemist 

 

P.S: It seems, Altera tries to hide "unimportant details" from the user. However, sometimes some of these details are needed...
0 Kudos
Altera_Forum
Honored Contributor II
1,212 Views

I learned a new term reading this post so now I&#39;m curious..... what is "clean" CTS/RTS mode? (I know flow control but what do you mean by "clean"???). By clean if you mean a clean signal ........ RS232 has never been known to be "clean".

0 Kudos
Altera_Forum
Honored Contributor II
1,212 Views

make sure you set the tx fifo in the com port properties to 1. Do this through control panel - system - device manager. 

 

This is because, when it&#39;s more than 1 (typically 14/16), the PC continues to send data after you raise CTS. It continues until its FIFO is emptied. Thus you would experience Rx overruns on your embedded device.
0 Kudos
Altera_Forum
Honored Contributor II
1,212 Views

 

--- Quote Start ---  

originally posted by badomen@Jun 23 2005, 11:12 AM 

i learned a new term reading this post so now i&#39;m curious..... what is "clean" cts/rts mode?  (i know flow control but what do you mean by "clean"???).  by clean if you mean a clean signal ........ rs232 has never been known to be "clean". 

--- Quote End ---  

 

Hej BadOmen, 

 

with "clean" I meant that only the CTS/RTS and TxD and RxD are used. It is maybe a strange and unofficial term, but since i now have problems with tools like "Hyperterminal" and also "Matlab", where you just specify "FlowControl = Hardware" and do not really know, which pins take part in the communication, I think the term is justified... (When assigning CTS/RTS in a more advanced terminal program, the communication works). 

 

By the way, maybe someone has a experiences with Matlab and CTS/RTS-communication with Nios. I read the Matlab documentation, but did not get it working. 

 

Here are my matlab commands (but I tried other as well): 

 

>> s2 = serial(&#39;COM2&#39;); 

>> set(s2, &#39;BaudRate&#39;, 115200); 

>> set(s2, &#39;FlowControl&#39;, &#39;hardware&#39;); 

>> set(s2, &#39;DataTerminalReady&#39;, &#39;off&#39;); 

>> fopen(s2) 

>> fprintf(s2, &#39;%d&#39;, 3); 

 

Matlab "freezes" after execution of these commands... 

 

So, if somebody has a good idea, it would be great...
0 Kudos
Altera_Forum
Honored Contributor II
1,212 Views

if you use RTS&CTS Handshake and you set hyperterminal to flowcontrol,  

perhaps it also wants to handle DTR/DSR/CD Signals. 

 

assuming 9 PIN SUB-D 

at the PC side, make a bridge between PINS 4 -> 6+1, so the PC  

sets DATA TERMINAL READY(PIN4) and gets back DATA SET READY(PIN6) + CARRIER DETECT(PIN1) 

 

see also http://www.hardwarebook.net/cable/serial/n...lmodem9to9.html (http://www.hardwarebook.net/cable/serial/nullmodem9to9.html)
0 Kudos
Altera_Forum
Honored Contributor II
1,212 Views

Ok I find THE solution: RST/CTS flow control works well. This my code: 

int main() 

char* msg = "Detected the character &#39;t&#39;.\n"; 

FILE* fp; 

char prompt = 0; 

 

fp = fopen("/dev/uart", "r+"); 

unsigned int uart_status; 

unsigned int uart_ctrl; 

if(fp) 

while(prompt != &#39;v&#39;) 

prompt = getc(fp); 

if(prompt == &#39;t&#39;) 

fwrite(msg, strlen(msg), 1, fp); 

 

fprintf(fp, "Closing the UART file.\n"); 

fclose(fp); 

return(0); 

 

This code works under Hyper Terminal with "hardware" flow control. 

 

I found the error. It iwas an Altera error.  

You just have to change : 

CTS: PIN L15 (instead of PIN K15) 

RTS: PIN K15 (instead of PIN L15) 

for the Altera DSP Stratix II Evaluation Board.
0 Kudos
Altera_Forum
Honored Contributor II
1,212 Views

In your code, what do you mean by "&#39" ? 

and how are you checking for an incoming RTS and setting ur own RTS(sending CTS) signal?
0 Kudos
Reply