AN3260
Application note
Building a thermometer
using the STM8S-DISCOVERY
Application overview
This application demonstrates how to build a simple thermometer based on the STM8S-
DISCOVERY and the LM235 precision temperature sensor. The STM8S105C6T6
microcontroller reads the temperature values and transmits them through the UART
interface. The temperature values are then displayed on a terminal window (possibly based
on Windows HyperTerminal) of a PC connected to the UART through an RS232 cable.
Once the STM8S-DISCOVERY is powered up through an USB cable connected to the host
PC, an informative message is displayed on the terminal window and the user is prompted
to enter minimum and maximum temperature thresholds.
The current temperature is displayed on the terminal window every minute together with a
warning message when the temperature is out of range.
The minimum and maximum values of the temperature over one-hour period are recorded in
the MCU data EEPROM once per hour. They can be displayed any time by pressing a
pushbutton.
Even if it is built on an STM8S105C6T6, the STM8S-DISCOVERY can be used to evaluate
the main features of all STM8S microcontrollers.
Reference documents
I
I
STM8S-DISCOVERY evaluation board user manual (UM0817).
Developing and debugging your STM8S-DISCOVERY application code user manual
(UM0834).
LM235 precision temperature sensor datasheet
ST232C 5 V powered multi-channel RS-232 driver and receiver datasheet
I
I
December 2010
Doc ID 17836 Rev 1
1/24
www.st.com
Contents
AN3260
Contents
1
2
3
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Configuring the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1
3.2
3.3
3.4
Hardware required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Application schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Application principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Launching your application from the PC terminal . . . . . . . . . . . . . . . . . . . 10
4
Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.1
4.2
4.3
STM8S peripherals used by the application . . . . . . . . . . . . . . . . . . . . . . . 11
Exclusion of the Standard STM8S standard firmware library . . . . . . . . . 12
Application software flowcharts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3.1
4.3.2
4.3.3
4.3.4
Main loop flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Interrupt function flowcharts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
State machine flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Terminal communication functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Appendix A Configuring your terminal window. . . . . . . . . . . . . . . . . . . . . . . . . . 19
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2/24
Doc ID 17836 Rev 1
AN3260
List of tables
List of tables
Table 1.
Table 2.
Table 3.
Table 4.
List of passive components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
List of packaged components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Application typical behaviors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Doc ID 17836 Rev 1
3/24
List of figures
AN3260
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.
Application schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Application state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Terminal window at startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Main loop flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
PORTA_IRQhandler() function flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
TIM3_Init() function flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
State_Machine function flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Launching Windows HyperTerminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Selecting communication port. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Configuring connection properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Checking communication settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
ASCII Setup parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4/24
Doc ID 17836 Rev 1
AN3260
Prerequisites
1
Prerequisites
The material required to run the STM8S-DISCOVERY thermometer demonstration
application is the following:
G
A terminal window running on a PC: the terminal emulator software can be Windows
Hyperterminal (see
Appendix A),
TeraTerm Pro, or any terminal software.
An RS232 null-modem cable (transmit and receive line crosslinked)
USB type-A to mini-B cable.
G
G
2
Configuring the application
STM8S-DISCOVERY JP1 jumper must be set in 2/3 position to select a 5 V V
DD
supply
voltage.
3
3.1
Application description
Hardware required
This application uses the STM8S-DISCOVERY on-board LED (LD1) together with its
associated resistor (R1).
The external passive components required by the application are listed in
Table 1.
In addition, the application makes use of a 5 V powered ST232C RS232 driver/receiver. This
extra component is essential since the COM port of the PC operates from a nominal 12 V
power supply which is not compatible with the STM8S UART input/output operating at 5 V.
This component is available in an SO16 package which fits the STM8S-Discovery footprint.
Refer to the datasheet for more information on the ST232C. Refer to
Table 2
for the full list of
packaged devices.
Table 1.
List of passive components
Value
2.2 kΩ
100
Ω
100 nF
-
-
100 nF
100 nF
100 nF
Comments
Pull-up resistor
Current limitation resistors
Debounce filters
Standard pushbutton
Standard pushbutton
Charge-pump capacitors
Output capacitors
Decoupling capacitor
Component name
R2
R3, R4 (optional)
C6, C7
Button1
Button2
C2, C3
C1, C4
C5
Doc ID 17836 Rev 1
5/24