UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Newbie dedanan
Newbie
14,500 Views
Registered: ‎02-16-2009

how to read data from the serial port?

Hello everybody, i have a problem: i dont know how to read data from the serial port.

 

i explain my goal: i have a mobile platform with 2 motored wheels, a nexys2 fpga board and a pc on my mobile platform. i have to create a connection between the pc and the fpga with the serial port. At the moment i can write on the serial (i use xil_printf) and i see all with hyperterminal on my pc but it isnt very important for my project. the problem is that i cant do the opposite, i dont know how to read data in the same way. The goall will be to elaborate data with the pc and send the velocity to the fpga via serial.

 

thanks for help and sorry for the bad english! 

0 Kudos
15 Replies
Visitor rents85
Visitor
14,477 Views
Registered: ‎12-10-2008

Re: how to read data from the serial port?

I have the same problem . I would like use rs232 with interrupt and i find this http://warp.rice.edu/trac/browser/trunk/EDK_Demos/UberDemo/demoapp2.c?rev=15 . I don't understand this function :

XIntc_RegisterHandler(XPAR_OPB_INTC_0_BASEADDR, XPAR_OPB_INTC_0_RS232_INTERRUPT_INTR, (XInterruptHandler)uart_int_handler, (void *) 0);.

What is XPAR_OPB_INTC_0_RS232_INTERRUPT_INTR?

 

0 Kudos
Historian
Historian
14,459 Views
Registered: ‎02-25-2008

Re: how to read data from the serial port?


rents85 wrote:

I have the same problem . I would like use rs232 with interrupt and i find this http://warp.rice.edu/trac/browser/trunk/EDK_Demos/UberDemo/demoapp2.c?rev=15 . I don't understand this function :

XIntc_RegisterHandler(XPAR_OPB_INTC_0_BASEADDR, XPAR_OPB_INTC_0_RS232_INTERRUPT_INTR, (XInterruptHandler)uart_int_handler, (void *) 0);.

What is XPAR_OPB_INTC_0_RS232_INTERRUPT_INTR?

 


Look in xparameters.h.

 

-a

----------------------------Yes, I do this for a living.
0 Kudos
Contributor
Contributor
14,241 Views
Registered: ‎06-13-2008

Re: how to read data from the serial port?

 
0 Kudos
Contributor
Contributor
14,239 Views
Registered: ‎06-13-2008

Re: how to read data from the serial port?

Hi all,

 

I'm a newbie and have a similar question. I am using a Spartan3A-1800A-DSP Board, and I want to communicate my board and PC. I'm trying to send data to RS232 by using a C program such as " printf"hello world" " , and hopefully can get it shown back on PC hyper-terminal.

 

Could anyone let me know how I can achieve this? Or some tutorials recommended will also be a help.Thank you in advance.

 

Kind regards,

tarzandavid

0 Kudos
Highlighted
Observer robbi11880
Observer
14,184 Views
Registered: ‎11-11-2008

Re: how to read data from the serial port?

Hello tarzan,

 

I work with the same board, EDK, MicroBlaze and RS232.

 

Sending Data: There are two opportunities. You can configure the RS232 as Standard I/O. From this it follows that the methods "xil_printf" or "print" prints a string via Standard I/O (in this case RS232) to the console which is connected to the serial port of the PC (in your (windows) case: hyperterminal; for linux: minicom). Write "xil_printf("Hello World\n\r"); in your C-File and you get what you want to.

The second opportunity is to send a databuffer via RS232. Then there is no need to set it as Standard I/O. An example for sending a buffer, is delievered with EDK in its installation path (installationpath/EDK/sw/XilinxProcessorIPLib/drivers/uartlite_v_1_12_a/examples). You can find necessary functions in xuartlite.h.

 

Receivind Data: see examples and xuartlite.h.

 

Hope this helps.

 

Best regards, Robbi

 

0 Kudos
Contributor
Contributor
14,156 Views
Registered: ‎06-13-2008

Re: how to read data from the serial port?

hi robbi,

Thanks a lot for your suggestion, I'll try to do as what you told me. Really appreciated. :-)

tarzan

0 Kudos
14,133 Views
Registered: ‎09-05-2008

Re: how to read data from the serial port?

Hi together,

if you want to read data from a serial port that is connected to stdin,

you may follow this link :

http://forums.xilinx.com/xlnx/board/message?board.id=EDK&message.id=6717#M6717

 

--Ralf

0 Kudos
Contributor
Contributor
14,103 Views
Registered: ‎06-13-2008

Re: how to read data from the serial port?

Hi ralfcantnerbosch,

 

In the link you posted you mentioned "Hyperterminal sends each character as soon as you type it. It does not wait for the <RETURN> key. ", have you connected the board to PC under this circumstances?

 

tarzan

0 Kudos
Observer robbi11880
Observer
14,100 Views
Registered: ‎11-11-2008

Re: how to read data from the serial port?

Hello tarzan,

 

are you working with EDK? If true, you can set the RS232 device as STD I/O in *.mss-file for your OS like:

BEGIN OS
 PARAMETER OS_NAME = standalone
 PARAMETER OS_VER = 2.00.a
 PARAMETER PROC_INSTANCE = microblaze_0
 PARAMETER STDIN = RS232_Uart_1
 PARAMETER STDOUT = RS232_Uart_1
END

 

-> "Hyperterminal sends each character as soon as you type it. It does not wait for the <RETURN> key. "

I think this simply means how Hyperterminal works. If the serial connection is build up and you press a key on your keyboard (of the pc), the ASCII code of the key you pressed is sended via serial-interface. There is no need of pressing <RETURN> to confirm the sending.

 

I also have connected the Spartan-3A DSP Board to PC to communicate. 

More questions?

 

Greetz Robbi 

 

0 Kudos
Xilinx Employee
Xilinx Employee
8,740 Views
Registered: ‎08-01-2007

Re: how to read data from the serial port?

dedanan,

 

You would use a RecvByte or Recv function of the Uart driver. 

 

The available functions for a driver are available in the API documentation. For example if you are using the xps_uartlite peripheral, then you would look at $XILINX_EDK/sw/XilinxProcessorIPLib/drivers/uartlite_v1_13_a/doc/html/api/index.html for the available functions in this driver. 

 

Hope this helps...

 

 

0 Kudos
Observer robbi11880
Observer
8,735 Views
Registered: ‎11-11-2008

Re: how to read data from the serial port?

Hello dedanan,

 

that's right what centaur10 says.

For receiving data via RS232 you need a RecvBuffer. Look after examples in:

$XILINX_EDK/sw/XilinxProcessorIPLib/drivers/uartlite_v1_13_a/examples

 

You can use it in polling mode or with interrupts. I am using it in polling mode.

First you have to initialize the UART interface:

    XUartLite_Initialize(&UartLite, UARTLITE_DEVICE_ID);

     

Therfore you need a RecvBuffer of this type: Xuint8 RecvBuffer[16];

 

You can poll like this: while (XUartLite_Recv(&UartLite, RecvBuffer, 16) == 0); 

This method returns the length of the received buffer. But be careful, data are sended in ASCII.

 

Best regards, Robbi 

0 Kudos
8,731 Views
Registered: ‎09-05-2008

Re: how to read data from the serial port?

Hi tarzandavid,

if you skip the setvbuf() function in the example you will get what you want.

 

I have tested the stuff with Hyperterminal on WinXP.

 

BTW : if you want to receive a whole command line up to CR

you may try scanf(), but I never tested that.

But  : with scanf() you do not have the ability to send back the

typed characters to the user. Depends on what you want and on the

settings of your terminal.

 

-- Ralf

 

 

0 Kudos
Contributor
Contributor
8,672 Views
Registered: ‎06-13-2008

Re: how to read data from the serial port?

Hi robbi,

 

Thanks for your advice, yes I am working with EDK and using spartan3a dsp 1800, just set the developing environment up couple of hours ago :P

 

What I'm doing right now is using the provided example files and following the instruction of Spartan3ADSP_MB_EXAMPLE_10_1.pdf, and I just met one problem. I have done the following part by following the example tutorial:

 

1. Connect the JTAG cable between board and PC

2. Connect the serial cable( RS232cable) between PC and P2 connector of the board

3. Apply power to the board

4. Start the HyperTerminal, set the Baud Rate to 9600, Data bits to 8 bits, Parity to None, Stop bits to 1 bit, and Flow control to None

5. Use iMPACT to download the bitstream

7. Invoke XMD and connect to the MicroBlaze Processor.

8. Download the Application to be tested

 

and then I followed the step 9 by running the software application, according to the tutorial, output of the TestApp Memory application and Peripheral application should appear on hyperterminal, but actually it didn't happen to mine.

 

I had COM1, COM2,COM3,COM8 in my PC. When I use 1,2,3 there are no response when typed "RUN" in XMD, and when I chose COM8 a notice saying" Another Program is Using the Selected Telephony...", so what's the matter with this issue and how can I get result shown in hyperterminal? Many thanks!

 

 

 

0 Kudos
Explorer
Explorer
8,666 Views
Registered: ‎07-08-2008

Re: how to read data from the serial port?

Hi,

 

There is whole chapter (7) about UART in Spartan-3 devices in the book: "FPGA prototyping by VHDL Examples" by Pong P. Chu

 

I am attaching to console with the usage of screen tool.

 

 

Greetings, Mariusz

Message Edited by mariuszgrad on 03-07-2009 12:07 PM
--
Mariusz Grad.
0 Kudos
Contributor
Contributor
8,585 Views
Registered: ‎06-13-2008

Re: how to read data from the serial port?

Hi guys,

 

I have fixed my problem and am able to successfully display results on hyperterminal now. The problem happened to my RS232 cable... I changed a new one then the problem was solved. Thanks for all your help :-)

 

Cheers,

tarzan

0 Kudos