Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

Communication with RS232 UART

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;

}

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.