- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
i have a question what would be the best way to transfer 32-bit integers using UART in nios? I've allready made a simple nios design with uart connected to on-chip memory. I wrote a base echo uart application, which works great:
alt_u8 data;
while(1)
{
if( IORD_ALTERA_AVALON_UART_STATUS( UART_BASE ) & 0x80 )
{
data = IORD_ALTERA_AVALON_UART_RXDATA( UART_BASE );
IOWR_ALTERA_AVALON_UART_TXDATA( UART_BASE, data );
printf("%c",data);
}
}
But mainly I'd like to send 32bit integer data from PC to fpga board. How should I organise it? Should I use 32bit - DMA connected to uart and read 5bits of data every time? or maybe there is a simpler way? Thanks in advance
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Unless you really need the speed (but seeing that you used printf in your code I suspect you don't), why not just read the bytes one by one?
Regards, Andreas- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
maybe you could use the HAL file system as described in the embedded peripherals ip user guide / uart core./* A simple program that recognizes the characters 't' and 'v' */# include <stdio.h># include <string.h>
int main ()
{char* msg = "Detected the character 't'.\n";
FILE* fp;
char prompt = 0;
fp = fopen ("/dev/uart1", "r+"); //Open file for reading and writing
if (fp)
{while (prompt != 'v')
{ // Loop until we receive a 'v'. prompt = getc(fp); // Get a character from the UART.
if (prompt == 't')
{ // Print a message if character is 't'.
fwrite (msg, strlen (msg), 1, fp);
}
}
fprintf(fp, "Closing the UART file.\n");
fclose (fp);
}
return 0;
}
It's not an example how to transfer 32 bit, but it shows you how to open a device with the HAL file system and sending/receiving data. I would recommend to use something like fwrite(&buffer32bit,4,1,fp) and fread(&buffer32bit,4,1,fp). I never tried it, but I guess it should work. But I also would recommend to use the uart-registers directly (as you did in your example) and read byte by byte. Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would be wary about sending binary data over a uart connection. The system software at the host end might act on some byte values (eg for flow control).
It you are sending 32bit data you also need to be aware of the endianness of the data - do you send the least or most significant 8 bits first. You also might want to use a simple data encapsulation protocol so that the reciever knows what data is being sent, and to allow additional requests to be added later.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want to send binary data over a serial line you will have to use/design some kind of communication protocol. Otherwise things might get nasty soon.
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