AN3259
Application note
RS232 communications with a terminal
using the STM8S-DISCOVERY
Application overview
This application note describes how to control the STM8S-DISCOVERY from a terminal
window running on a PC which is connected to the STM8S105C6T6 microcontroller UART
through an RS232 cable.
After adding the required components to the board and downloading the application
software, you will be able to use a terminal to manage STM8S GPIOs and TIM3 timer, and
to configure the beeper output.
Reference documents
●
●
●
STM8S-DISCOVERY evaluation board user manual (UM0817).
Developing and debugging your STM8S-DISCOVERY application code (UM0834).
ST232B-ST232C datasheet
All these documents are available at http://www.st.com.
December 2010
Doc ID 17835 Rev 1
1/25
www.st.com
Contents
AN3259
Contents
1
2
3
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Configuring the STM8S-DISCOVERY . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1
3.2
3.3
Hardware required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Application schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Application principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3.1
3.3.2
Running the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Communication sequence between the STM8S-DISCOVERY
and the terminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4
Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1
4.2
4.3
STM8S peripherals used by the application . . . . . . . . . . . . . . . . . . . . . . . . 9
Configuring STM8S standard firmware library . . . . . . . . . . . . . . . . . . . . . . 9
Application software flowcharts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.3.1
4.3.2
4.3.3
4.3.4
4.3.5
4.3.6
Application main routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
App_menu function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
GetInputString function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Get_key function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
SerialPutString and SerialPutChar functions . . . . . . . . . . . . . . . . . . . . . 16
GetIntegerInput function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Appendix A Standard ASCII character codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Appendix B Configuring your terminal window. . . . . . . . . . . . . . . . . . . . . . . . . . 20
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2/25
Doc ID 17835 Rev 1
AN3259
List of tables
List of tables
Table 1.
Table 2.
Table 3.
Table 4.
List of passive components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
List of packaged components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Standard ASCII character codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Doc ID 17835 Rev 1
3/25
List of figures
AN3259
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Figure 6.
Figure 7.
Figure 8.
Figure 9.
Figure 10.
Figure 11.
Figure 12.
Figure 13.
Figure 14.
Application schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Terminal window menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Main routine flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
App_menu flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
GetInputString flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Get_key function flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
SerialPutChar flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
SerialPutString flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
GetIntegerInput flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Launching Windows HyperTerminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Selecting communication port. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Configuring connection properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Checking communication settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
ASCII Setup parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4/25
Doc ID 17835 Rev 1
AN3259
Prerequisites
1
Prerequisites
The material required to run the STM8S-DISCOVERY terminal demonstration application is
the following:
●
●
A terminal window running on a PC: the terminal emulator software can be Windows
Hyperterminal (see
Appendix B),
TeraTerm Pro, or any terminal software.
An RS232 null-modem cable (transmit and receive line crosslinked).
2
Configuring the STM8S-DISCOVERY
Prior to running the application, the STM8S-DISCOVERY must be configured to enable the
beeper output. The beeper output is an STM8S105C6T6 alternate function. It is enabled by
setting the alternate function remap option bit AFR7 in OPT2 option byte to ‘1’.
For details on alternate function remapping and on option bytes, refer to user manual
“Developing and debugging your STM8S-DISCOVERY application code” (UM0834), and to
the STM8S105xx datasheet, respectively.
3
3.1
Application description
Hardware required
This application uses STM8S-DISCOVERY on-board LED (LD1) together with its associated
resistor (R1).
The external passive components required by the application are listed inTable
1.
The application also makes use of a 5 V powered ST232B RS232 driver/receiver (see
Table 2).
This extra component is essential since the COM port of the PC operates from a
nominal 12 V power supply. This is not compatible with the STM8S UART input/outputs
operating at 5 V. This component is available in an SO16 package which fits the STM8S-
DISCOVERY footprint. For more information on the ST232B refer to the ST232B datasheet.
Table 1.
List of passive components
Component description
B1 buzzer
C1,C2,C3,C4,C5 capacitors
DB9 connector
Value
-
100 nF
-
Doc ID 17835 Rev 1
5/25