Hi Bala,
Adding a UART to SOPC is quite simple. Select AvalonComponents\Communication\UART(RS-232 serial port). For simplicity, you might want to start by having a fixed Baud rate, at say 9600 Bd, common settings for the other items are parity=none, 8 data bits and 1 stop bit. Don't include any flow control at this stage as this may hamper your initial attempts to get communicating. You should now have a serial device setup for 9600,N,8,1,no-handshake - which is pretty unambiguous.
Quartus will now show the two new connections on the NIOS design, rxd_to_the_uart and txd_from_the_uart. These will need to be assigned to external pins using the assignment editor. The rxd pin should default to Vcc.
I don't know what your Altera hardware looks like but if you want to talk to a PC (into COM1: etc) you need to supply the proper RS-232 levels of -12v and +12v. Quite often boards will only present themselves to the outside world at TTL levels of 0v and +5v. Perhaps this is your problem. You need to check this. Also, check which is your Tx and Rx pins, you would be surprised how often stuff doesn't work because Rx is connected to Rx and Tx is connected to Tx. (On PC 9-pin-D Rx [into PC] is pin2 and Tx [out of PC] is pin3). I have also encountered problems trying to communicate with PCs that only have USB and not the traditional DB9 connectors.
If you don't have proper RS-232 levels from your board you will have to make some kind of interface board to do the level shifting. Try searching for datasheets on devices like MAX232 or DSV14196WM.
That should take care of the hardware.
On the software side, there are various ways to implement a serial channel depending on your needs but this should be enough to make the port send characters out. Hyperterminal on your PC (with the appropriate settings) should be perfectly adequate to make the connection.
# include "altera_avalon_uart_regs.h"
void endless_send(void)
{
unsigned char ch;
unsigned int stat;
/* make sure no IRQ enabled */
IOWR(UART_BASE, 3, 0x00);
/* flush any characters sitting in the Rx holding register */
i = IORD(UART_BASE, 0);
i = IORD(UART_BASE, 0);
ch = ' ';
for (;;) {
/* get serial status */
stat = IORD(UART_BASE, 2);
/* check for character Rx */
if (stat & 0x0080) {
/* if character is '1' then reset o/p character back to ' ' */
if (IORD(UART_BASE, 0) == '1') ch = ' ';
}
/* check if able to Tx next character. */
if (stat & 0x0040) {
IOWR(UART_BASE, 1, ch);
/* increment character but keep in printable range */
ch++;
if (ch==0x80) ch = ' ';
}
}
}
Once you have established a link you can go back to SOPC and experiment with changing Baud rates etc.
I hope this is of some help.
Banx.