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

Urgent HELP!!! RS232 problem

Altera_Forum
Honored Contributor II
1,278 Views

Hi all, 

 

I trying to send signal through the RS232 port. 

 

I have problem in sending out the integer/character. Below is my code: 

 

void serial() 

unsigned int a = 0x61626364; 

char* msg = "Testing 't'.\n"; 

char *b; 

char e[16]; 

unsigned char ch='f'; 

int c; 

 

system("pause"); 

FILE *fp; 

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

 

while(1) 

b=&e; 

for(c=16;c>=1;c--) 

if (fp) 

 

*b = getc(fp); 

printf("%c",*b); 

//if (ferror(fp))// Check if an error occurred with the file 

//clearerr(fp);// If so, clear it 

//putc('c',fp); 

for(c=16;c>=1;c--) 

IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE,ch); 

usleep(1000); 

} THIS IS THE PROBLEM PART!!! 

 

 

If possible, please provide me with example of simple RS232 transmission. 

THANKS!! 

 

Regards 

Vincoldes
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
314 Views

What exactly the problem is? 

Are you losing tx data? If so, this is because usleep delay is too short for your current baudrate; you'd better poll the transmitter empty in status register for transmission completion instead of using a fixed delay.
0 Kudos
Altera_Forum
Honored Contributor II
314 Views

Wouldn't fprintf(fp,"%c",ch); work instead of the IOWR call. The usleep would then not be necessary. Not a good practice to use usleep unless you absolutely need to.  

Also, don't forget the # include <stdio.h> line.
0 Kudos
Altera_Forum
Honored Contributor II
314 Views

Its never a good idea to mix different access level/modes on the same hardware. If you deceide to use the standard lib function for input then use them also for output.

0 Kudos
Altera_Forum
Honored Contributor II
314 Views

hi .... 

 

you can change the stdout , stderr and stdin on your nios2 clicking with right button on your design and select system libraty properties (change to your rs232 out)....... if you did that you can use printf to put data on your rs232 

 

thats it 

 

Franz Wagner
0 Kudos
Reply