HOME
Lab components |
CSE
477: Digital Systems Design
(Spring 2002) |
Lab
4: Using Serial Communications
Objectives: In this lab will you will learn the following:
Part 1 -- Setting up the serial interface Refer to the 8051 documentation to see how to set the baud rate of the serial port using timer 1. We will be using a baud rate of 9600 - figure out how the timer should be configured to implement this baud rate. In addition, you will need to connect to the serial connector on the XSV board to the RXD/TXD pins of the the embedded 8051 microcontroller. This connection goes through the X95108 CPLD, which is also used to connect the parallel port to the FPGA. We will have to use a different SVF file to program the CPLD so that this connection is made - the dnldpar.svf program only connects the parallel port. (We will have to write this!) You can test your connection with the Serial.c in the ...\lab4 folder. (You will have to set the timer for 9600 baud rate for this to work.) There are five major components to get serial working:
We will use the following FPGA pins for the TxD and Rxd signals. There will be a new UCF entries for these signals.
Part 2 -- Simple getchar/putchar In this part, you will implement simple getchar() and putchar() routines. getchar() returns the character that has been received by the serial port. If there is a character waiting, it just returns it. If there is no character, then getchar() returns NULL. The user can thus call getchar() repeatedly if necessary until a character is returned, but getchar() doesn't hang if no character ever comes. putchar(c) sends a character c to the serial port. If the port is not ready, i.e. it is in the process of sending a character, then putchar() returns NULL. Otherwise it sends the character and returns a 1. Test these routines by writing a program that reads characters from the serial interface, and writes them back, transforming lower case letters to upper case, and vice versa. In case of non-alphabetic character echo the same character back) (The character
codes for the alphabets : 'A' = 65, 'Z'=90 , 'a'=97 and 'z'=122; )
Part 3 -- Serial Interface Interrupt Routine The getchar and putchar routines in Part 2 do not have any buffering and thus do not allow a lot of concurrent processing. In this part, you will write one interrupt routine, that sends a character and that receives a character depending on when the interrupt is triggered. The interrupt call that sends a character is interrupted when the serial port send buffer is free. If there is a character waiting to be sent (use a global variable for this), then the routine sends the character and clears the global variable. If there is no character waiting to be sent, then it does nothing. The interrupt routine is also called when a character is received. This character should be stored in a global variable. If the global variable already has a character, then an error condition should be flagged. You will now use the interrupt routine that you just wrote to implement getchar() and putchar(). These routines no longer look at the serial port registers directly, but rather at the global variables used by the interrupt routines. However, if putchar() is called and the global variable is empty, then putchar() must send that character explicitly since the interrupt routine will not be called again. Test these routines
by writing a program that reads characters from the serial interface, and
writes them back, but transforming lower case letters to upper case, and
vice versa.
Part 4 -- Buffered readchar/putchar In this part, you will increase the buffering from a single global variable to a buffer of size 32. This buffer should be a queue. When writing, the user adds characters into one end and the interrupt routine takes characters out of the other end. When reading, the interrupt routine puts characters at one end and the user reads from the other. Don't forget the error flags for cases where data gets lost. To test the buffer you should implement a software flow-control along with the simple echo application. From hyperterminal you send an Xoff and all data afterward would end up in the buffer. After sending an Xon, all the buffered data should be echoed back. In practical terms
Xoff and Xon are reserved characters that you send; for example, Xon is
say the '$' and Xoff is say '#'. These characters act as commands for your
program.
What to Turnin Demonstrate your program to the TA. Hand in a printout of the C programs you wrote. You should also be able to answer detailed questions about every part. |
|
BACK
TO TOP
Last Updated:
|
Contact the instructor at:cse477-webmaster@cs.washington.edu
|