Project 5.1 UARTs

Communicate with the Blackboard using a PC's COM port



This Project introduces the concept of Universal Asynchronus Recieve/Transmit (UART) Devices. UART is a communication standard that is very widely used in a range of applications. For this lab, we will use UART to transfer data between between your computer and the blackboard. It can also be used to talk between embedded devices (not necessarily to a PC). Using a terminal on the PC-side, you can create text interfaces to your programs where you can send and receive data from the blackboard.


UART on blackboard

Most embedded controllers have at least one (but often many UART controllers). There are two UART controllers found in the Zynq system: Each allow the processor to receive and transmit data with connected devices. UART1 is connected to the FTDI controller on the blackboard, which converts the serial data to USB. This allows serial data to be read/written to/from your PC via the same USB connection that programs the Blackboard.


Terminal emulators are a class of programs that can connect to devices and display input received and send output from the user. Xilinx’s SDK has a built in terminal emulator that can connect to serial ports. Other terminals can be used as well (like screen on linux), but only configuration for the XSDK terminal is covered.


1. Configure the UART module and transmit characters to your computer.

Write a program that configures UART1 for a baud-rate of 115200, 8 data bits, no parity bits, and 1 stop bit. Then have the program continuously send a single character, with a long delay between each character sent (to ensure you don’t overflow the transmit buffer). You can send an ascii value held in a char or uint8_t.

You can use the following code to help start writing your program:

int i;
char val = 'a';

//configure uart here

for(;;)	//endless loop
	send_character( val);	//send character

	//delay for at least 60000 cycles
	//to make sure the TX buffer doesn't overflow	

Verify your program works by connecting a terminal to your computer’s corresponding serial port. Make sure your terminal is configured for 115200, 8 data bits, no parity, and a single stop bit. If everything is correct you should see a continuous stream of the given character.

2. Receive characters on the Blackboard

Write a program that waits to receive data from the UART and responds via UART when data arrives. Have the program wait for a specific number or letter. Respond with a multi-character message when it receives the character you defined.

For example: Your blackboard could reply “Hello!” every time it received an ‘h’ character.

3. Write a function that can transmit C-strings

Write a function that takes a C String as an argument and transmits the string through uart1. C-Strings are null terminated; The character ‘\0’ or ascii value 0 is found at the end of the string. Make sure you stop sending data if you see a null character in your string. You should also define a maximum string length for the case where a string that isn’t terminated properly is sent to the function.

Before writing a character to the transmit buffer, check the status flags for the buffer to make sure the buffer has room for additional characters. The ‘FIFO_FULL’ flag being clear should tell you that the there is room for at least 1 more character in the buffer. If you overflow the buffer, you will lose data.

4. Write a program that sends the state of the switches when requested

Have your program wait for a specific character to be received and then have it respond with the current value of the slide switches. Have the program format the value as a binary number. Since you read all of the switches at once in a single integer value, you will neet to convert the switch read value into a sequence of characters to send via the uart. (If you read the switches from the register as 9, send “1001” to the PC)

5. Receive numbers from the terminal and display on the LEDs

Have your program receive a single hexadecimal digit from the computer and display the value as binary on 4 LEDs. Since the character received will be in ascii format, you’ll need to convert it to an binary integer before writing to the LEDs.


1. Write a function that can send integer values via the uart

Write a function that takes an decimal integer as an argument and sends the number through the uart (send the characters representing the number, not the ascii value). You can also make a version that sends hex numbers. Converting integers to a string of hex characters might be easier. Why? How do computers represent integers?

2. Read XADC voltage and display the result on the terminal

Configure the GTC to intterrupt every 1/2 second (500ms). When the interrupt occurs read data from the XADC channel corresponding to the potentiometer on the blackboard. Convert the Data so it appears as a value between 0 and 1 volts, with 4 digits of precision; 0.000 to 1.000. To do this you will need to know how the data is represented in the XADC regsiters.

When you convert the XADC read value to volts you will end up with a floating point number. If you’ve written functions in challenge 1, you cannot just pass it a floating point number as they are represented via their own format. Instead, you can convert the floating point number to an integer before sending it to the PC. This of course results in a loss of precision. Make sure you put the decimal point in the proper place and include a unit!.

3. Use interrupts from the UART module

Configure UART1 to generate interrupts when it receives data.

Write a program that counts upwards every second and sends the count value to the PC. Have the count reset when it receives any input from the PC and have your program send an acknoledgement of some kind to the terminal. Use interrupts to accomplish this. Polling the receiver fifo will not count.