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

Communication with RS232 UART

Altera_Forum
Honored Contributor II
1,616 Views

Hello, 

 

I am just trying to see some activity out of the Avalon RS232 UART. I have instrumented my board's TX and RX lines on my 232 device ands am running the simple example below( Took from Software Handbook and then modified for just writes): 

 

I get the error at runtime: 

nios2-terminal: can't open uart: Permission denied 

 

Any tips or thoughts? 

 

Thanks. 

 

/* A simple program that recognizes the characters &#39;t&#39; and &#39;v&#39; */# include <stdio.h># include <string.h># include "system.h" 

int main() 

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

FILE* fp; 

char prompt = 0; 

 

//fp = fopen ("/dev/uart_1", "r+"); // Open file for reading and writing 

fp = fopen ("/dev/uart_1", "w"); // Open file for reading and writing 

//print a message to console 

//printf(" I am starting UART Test \n "); 

fprintf(fp, "Open the UART \n"); 

 

//printf(" Should have written to UART .\n"); 

 

if(fp) 

fprintf(fp, "%s",msg); 

fclose(fp); 

/* 

if(fp) 

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

{ // Loop until we receive a &#39;v&#39;. 

prompt = getc(fp); // Get a character from the UART 

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

{ // print a message if character is &#39;t&#39;. 

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

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

fclose (fp); 

*/ 

return 0; 

}
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
542 Views

Hello, 

 

Just an update to this problem. The nios2-terminal problem was due I believe to another session already open, hint I got from Altera. However, the simple HAL file example, where the UART is treated as a character device still does not work. I have double checked my connections,SOPC build, pin files, analyzer settings, trigger,etc, but I do not see any activity on the TX pin of the FPGA when I run my example( borrowed from Altera&#39;s software manual). 

 

Any thoughts on UART RS232 comm? 

 

Thanks.
0 Kudos
Altera_Forum
Honored Contributor II
542 Views

Hello, 

 

This turned out to be operator error.  

 

The code example above works fine on a custom board that we are developing. The HAL approach is very clean as opposed to setting up registers for the UART. Also, I am using the Bray terminal that I saw referenced here in the forum, it is much better than Hyperterminal! 

 

http://bray.velenje.cx/avr/terminal/ (http://bray.velenje.cx/avr/terminal/

 

 

-Baycool
0 Kudos
Reply