Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
10 years ago

Help with Basic Concept Please

Hello folks, Having lots of trouble understanding a simple concept. I would like to know how the data register works for this UART. From the Data sheet, this is what info i have:

device

RS-232 UART

configuration

Two 32-bit mapped registers

input/output

Either

address base

0x10001010

address map

address

r/w

description

base

R/W

Data 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+4

R/W

Control 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

Now a simple question, Let's say i want to read the UART of the Board, i wrote a short code in C for (Altera Monitor Program) but i get a garbage as input. Using a Terminal on PC to send some characters, and would like to display them on the HEX Disp. Here is what i tried to do:

------------------------------------------------------------------------------

mask = ((*RS232_UART_DATA)&0xFF00FF); // Reading the UART and masking some bits

HEX=mask; // Storing data to be written to hex

------------------------------------------------------------------------------

The issue is before i even get to send a character from the PC side, i start seeing garbage on HEX. And when i do attempt to send a character, the HEX shows more garbage. At least i can be sure the data is being transmitted, but i have no knowledge on how to mask the DATA Register appropriately. ANY HELP WOULD BE APPRECIATED!!!!

Thanks.

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    zikmir, you posted several uart related questions in the past few days.

    Here is a very useful thread on how to use UART to communicate with external devices such as PC: http://www.alteraforum.com/forum/showthread.php?t=17224

    I've used this code successfully to talk to the PC.

    --- Quote End ---

    Thanks for your reply, my issue is not on coding, and i am not familiar with the methods you have used. My entire question is trying to understand how the hardware it self has to be configured, as of the DATA Register and Control Register. I am already able to print any characters to the Terminal(Sending from UART to PC) but i really need some help on the opposite direction. If you may help me with this specific issue i would be glad than using some one else code.

    Kindly if you or any one can guide me on how to read the UART. Here is my code:

    # include <stdio.h># define RS232_UART_DATA ((volatile int*) 0x10001010)# define RS232_UART_CONTROL ((volatile int*) (0x10001010+4))

    int main()

    {

    unsigned char *pOutput;

    unsigned char mask;

    while(1) //strings in C are zero terminated

    {

    mask = ((*RS232_UART_DATA)&0xFFFF0000); // mask incoming UART

    if (mask!=0){

    pOutput=((*RS232_UART_DATA)&0x0000ff);

    }

    if((*RS232_UART_CONTROL)&0xff0000 ){

    *RS232_UART_DATA = (*pOutput); } //output back to PC Terminal

    }

    }