Forum Discussion
Altera_Forum
Honored Contributor
15 years agoUrgent HELP!!! RS232 problem
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 Vincoldes4 Replies
- Altera_Forum
Honored Contributor
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. - Altera_Forum
Honored Contributor
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. - Altera_Forum
Honored Contributor
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.
- Altera_Forum
Honored Contributor
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