LAB #8: Serial Communication

Embedded Systems (Microcontrollers) Lab
LAB #8: Serial Communication
<Student 1 Name>
<Student 2 Name>
<Student 1 ID>
<Student 2 ID>
Start Date: MM DD, YYYY
Due date: MM DD, YYYY
I. Learning Objectives
Understand how the STM32F3 microcontroller serial communication module works. Develop applications that
use this peripheral in C language.
II. Introduction
There are two types of serial communication: synchronous and asynchronous.
In a synchronous communication there exists a clock line and one or more data lines. A device called master is
the one that controls the clock line. The slaves also use the clock line, but have no control of it.
Figure 1. Synchronous communication waveforms
In an asynchronous communication, there is no clock line. Still, two data lines are used: transmit (TX) and
receive (RX).
Figure 2. Asynchronous communication waveforms
LAB #8 – Serial Communication
1/8
Embedded Systems (Microcontrollers) Lab
Table 1. Communication protocols comparison
RS232 standard is a type of asynchronous communication. Its voltage levels switch between +25V+3V for a
logic ‘0’ and -25V-3V for a logic ‘1’ (typically +12V for a logic ‘0’ and -12V for a logic ‘1’).
Figure 3. Serial RS232 and TTL Voltage Levels
LAB #8 – Serial Communication
2/8
Embedded Systems (Microcontrollers) Lab
A microcontroller can’t handle those voltage levels, so a level translator must be used, like the MAX3232. This
chip translates from TTL/CMOS voltage levels to those required by RS232.
Figure 4. MAX3232 Schematic
The connector used in the RS232 side is called DB9 and has the pinout shown in Figure 5.
Figure 5. DB9 connector pinout
The RS232 protocol is described in figure 6. Basically it works the following way:
1.
2.
3.
4.
5.
A start bit is sent in order to indicate the beginning of bits transmission.
The data is sent.
A parity bit (optional) is sent for CRC purposes.
A stop bit is sent.
Line stays in idle state before next start bit.
Figure 6. RS232 protocol
LAB #8 – Serial Communication
3/8
Embedded Systems (Microcontrollers) Lab
Another parameter for UART configuration is the baud rate, which is a measure of how many bits are
transfered per second. Both devices must have the same baud rate configured in order for communication to
be established.
Most PCs today have no serial ports available. Because of that, a USB-Serial cable must be used in order for a
PC to communicate serially using the RS232 protocol.
Figure 8. USB-Serial Cable
Besides the last problem, Windows 7 has no HyperTerminal console, so a substitute is required.
Figure 9. Shows a typical serial configuration on the PC side.
Figure 9. Serial configuration in PuTTY
LAB #8 – Serial Communication
4/8
Embedded Systems (Microcontrollers) Lab
IV. LAB
1. Get and install the following prerequisites:
a. LabVIEW 2012.
b. USB-Serial Cable driver.
c. PuTTY Terminal program.
2.
3.
4.
5.
Connect the USB-Serial Cable.
Go to Start Button -> Search window. Type devmgmt.msc
Check which COM matches to the connected USB Serial Cable.
Wire the circuit in Figure 10. WARNING: Make sure the connections match at the DB9 connector. Aid
yourself with Figure 5.
Figure 10. Circuit Schematic for LAB8
6. Open the LAB8.vi file.
7. Open the Keil-MDK project. Compile the project and upload it to the STM32F3DISCOVERY board. Reset
the board.
8. Open PuTTY client program. Go to Serial category and select the options in Figure 9 (place the COM
port of step 4). Then go to Session category, select Serial option and then click on the Open button. A
terminal should open showing the values sent from the microcontroller.
9. Close PuTTY and then run the LAB8.vi file.
10. Read the contents of Table 2.
LAB #8 – Serial Communication
5/8
Embedded Systems (Microcontrollers) Lab
Table 2. Explanation of .vi file
Element
VISA Configure Serial Port
Explanation
Requires the specification of (counter-clockwise):
1.
2.
3.
4.
Termination character enabled? -> Yes. By default, the termination
character is \n
Number of milliseconds to wait before error -> Waits 1000 ms.
COM Port ID
Baud Rate -> 115200
Wait
Spares 50ms in time to enable serial configuration. Requires specification of
number of ms.
VISA Serial Read
Requires the specification of characters to expect. Since a termination character
is enabled, this is a dummy value.
Reads when a data is present on the buffer and until the termination character.
Outputs the array of characters (string) received before termination character.
Hexadecimal String to Number
Receives an array of characters (string) in hexadecimal representation. Outputs
the number in uint32_t format. Then goes through a cast to double precision
format.
Location: Programming -> String -> String/Number Conversion -> Hexadecimal
String to Number
Division, Multiplication and
Waveform chart
Receives number in double precision format, then divides the value by the
recognized highest input value and then multiplies the number for the highest
recognized output value. The data is then displayed in a chart.
NOTE: In order to adjust the scale of the chart, just left-click on the maximum and minimum values on the axis
that requires modification. Then write the required values.
LAB #8 – Serial Communication
6/8
Embedded Systems (Microcontrollers) Lab
11. Make the following:
a. Modify the whole system to receive decimal numbers instead of hexadecimal numbers.
b. Modify the whole system baud-rate from 115200 to 9600.
c. Make the microcontroller generate and send an 8-bit instead of 12-bit data sine wave. Also
adjust the .vi to display that info from 0 to 5.
d. Instead of a sine wave to be displayed in the .vi, make the microcontroller display a sawtooth
wave.
12. Show your results and document your modifications, this last requisite will be your report.
V. Suggestions and Feedback
Time for completing prelab: ________________________________________________
Time for completing lab: ________________________________________________
Please explain difficulties you had and suggestions for improving this laboratory. Be specific, e.g. refer to
paragraphs or figures in the write-up. Explain what experiments should be added, modified (how?), or
dropped. Why? Please be critical but constructive.
Note: This section is not optional.
Final note: Your report must include a detailed explanation of the solutions you have found to the assignments,
in particular the programs. All the questions must be answered.
Important note about academic misconduct:
All work is to be the original work of the individual, or in the case of lab experiments, the two lab group members. Depending on the severity, individuals
performing plagiarism, cheating, and/or any other violation of the Student Code of Conduct may result in a zero for the assignment, may receive a grade
of zero for the class, and may be referred to the ITESM CEM Ethics Committee for disciplinary action.
LAB #8 – Serial Communication
7/8
Embedded Systems (Microcontrollers) Lab
APPENDIX: Instructions for VMWare Player Setup
1. Download and install the program in the following link:
https://download3.vmware.com/software/player/file/VMware-player-6.0.11379776.exe?HashKey=8befaf0850e8d68c3d7e0f3e47837ab2&ext=.exe&params=%7B%22sourcefilesize%22%
3A%2294M%22%2C%22dlgcode%22%3A%22PLAYER601%22%2C%22languagecode%22%3A%22en%22%2C%22source%22%3A%22DOWNLOADS%22%2C%22downl
oadtype%22%3A%22manual%22%2C%22eula%22%3A%22N%22%2C%22downloaduuid%22%3A%22a87c23a91c22-42a8-a63038901dce0bfb%22%2C%22purchased%22%3A%22N%22%2C%22dlgtype%22%3A%22Product+Binaries%22%2C
%22productversion%22%3A%226.0.1%22%2C%22productfamily%22%3A%22VMware+Player%22%7D&AuthKe
y=1383931757_306b617e5f7c59eb57829f36b0ff6d46&ext=.exe
2. Go to Start Menu and search for VMWare Player. Right-click on it and then go to Run as Administrator.
3. Select Open a Virtual Machine and then browse to the location of the virtual machine. Open the Microsoft
Windows XP Professional + SP3.vmx file.
4. Click on the full-screen button in the top of the tools menu.
LAB #8 – Serial Communication
8/8