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: 
Highlighted
Visitor alialp
Visitor
12,245 Views
Registered: ‎12-19-2010

UART menu example.

Hi everyone,

 

I am a new xilinx fpga user. Actually I am also new to C language too. I have an XUPV5 board.

 

My question is:

 

How can I simply prepare an UART menu which will be used to select some specific tasks for my microblaze controller.

 

For example,  when it is pressed "1" the controller will turn on the "LED 0" on the board and wait for another number to be selected by the user. (Of course when the terminal in SDK is connected.)

 

If you have an example project or code please send. I already looked to the examples  uart 2.00a in the "drivers" directory of the xilinx installation but did not helped much. (new to the C...)

 

 

Thanks in advance...

0 Kudos
5 Replies
Mentor awillen
Mentor
12,232 Views
Registered: ‎11-29-2007

Re: UART menu example.

Let me summarize:

  • you don't know C
  • you're new to FPGAs
  • you want to design a SoC with FPGAs and program an embedded processor in C
  • you looked at a few lines of example C code but that didn't help you

Well, DUH! Do you think you can learn how to land an airplane by watching a pilot in a movie do it?

 

  1. Learn C
  2. Write C for your desktop processor!
  3. Learn about FPGAs
  4. Write code for an FPGA!
  5. Only then you should start thinking about your project.

 

 

Adrian



Please google your question before asking it.
If someone answers your question, mark the post with "Accept as solution". If you see a particularly good and informative post, consider giving it Kudos (the star on the left).
0 Kudos
Visitor alialp
Visitor
12,226 Views
Registered: ‎12-19-2010

Re: UART menu example.

Well, in fact I behaved a little bit modestly, I do have my own cpu desings, I used the LCD on my development kit, lighted up the LEDs, dip switches, push buttons already. My next target is to command the soft cpu over rs232. I even used matlab - simulink xilinx toolbox to develop some dc motor control stuff and targeted my dev board it worked fine at least for a "beginner".

 

So, I am ambitious to learn more. I welcome all the answers from the ones who can share their knowledge but not the arrogant advises.

 

Regards...

0 Kudos
Mentor awillen
Mentor
12,224 Views
Registered: ‎11-29-2007

Re: UART menu example.

I'm sorry if my post sounded arrogant. The thing is, you wouldn't believe how many people come here without a clue about FPGAs and ask how to do complex stuff without ever trying the simple stuff. And modesty is a nice character trait, but if you sell yourself under value, then you won't get the answers that fit your level of knowledge.

 

However, the essence of my reply still stands: you can't learn C from code examples, and you really should learn C if you want to work with embedded CPUs. There are tons of textbooks and/or online resources that teach you C, and it's really worth the effort.

 

One more piece of advice: asking for sample code kind of has a stigma around here, because there are just so many people that shy away from digging into the manuals themselves and instead demand that others do their work.

 

 

Adrian



Please google your question before asking it.
If someone answers your question, mark the post with "Accept as solution". If you see a particularly good and informative post, consider giving it Kudos (the star on the left).
0 Kudos
Visitor alialp
Visitor
12,163 Views
Registered: ‎12-19-2010

Re: UART menu example.

I solved my own problem and I wrote below code. It is functioning on my XUPV5 board. The thing is when I write "XPAR_UARTLITE_0_BASEADDR" in "XUartLite_RecvByte" function my program did not work, I really wonder why? When I wrote "XPAR_RS232_UART_1_BASEADDR" instead of uart base address program functions flawlessly.

 

Is there any way to see which device is using which parameter correctly in EDK or SDK?

 

If anyone would like to see how rs232 works both in RX and TX direction simply, below code would be a good staring point I suppose....

 

/************************************************************************************************************/

#include <stdio.h>
#include "platform.h"
#include "xparameters.h"
#include "xbasic_types.h"
#include "xgpio.h"
#include "xstatus.h"
#include "xtmrctr.h"
#include "xuartlite.h"
#include "xuartlite_l.h"
#include "xil_exception.h"

/************************** Constant Definitions *******************************/

int LED_number[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

/************************** Variable Definitions *******************************/

XUartLite UartLite; /* Instance of the UartLite device */
XGpio Gpio8bitsLED; /* Instance of the Gpio8bitsLED */
XTmrCtr TmrCtr; /* Instance of the Timer/Counter */

/************************** Function Prototypes ********************************/

void delay_us(Xuint32 time);


/*****************************************************************************/
/* Main Function
/******************************************************************************/


int main()
{

int status;
// Initialize UART
status = XUartLite_Initialize(&UartLite, XPAR_UARTLITE_0_DEVICE_ID);

if (status!=XST_SUCCESS){
xil_printf("UART failed to initialize. \r\n");
return XST_FAILURE;
}
// Perform a self-test to ensure that the hardware was built correctly.

status = XUartLite_SelfTest(&UartLite);
if (status != XST_SUCCESS) {
xil_printf("UART failed to self test. \r\n");
return XST_FAILURE;
}
// Initialize timer.

status = XTmrCtr_Initialize(&TmrCtr, XPAR_XPS_TIMER_0_DEVICE_ID);
if (status != XST_SUCCESS){
xil_printf("Timer failed to initialize. \r\n");
return XST_FAILURE;
}
// Set up timer options.
XTmrCtr_SetOptions(&TmrCtr, 1, XTC_DOWN_COUNT_OPTION);

// Initialize GPIO 8 Bit LEDs.

status = XGpio_Initialize(&Gpio8bitsLED, XPAR_LEDS_8BIT_DEVICE_ID);
if (status!=XST_SUCCESS){
xil_printf("GPIO failed to initialize. \r\n");
return XST_FAILURE;
}
// Set all the 8 bits LEDs as outputs.
XGpio_SetDataDirection(&Gpio8bitsLED, 1, 0x00);

// Display the menu.

xil_printf("%c[2J",27);
print("\n\r - Please select your wish - \n\r");
print("1 - Turn on and off continuously LED 2 \n\r");
print("2 - Turn on and off continuously LED 4 \n\r");
print("3 - Turn on and off continuously LED 6 \n\r");
print("4 - Turn on LEDs one by one from 0 to 7 once \n\r");
print("5 - Turn on LEDs one by one from 7 to 0 once \n\r");

// Endless loop

u8 RS232Recv;
u8 n;


while(1){
RS232Recv = XUartLite_RecvByte(XPAR_RS232_UART_1_BASEADDR);

switch (RS232Recv) {
case 0x31:
xil_printf("You have chosen : %x . \n\r", RS232Recv-0x30);
XGpio_DiscreteWrite(&Gpio8bitsLED,1,0x00);
XGpio_DiscreteWrite(&Gpio8bitsLED,1,0x04);

break;
case 0x32:
xil_printf("You have chosen : %x . \n\r", RS232Recv-0x30);
XGpio_DiscreteWrite(&Gpio8bitsLED,1,0x00);
XGpio_DiscreteWrite(&Gpio8bitsLED,1,0x10);

break;

case 0x33:
xil_printf("You have chosen : %x . \n\r", RS232Recv-0x30);
XGpio_DiscreteWrite(&Gpio8bitsLED,1,0x00);
XGpio_DiscreteWrite(&Gpio8bitsLED,1,0x40);

break;

case 0x34:
xil_printf("You have chosen : %x . \n\r", RS232Recv-0x30);
XGpio_DiscreteWrite(&Gpio8bitsLED,1,0x00);
for (n = 0; n < 8; ++n) {
XGpio_DiscreteWrite(&Gpio8bitsLED, 1, LED_number[n]);
delay_us(100);
}
break;

case 0x35:
xil_printf("You have chosen : %x . \n\r", RS232Recv-0x30);
XGpio_DiscreteWrite(&Gpio8bitsLED,1,0x00);
for (n = 8; n > 0; --n) {
XGpio_DiscreteWrite(&Gpio8bitsLED, 1, LED_number[n-1]);
delay_us(100);
}
break;


default:
xil_printf("Out of range! \n\r", RS232Recv-0x30);
XGpio_DiscreteWrite(&Gpio8bitsLED,1,0x00);
break;
}
}

return 0;
}

// Functions Declarations

/*****************************************************************************/
/* Time Delay Function:
/*****************************************************************************/
void delay_us(Xuint32 time)
{
XTmrCtr_SetResetValue(&TmrCtr, 1, time * 125000);
XTmrCtr_Start(&TmrCtr, 1);
while(!(XTmrCtr_IsExpired(&TmrCtr, 1))){}
XTmrCtr_Stop(&TmrCtr, 1);
}

0 Kudos
Visitor mostafa01
Visitor
31 Views
Registered: ‎12-06-2018

Re: UART menu example.

hi all

I have a problem. I have a zybo board zynq7000, I want use UART PS, what Pins use zybo for send and receive data? i need a code for send and receive a message. please help me. Thanks.

Tags (1)
0 Kudos