- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 VincoldesLink Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page