RS-232 UART

The RS-232 UART (Universally Asynchronous Receiver-Transmitter) is a serial protocol UART, allowing for a connection between a terminal and the DE2 Board. It is configured for 8-bit data, one stop bit, odd parity, and a baud rate of 115,200.

DeviceRS-232 UART
ConfigurationTwo 32-bit mapped registers
Input/OutputEither
Address Base0x10001010
Address Map
AddressR/WDescription
baseR/WData Register
23:16 - Number of characters available to read (after this read - see Notes)
15 - read data valid
9 - parity error
7:0 - the data itself
base+4R/WControl Register
23:16 - Spaces available for writing
9 - Write interrupt is pending
8 - Read interrupt is pending
1 - Enable write interrupts
0 - Enable read interrupts
InitializationNone
Interrupts
TriggeredOn data-received or able to send (see below)
IRQ Line10
EnableSet bit 1 and/or 0 in the Control Register for write and read interrupts respectively.
AcknowledgeRead (write) interrupts acknowledged by reading (writing) to the Data Register
Hardware SetupPlug the serial cable into the serial outlet on the DE2 Board (also see Notes)
ReferenceFull documentation from Altera.
Section 2.5 of the DE2 Media Computer Manual

Notes

To communicate through the RS-232, you must set up a terminal to send and receive characters. Open the Conport program (in the lab, this can be found on the network drive, X:\TTERMPRO, as ttermpro.exe), ensure that the Baud Rate is set to 115200 (for the default system, or whatever your baud rate is in a custom system), and ensure that it is communicating through CON1.

Assembly Example: Receiving a character through the RS-232 UART

POLL:
    movia r7, 0x10001010 /* r7 now contains the base address */
    ldhio r2, 2(r7) /* Load from the UART */
    beq   r2, r0, POLL /* If this is 0 (branch true), data is not valid */
    ldwio r2, 0(r7)

C Example: Sending "Hello World" through the UART

#define RS232_UART_DATA ((volatile int*) 0x10001010)
#define RS232_UART_CONTROL ((volatile int*) (0x10001010+4))

int main()
{
    unsigned char hwld[] = {'H','e','l','l','o',' ','W','o','r','l','d','\0'};
    unsigned char *pOutput;

    pOutput = hwld;
    while(*pOutput) //strings in C are zero terminated
    {
         //if room in output buffer
         if((*RS232_UART_CONTROL)&0xffff0000  ) 
         {
            //then write the next character
            *RS232_UART_DATA = (*pOutput++); 
         }
     }
}