18-348 Lab #10
Fall 2007
Pre-lab due: Friday, 10/05/2007
Lab demos: week of 10/08/2007
Lab handins due: Friday, 10/12/07
Links to all files referenced in the lab and prelab can be found in the
Files section at the end of this document.
We strongly recommend you complete this lab (except for
the actual in-lab demo) by 6 PM on Monday -- i.e., before the official lab demo
times and before the in-class test. Completing this lab will help you
understand serial communications, and you can be sure that topic will appear on
the test!
Change -- 8 Oct 2007: We have released a new version of
the serialcomm zip file. The demo.txt file within the zip file has been changed
to accommodate a change in the way lab groups are numbered this year. It is
important that you use this new version for your lab demo. Link:
SerialComm
Pre-Lab:
Goal:
- To learn the basics of serial communication.
Discussion:
Refer to Chapter 13 of the
MCU9S12
Datasheet for details of the Serial Communication Interface. Refer to
the lecture notes for details on serial communication.
Procedure:
Part 1:
Study Sections 13.3 and 13.4 of the
MCU9S12
Datasheet.
For each table below, fill in the values from the corresponding list (Hint
there are the same number of values as locations in the table. Each value
should be used only once).
Table 1:
Register
|
Value for this bit = 0
|
Value for this bit = 1
|
SCICR1 bit 7
|
|
|
SCICR1 bit 6
|
|
|
SCICR1 bit 5
|
|
|
SCICR1 bit 4
|
|
|
SCICR1 bit 3
|
|
|
SCICR1 bit 2
|
|
|
SCICR1 bit 1
|
|
|
SCICR1 bit 0
|
|
|
Values for table 1:
(copy each phrase below into exactly one box above)
- 8 bit data format
- 9 bit data format
- Count idle bits after start bit
- Count idle bits after stop bit
- Disable loop operation (Normal operation)
- Disable SCI in wait mode
- Enable loop operation
- Enable SCI in wait mode
- Even parity
- Odd Parity
- Parity disabled
- Parity enabled
- Receiver connected externally to transmitter
- Receiver internally connected to transmitter output
- Wake on address mark
- Wake on idle line
Table 2:
Register
|
Value for this bit = 0
|
Value for this bit = 1
|
SCICR2 bit 7
|
|
|
SCICR2 bit 6
|
|
|
SCICR2 bit 5
|
|
|
SCICR2 bit 4
|
|
|
SCICR2 bit 3
|
|
|
SCICR2 bit 2
|
|
|
SCICR2 bit 1
|
|
|
SCICR2 bit 0
|
|
|
Values for Table 2:
- IDLE interrupt disabled
- IDLE interrupt enabled
- No break characters
- No receiver wakeup (normal operation)
- RDRF interrupt disabled
- RDRF interrupt enabled
- Receiver disabled
- Receiver enabled
- Receiver wakeup and block receiver interrupts
- TC interrupt disabled
- TC interrupt enabled
- TDRE interrupt disabled
- TDRE interrupt enabled
- Transmit break characters
- Transmitter disabled
- Transmitter enabled
Table 3:
Register
|
Value = 0
|
Value = 1
|
SCISR1 bit 7
|
|
|
SCISR1 bit 6
|
|
|
SCISR1 bit 5
|
|
|
SCISR1 bit 4
|
|
|
SCISR1 bit 3
|
|
|
SCISR1 bit 2
|
|
|
SCISR1 bit 1
|
|
|
SCISR1 bit 0
|
|
|
Values for Table 3:
- Data not available in SCI data register
- Framing error detected
- No byte in transmit shift register
- No framing error detected
- No noise detected
- No overrun
- No parity error detected
- Noise detected
- Overrun has occurred
- Parity error detected
- Received data in SCI data register
- Receiver idle
- Receiver not idle
- Transmission complete
- Transmission in progress
- Transmit register empty
Part 2:
Review section 13.4.2. of the
MCU9S12
Datasheet on baud rate generation. Note that the values in table
13-10 are incorrect for our purposes because they assume a module clock rate of
25 MHz, and the module clock is 8 MHz.
Using the formula given, fill in the SCIBR[12:0] values required for each
of the listed baud rates below. Compute the actual baud rate (using the
formula and the integer value you chose for SCIBR. Compute the % error
using the formula:
100 * (Actual Baud Rate - Nominal Baud Rate) / Nominal Baud Rate
Table 4:
Nominal Baud Rate (bits / sec)
|
SCIBR value (decimal representation)
|
Actual Baud Rate (bits / sec)
|
Error (%)
|
300
|
|
|
|
600
|
|
|
|
1200
|
|
|
|
2400
|
|
|
|
4800
|
|
|
|
9600
|
|
|
|
14400
|
|
|
|
19200
|
|
|
|
38400
|
|
|
|
56000
|
|
|
|
115200
|
|
|
|
Questions:
- (10 points) Complete Table 1 from part 1.
- (10 points) Complete Table 2 from part 1.
- (10 points) Complete Table 3 from part 1.
- (20 points) Complete Table 4 from part 2.
Hand-in Checklist: (50 pts)
All non-code submissions shall be in a single PDF document.
- (50 pts) Answers the the questions above.
Refer to the LAB FAQ for more information on lab
handin procedures and file type requirements. You MUST follow these
procedures or we will not accept your submissions.
Lab 10
For this lab, you will establish serial communication with a PC. We
have written a simple program which reads a query string from the serial port,
looks for the query in a string file, and returns a response string over the
serial port. The program uses the following protocol:
- Each character of the message (excluding the null terminator) is
transmitted.
- Then a Cyclic Redundancy Code (CRC) of the message is transmitted.
- Then a NULL byte is sent to signal the end of transmission.
Your program must be able to follow this protocol when it sends or receives
data from the PC.
In addition to the PC software, you will use an LCD library to display
output on the onboard LCD. The readme that accompanies
lcd_lib-1_2.zip contains information
about how to use it.
Procedure:
Part 1: PC serial program.
- Determine the address of the serial port (in Windows XP) by doing the
following:
- Open the control panel.
- Open "System Properties"
- Select the Hardware tab.
- Click the Device Manager button
- Expand the Ports item in the tree.
- You should see a list of com ports, e.g. "Communications Device
(COM1)." If you are using a USB to serial adapter, you may see the
brand-name of the adapter.
- Download the SerialComm program. The
zip file contains a sample string table file, the executable, and several
supporting DLLs. The DLLs must be in the same directory as the
executable.. You can obtain the command line syntax of the program by
running it with no arguments.
Part 2: Hardware and Software
- Wire the board according to the comments in the skeleton file. Be
sure to check the jumper settings in the lcd_lib readme file.
- Download the lab 10 skeleton file and
lcd_lib.zip.
- Start a new C project. Rename the skeleton to lab_10_gXX.c and
replace the main file with it. Add the lcd_lib.h and lcd_lib.c files.
- Implement the serial communications by filling in the TODO sections of the
program. The program must meet the following requirements:
- After reset, the program shall display the current groupString, the
computed CRC, and the current baud rate index.
- When PB1 is pressed, the program shall send a 2-byte string containing the
group name over the serial connection (according to the communications protocol
described above)
- After transmitting the query string, the program shall receive a response
from the PC, decode the response, and check the message integrity using the
CRC.
- The program shall display the response and the correct CRC or an error if
the CRC check fails.
- The program may terminate after 1 transmission cycle (i.e. need to be reset
before another query/response).
- October 9 UPDATE: Switches SW1_1 to SW1_4 should be used to
set serial communication at the different Baud rates
Part 3: Run the system
- Test your program by connecting the DB9 port on the CSM12C32 module with
the serial port on the PC. Run the SerialComm program using the demo.txt
and initiate a communication.
- Write out the byte-by-byte values of the query and response
communications. The default groupString has been done below as an
example.
- Query: 0x45, 0x58, 0xA6, 0x00
- Response: 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0xc8, 0x00
Bonus -- Part 4: Communication Speeds
This portion of the lab is optional. Try the communication at each
baud rate, starting at 300 baud and working up. Record the fastest baud
rate that you can successfully communicate at and the slowest baud rate where
communication fails (usually with a frame error on the PC). Note that you
will have to demo these two speeds to the TA, so if you are doing the part of
the lab on a computer other than one in the lab, you must be able to bring the
computer with you to lab for the demo. Note that you MUST successfully
demo the values recorded in your prelab in order to receive any bonus credit
for the writeup.
Demo Checklist: (40 + 8 points)
For the demo, the TA may ask you to use a different string file. The
query string will always be your lab number (e.g. "1A" in ASCII
characters). Response strings will never be longer than 8 characters.
- (20 points) Demo successful communication between the PC and the
computer at 2400 baud.
- (20 points) Demo successful communication between the PC and the
computer at 9600 baud.
- (8 points) (optional bonus) Demo your findings for the bonus (fastest
baud rate with successful communication and the slowest baud rate where
communication fails).
Hand-in Checklist: (50 + 10 pts)
- (5 points) List any problems you encountered in the lab and pre-lab, and
suggestions for future improvement of this lab. If none, then state so to get
these points.
- (20 pts) Submit your completed C implementation (as lab_10_gXX.c).
Your code must conform to the course style sheet to receive full credit.
- (25 points) Record the byte-by-byte query and response (using your own
group name) from part 3.
- Bonus: (10 pts) (optional) List the fastest baud rate with successful
communication and the slowest baud rate where communication fails from part 4.
Refer to the LAB FAQ for more information on lab
handin procedures and file type requirements. You MUST follow these
procedures or we will not accept your submissions.
Hints and Suggestions:
- We very strongly suggest you use the available tests to ensure your
hardware is working properly before starting the lab.
- In previous years many students have told us their boards were
"broken." But, in almost every case the problem was really
mis-configured jumpers. Please double-check your jumper settings (all
your jumper settings), using the baseline jumper checklist before concluding
your hardware is broken!
- USB to serial conversion devices are notoriously bad -- all of them. They
mostly work, but we've never met one we really trusted. So, use caution and if
in doubt use a lab computer with a REAL Serial Port.
- There are reports of lab computers having problems if both the USB cable
and a serial port device are plugged in at the same time. If you have problems
downloading firmware try unplugging the serial cable (leaving the USB cable
attached) when you download.
FILES for this lab:
Relevant reading:
Also, see the course materials
repository page.