AN5181. Building a thermometer using the STM8 Nucleo-64 boards. Application note. Introduction

Similar documents
AN5179. RS232 communications with a terminal using the STM8 Nucleo-64 boards. Application note. Introduction

Using the GPIOs and interrupt controller to drive LEDs on STM8 Nucleo-64 boards

AN3265 Application note

AN3996 Application Note

AN3279 Application Note

AN5123 Application note

AN4515 Application note

AN4311 Application note

This manual provides information for the final user application developer on how to use SPC57S-Discovery microcontroller evaluation board.

P-NUCLEO-IKA02A1. STM32 Nucleo pack: electrochemical toxic gas sensor expansion board with CO sensor. Description. Features

STM32SnippetsL0. STM32L0xx Snippets firmware package. Features. Description

UM0792 User manual. Demonstration firmware for the DMX-512 communication protocol transmitter based on the STM32F103Zx.

EVALKIT-VL6180X. VL6180X plug-in and STM32 F401RE Nucleo board explorer kit. Description. Features

Getting started with X-NUCLEO-53L1A1 long distance ranging ToF sensor expansion board based on VL53L1X for STM32 Nucleo

P-NUCLEO-6180X2. Proximity, gesture, ambient light sensor expansion board based on VL6180X for STM32L053R8. Description. Features

STSW-BLUENRG1-DK. BlueNRG-1, BlueNRG-2 DK SW package

AN4045 Application note

P-NUCLEO-USB001. STM32 Nucleo pack for USB Type-C and Power Delivery. Features. Description

AN3281 Application note

Getting started with the digital MEMS microphone expansion board based on MP34DT01-M for STM32 Nucleo

X-NUCLEO-53L0A1 ranging and gesture detection sensor expansion board based on VL53L0X for STM32 Nucleo

Getting started with the STM32 Nucleo pack for USB Type-C and Power Delivery with the Nucleo-F072RB board and the STUSB1602

UM2092 User manual. Basic metrology firmware for the STM32F103RD and the STPM32 devices. Introduction

Getting started with MotionPM real-time pedometer library in X-CUBE-MEMS1 expansion for STM32Cube

NUCLEO-L496ZG. STM32 Nucleo-144 board. Features. Description

UM2350. Getting started with MotionPW real-time pedometer for wrist library in X-CUBE-MEMS1 expansion for STM32Cube. User manual.

UM2276. Getting started with MotionSD standing vs sitting desk detection library in X-CUBE-MEMS1 expansion for STM32Cube. User manual.

AN2667 Application note

P-NUCLEO-USB001. STM32 Nucleo pack for USB Type-C and Power Delivery Data brief. Features. Description

P-NUCLEO-53L1A1. VL53L1X nucleo pack with X-NUCLEO-53L1A1 expansion board and STM32F401RE nucleo board. Description. Features

USB Type-C and Power Delivery Nucleo pack with NUCLEO-F072RB expansion board based on the STUSB1602

Getting started with MotionPM real-time pedometer library in X CUBE-MEMS1 expansion for STM32Cube

UM2194. Getting started with MotionAW activity recognition for wrist library in X-CUBE-MEMS1 expansion for STM32Cube. User manual.

AN2202 Application note

Getting started with the P-NUCLEO-IKA02A1 STM32 Nucleo pack for electrochemical toxic gas sensor expansion board with CO sensor

UM2255 User manual. SPC58NG-DISP user manual. Introduction

Running a simple 6LowPAN network consisting of one receiver node and one or more sensor nodes in a Sub-1GHz RF band

Motor control power board based on the SLLIMM-nano 2 nd series

UM2051 User manual. Getting started with the STM32 Nucleo pack for USB Type-C and Power Delivery. Introduction

P-NUCLEO-53L0A1. VL53L0X Nucleo pack with ranging, gesture detection sensor expansion board and STM32F401RE. Description. Features

USB Type-C and Power Delivery Nucleo pack with NUCLEO-F072RB expansion board based on STUSB1602. Description

Bluetooth low energy profiles for the X-CUBE-BLE1 expansion for STM32Cube. Description

Description. January 2019 DB2381 Rev 3 1/5

AN4696 Application note

EMIF06-HSD04F3. 6-line low capacitance IPAD for micro-sd card with EMI filtering and ESD protection. Features. Application.

Getting started with the X-CUBE-IKA02A1 multifunctional software expansion for STM32Cube

ST25DV-DISCOVERY. Discovery kit for the ST25DV04K dynamic NFC/RFID tag. Features

UM2461 User manual. SPC584B-DIS Discovery Board. Introduction

AN5224. STM32 DMAMUX: the DMA request router. Application note. Introduction

UM1978 User manual. Multi-sensor RF platform sensor board. Introduction

UM0401 User manual. User manual for eight bit port expander STMPE801 demonstration board. Introduction

External memory code execution on STM32F7x0 Value line and STM32H750 Value line MCUs

UM1844 User manual. EVAL-L9958 Graphical user interface (GUI) Introduction

UM2495. High performance HF reader / NFC initiator IC software expansion for NUCLEO-8S208RB. User manual. Introduction

DT0095 Design tip. Datalogging the SensorTile through a PC. Purpose and benefits. Description

Sub-1 GHz RF expansion board based on the SPSGRF-868 module for STM32 Nucleo. Description

UM2167 User manual. OrCAD PSpice model usage instructions

UM1000 User manual. 1 Introduction. STM8L1528-EVAL demonstration firmware

Switch mode single cell Li+ battery charger with OTG boost, voltage mode fuel gauge and LDO

AN4777 Application note

AN4749 Application note

EMIF06-USD14F3. 6-line low capacitance IPAD for micro-sd card with EMI filtering and ESD protection. Applications. Description. Features.

NUCLEO-L433RC-P NUCLEO-L452RE-P

STEVAL-IPMnM2N. Motor control power board based on the SLLIMM-nano 2 nd series. Description. Features. RoHS compliant

Getting started with X-NUCLEO-IHM06A1 low voltage stepper motor driver expansion board based on STSPIN220 for STM32 Nucleo

EVALKITSTKNX. Miniature transceiver STKNX evaluation and development kit. Features

Getting started with MotionAR activity recognition library in X-CUBE-MEMS1 expansion for STM32Cube

AN3147 Application note

UM2330 User manual. ST8500 boot. Introduction

SPC584Cx, SPC58ECx. 32-bit Power Architecture microcontroller for automotive ASIL-B applications. Features

AN2672 Application note

AN2737 Application note Basic in-application programming example using the STM8 I 2 C and SPI peripherals Introduction

UM2216 User manual. Getting started with MotionFA fitness activity library in X CUBE MEMS1 expansion for STM32Cube. Introduction

How to configure the BlueNRG-1 and BlueNRG-2 devices in network coprocessor mode. Main components Bluetooth Low Energy wireless system-on-chip

AN3964 Application note

STEVAL-STLKT01V1. SensorTile development kit. Description. Features

A scalable approach to your body, networking and security platforms. Description

TN1235 Technical note

AN2676 Application note

32L476GDISCOVERY. Discovery kit with STM32L476VG MCU. Features. Description

UM1982 User manual. Multi-Sensor RF 868 MHz platform. Introduction

Getting started with MotionAR activity recognition library in X-CUBE-MEMS1 expansion for STM32Cube

X-NUCLEO-53L0A1. Ranging and gesture detection sensor expansion board based on VL53L0X for STM32 Nucleo. Description. Features

STEVAL-STLKT01V1. SensorTile development kit. Description. Features

UM1719 User manual. The STPM3x evaluation software. Introduction

USB dongle for the Bluetooth class 2 SPBT3.0DP2 module

X-NUCLEO-53L1A1. Long distance ranging Time-of-Flight sensor expansion board based on VL53L1X for STM32 Nucleo. Description.

Description. July 2016 DocID Rev 2 1/6

Software GUI user guide for STEVAL-ISV021V1, STEVAL- IDS002V1 and STEVAL-IDS003V1 evaluation boards

AN3174 Application note

UM2119 User manual. Graphical user interface (GUI) for EVAL-L9907-H. Introduction

AN4872 Application note

AN2825 Application Note

STM8 I 2 C optimized examples

SPC58EHx,SPC58NHx. A scalable approach for high-end body, networking and security platforms for Automotive. Description. Features

UM2343 Application note

AN4113 Application note

STEVAL-SPBT4ATV3. USB dongle for the Bluetooth class 1 SPBT2632C1A.AT2 module. Features. Description

STBC ma standalone linear Li-Ion battery charger with thermal regulation. Description. Features. Applications

ST10F271B/E, ST10F272B/E Errata sheet

Transcription:

Application note Building a thermometer using the STM8 Nucleo-64 boards Introduction The NUCLEO-8S208RB (built around the STM8S208RBT6 device) and the NUCLEO-8L152R8 (built around the STM8L152R8T6 device) are boards that allow the evaluation of the main features of all the STM8S Series and STM8L Series microcontrollers. This application note demonstrates how to build a simple thermometer based on the STM8 Nucleo-64 boards and the LM235 precision temperature sensor. The STM8S208RBT6 or STM8L152R8T6 microcontroller (depending on the corresponding board) reads the temperature values and transmits them through the UART interface. The temperature values are then displayed on a terminal window (possibly based on a Windows HyperTerminal) of a PC connected to the UART through an RS232 or FTDI cable. Once the STM8 Nucleo-64 has been powered-up through a USB cable connected to the host PC, an informative message is displayed on the terminal window and the user is prompted to enter the 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 a one-hour period are recorded in the MCU data EEPROM once per hour. They can be displayed any time by pressing a push button. Table 1. Applicable products Type Evaluation boards Part number NUCLEO-8S208RB NUCLEO-8L152R8 Reference documents Available from STMicroelectronics website: STM8 Nucleo-64 boards data brief (DB3591) STM8L152R8T6 Nucleo-64 board user manual (UM2351) STM8S208RBT6 Nucleo-64 board user manual (UM2364) ST232C 5 V powered multi-channel RS-232 driver and receiver datasheet (DS1588) Precision temperature sensors datasheet (DS0437) for LM235 - Rev 1 - June 2018 For further information contact your local STMicroelectronics sales office. www.st.com

Prerequisites 1 Prerequisites The material required to run the STM8 Nucleo-64 boards thermometer demonstration application is the following: A terminal window running on a PC: the terminal emulator software can be Windows HyperTerminal (see Section A Configuring the terminal window), TeraTerm Pro, or any terminal software. An RS232 null-modem cable (transmit and receive line crosslinked) or an USB TTL serial cable. USB type-a to mini-b cable. - Rev 1 page 2/26

Application description 2 Application description 2.1 Hardware requirements This application uses the STM8 Nucleo-64 boards on-board LED (LD2) together with its associated resistor (R1). The external passive components required by the application are listed in the table below. Table 2. List of passive components Component name Value Comments R2 2.2 kω Pull-up resistor R3, R4 (optional) 100 Ω Current limitation resistors C6, C7 100 nf Debounce filters Button 1 - Standard push-button Button 2 (on-board user push-button) - Standard push-button C2, C3 100 nf Charge-pump capacitors C1, C4 100 nf Output capacitors C5 100 nf Decoupling capacitor 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 STM8 UART input/output operating at 5 V. This component is available in an SO16 package which fits the STM8 Nucleo-64 boards footprint. Refer to the corresponding datasheet for more information on the ST232C. The table below lists the packaged components. Table 3. List of packaged components Part number Component description Package ST232C (order code ST232CN) LM235 Very-high speed ultra-low-power consumption 5 V RS232 driver/receiver used for UART 5/12 V level shifter. Precision temperature sensor IC operating over a -40 to -125 C temperature range with 1 C initial accuracy. SO16 SO8 2.2 Application schematics The figures below shows how to interface the LM235 temperature sensor, the ST232C driver/receiver and the push-buttons with the STM8 Nucleo-64 boards. Button1 and Button2 (on-board user push-button) require an RC debounce filter to avoid triggering several interrupts. The debounce filter for Button1 and Button2 (on-board user push-button) consist of C7 and C6 capacitors plus I/Os pin internal pull-up resistor (about 45 KΩ). external pull-up resistors are required as the internal pull-ups of the I/Os are used. C2 and C3 are two charge-pump external capacitors which are used in the ST232C as voltage doubler and voltage inverter, respectively. The current flowing into the LM235 V+ pin must be regulated by a resistor. The sensor is powered from a 5 V power supply (V DD ). The breakdown voltage across the sensor is directly proportional to the absolute temperature with a sensitivity of 10mV/ K. Since the ambient temperature is around 300 K, the voltage drop is roughly 3 V, - Rev 1 page 3/26

Application schematics which leaves 2 V for the 2.2 kω resistor to regulate the current around 1 ma (intensity used to determine the typical values in the datasheet). For implementation details refer to the board schematics provided in the STM8 Nucleo-64 boards data brief (DB3591). Figure 1. STM8L Series application schematic 5V C2 100 nf C3 100 nf C4 100 nf C1 100 nf 1 2 3 4 5 6 7 ST232C 16 15 14 13 12 11 10 8 9 S U1 C5 100 nf 1 6 2 7 3 8 4 9 5 DB9 LD2 (on-board) 5V STM8L152R8T6 TIM3 USART3 PG0 PG1 R4 100 C7 100 nf Button 1 R1 PB5 GPIOD GPIOG PG6 PG4 R2 2.2 k 5V PC7 ADC1 AIN3 ADJ V- V+ R3 100 C6 100 nf Button 2 (on-board user push-button) LM235 - Rev 1 page 4/26

Application principle Figure 2. STM8S Series application schematic 5V C2 100 nf C3 100 nf C4 100 nf C1 100 nf 1 2 3 4 5 6 7 ST232C 16 15 14 13 12 11 10 8 9 S U1 C5 100 nf 1 6 2 7 3 8 4 9 5 DB9 LD2 (on-board) 5V STM8S208RBT6 TIM3 UART3 PD5 PD6 R4 100 C7 100 nf Button 1 R1 PC5 GPIOD GPIOA GPIOE PA3 PA4 R2 2.2 k 5V AB2 ADC2 AIN2 ADJ V- V+ R3 100 C6 100 nf Button 2 (on-board user push-button) LM235 2.3 Application principle At application startup, informative messages are displayed on the terminal window and the user is prompted to enter critical minimum and maximum temperature thresholds. The LM235 continuously measures the ambient temperature. The analog value is converted by the ADC2 (for STM8S Series) or the ADC1 (for STM8L Series) every 50 ms at each timer interrupt. In order to improve the temperature measurement reliability, the temperature data is obtained by averaging the first 16 samples measured after 1 second has elapsed. The resulting data is then compared to the current minimum and maximum temperature thresholds which can be modified if needed. LD2 is switched on if the temperature is below the low threshold or if it exceeds the high threshold defined by the user. Once per minute, the last computed average temperature is displayed on the terminal window together with the critical temperature warning message when relevant. The minimum and maximum temperatures over one hour period are recorded in the data EEPROM once per hour and displayed on the terminal window. Pressing Button1 prompts the user to enter new temperature threshold values. - Rev 1 page 5/26

Application principle Pressing Button2 (on-board user push-button) triggers the display on the terminal window of all recorded minimum and maximum temperatures stored in data EEPROM. LD2 is switched off. The figure below shows the application state diagram. Figure 3. Application state machine Startup Config rmal Button 1 pressed 1 Read 1 1 1s elapsed Idle Button 2 pressed The table below describes the actions performed by the application at each transition. Table 4. Application typical behaviors Application state LED state Entry condition Actions State 0 Idle - Default state Every 50 ms: conversion of analog temperature delivered by the LM235. State 1 Config - At startup or when Button1 is pressed Informative messages displayed on the terminal window. User prompted to enter minimum and maximum temperature thresholds for the first time or to update them. State 2 Read LD2 switched off Button2 pressed Minimum and maximum temperature values are read from data EEPROM and are displayed on the terminal window. - Rev 1 page 6/26

Launching the application Application state LED state Entry condition Actions State 3 rmal LD2 switched on if the temperature is out of range Every 1 s Every 1 min Every 1 hr Every 1 s: computation of average temperature from 16 samples. Update of current minimum and maximum temperature values if needed. Every 1 min: display of current temperature value and critical temperature warning message on the terminal window (if needed). Every 1 hr: minimum and maximum temperature over the previous hour recorded in data EEPROM. The algorithm that controls the progress of the execution according to the timer and external events is managed by the State_Machine() function (see Section 3.3.3 State machine flowchart). 2.4 Launching the application To display the terminal window, you can either run the preconfigured thermometer.h terminal based on Windows HyperTerminal (COM1 port) or create one by proceeding as explained in Section A Configuring the terminal window. At application startup, the user is prompted to enter the minimum and maximum temperature thresholds. The temperature thresholds must range from 40 to +125 C, and be expressed as follows: Positive temperature values: "+XXX". For example enter "+025" for 25 C. Negative temperature values: " XXX". For example enter " 005" for 5 C. Figure 4. STM8S terminal window at startup - Rev 1 page 7/26

Launching the application Figure 5. STM8L terminal window at startup - Rev 1 page 8/26

Software description 3 Software description 3.1 STM8 peripherals used by the application The thermometer application software does not use STM8S Series or STM8L Series standard firmware library. It rather consists in an optimized code by using direct register accesses to control and use the STM8S Series and STM8L Series general purpose peripherals as described below: CLK The clock controller enables and delivers the correct clock frequency to the CPU and peripherals. It configures the HSI clock as the 16 MHz master clock source and the CPU clock prescaler division factor to 1. GPIOs The STM8S Series and STM8L Series GPIOs are used to switch on and off LD2, and to interface with pushbuttons using the following configuration: EXTI STM8S Series: PA3 and PE4 (only PE4 is on-board) STM8L Series: PG6 and PG4 (only PG4 is on-board) The external interrupt sensitivity is configured to trigger an interrupt each time a falling edge and only a falling edge, is detected on PA3 or PA4 for STM8S Series or on PG6 or PG4 for STM8L Series. Flash memory The minimum and maximum temperature values over a one-hour period are saved in the data EEPROM for further display on the terminal window. U(S)ART STM8 Series uses UART3 and STM8L Series uses USART3 to communicate with the PC temrinal software. Its configuration is the one below: Baud rate = 9600 baud Word length = 8 bits One-stop bit parity Receive and transmit enabled te: For STM8L Series, the USART3 CLK must be disabled. Communications are managed by polling each receive and transmit operation on the UART3 (STM8S Series) or USART3 (STM8L Series) peripheral. ADC The channel 2 of the ADC2 for STM8S Series or the channel 3 of the ADC1 for STM8L Series is used to convert the analog data issued from the LM235 to digital values out of which the microcontroller can compute the current temperature value. Timer 3 (TIM3) This peripheral is used to generate a 50-ms timebase and to trigger a temperature acquisition every 50 ms. 3.2 Exclusion of the STM8S Series and STM8L Series standard firmware library As this application uses optimized code, thestm8s.h and stm8l.h files must be modified not include the STM8S Series standard firmware library and STM8L Series standard firmware library respectively. This is done by commenting the following define statement: #define USE_STDPERIPH_DRIVER - Rev 1 page 9/26

Application software flowcharts 3.3 Application software flowcharts This section gives an overview of the application software main loop, the interrupt function flowchart and the state machine flowchart as well as some reference to the terminal communication functions. 3.3.1 Main loop flowchart The main loop code initializes the required features, unlocks data EEPROM programming and calls the functions required to implement the general application algorithm. To minimize the time drift of the software real time clock (refer to Timer-triggered acquisition), the HSI clock is used as the master clock source. After the initialization phase is complete and informative messages are displayed on the terminal window, the user is prompted to enter the minimum and maximum temperature thresholds. As a consequence, the first time the State_Machine() function is called, it enters the configuration mode directly (state = 1, see Section 3.3.3 State machine flowchart ). The figure below shows the flowchart of the application software main loop. - Rev 1 page 10/26

Application software flowcharts Figure 6. Main loop flowchart Start UnlockFlash() Unlocks data EEPROM to save application state prior to reset CLK configuration Configures HSI as master clock source. Sets CPUDIV prescaler to 1: fmaster = fcpu = fhsi = 16 MHz GPIO configuration *For STM8Series: Configures PB5 as output push-pull high to drive LD2. Configures PG6 and PG4 as input pull-up with interrupts to handle buttons 1 and 2 *For STM8L Series: Configures PC5 as output push-pull high to drive LD2. Configures PA3 and PA4 as input pull-up with interrupts to handle buttons 1 and 2 EXTI configuration Configures the external interrupt sensitivity to falling edge on pins PG6 and PG4 for STM8S Series and on pins PA3 and PA4 for STM8L Series UART2_Init() Configures UART3 for STM8S Series and USART3 for STM8L Series peripheral for proper communication ADC configuration Configures ADC to operate at 4 MHz with input channel 2 of the ADC2 for STM8S Series and input channel 3 of the ADC1 for STM8L Series. Configures right alignment for converted data EnableInterrupts() Enables all STM8S Series and STM8L Series interrupts Display messages Displays informative messages on the terminal window and prompts the user to enter the threshold temperature values State_Machine() Implements the application state machine according to timer and button events. Displays terminal messages according to the different events 3.3.2 Interrupt function flowchart Push button acquisition for STM8L Series Each time Button1 or Button2 (on-board user push-button) is pressed, an interrupt is triggered and the PORTG_IRQhandler() function is called. The PORTG_IRQhandler() routine identifies which push button has been pressed by testing port G input register and asserts the ButtonPressed1 or ButtonPressed2 flag accordingly (see Section 3.3.3 State machine flowchart). These flags trigger a change of state in the application state machine. - Rev 1 page 11/26

Application software flowcharts The figure below shows the flowchart of the PORTG_IRQhandler() function. Figure 7. STM8L Series: PORTG_IRQhandler() function flowchart GPIO port G interrupt PG6 IDR = "0"? PG4 IDR = "0"? Set ButtonPressed1 Set ButtonPressed2 Back to main() Push button acquisition for STM8S Series Each time Button1 is pressed, an interrupt is triggered and the PORTA_IRQhandler() function is called. Each time Button2 (on-board user push-button) is pressed, an interrupt is triggered and the PORTE_IRQhandler() function is called. The routine asserts the ButtonPressed1 or ButtonPressed2 flag accordingly. These flags trigger a change of state in the application state machine. The figure below shows the flowchaert of the PORTA_IRQhandler() and PORTE_IRQhandler() functions for STM8S Series. - Rev 1 page 12/26

Application software flowcharts Figure 8. STM8S Series: PORTA_IRQhandler() and PORTE_IRQhandler() functions flowcharts GPIO port A interrupt GPIO port E interrupt PA3 IDR = "0"? PE4 IDR = "0"? Set ButtonPressed1 Set ButtonPressed2 Back to main() Back to main() Timer-triggered acquisition TIMER3 is configured to generate an interrupt every 50 ms to trigger temperature acquisitions. After each conversion of ADC2 channel 2 (for STM8S Series) or ADC1 channel 3 (for STM8L Series), the digital value is stored in the buffer array for further computations and ADC is powered down. A maximum of 16 samples are saved in the buffer array. This allows dividing by a power of two by performing a simple right shift, when calculating the average temperature over one-second period. TIM3_IRQHandler() calls the TRtc_CntUpdate() function which simulates a real time clock. It sets the flags representing seconds, minutes, and hours. This RTC routine is based on TIM3 50 ms timebase. Every second, the state machine automatically switches to state 3 (normal mode) (see Section 3.3.3 State machine flowchart). The figure below shows the flowchart of the TIM3_IRQhandler() function. - Rev 1 page 13/26

Application software flowcharts Figure 9. TIM3_Init() function flowchart TIM3 interrupt 16 values converted? Start ADC and conversion Store result in buffer array Power ADC down TRtc_CntUpdate() Back to main() 3.3.3 State machine flowchart The State_Machine function implements the algorithm that controls the progress of the application execution according to timer and external events. The different values of the state variable represent the application modes.: state = 0: Idle mode This is the state machine default state. The conversion of the analog temperature delivered by the LM235 is performed every 50 ms. This state is exited by pressing Button1 or Button2 (on-board user push-button). state 1 = Configuration mode In state machine Configuration mode, a terminal message prompts the user to input the minimum and maximum temperature thresholds. These values are read from the terminal window and recorded in decimal format. This state is entered at startup or when Button1 is pressed. state 2 = Read mode In state machine Read mode, the application reads back the minimum and maximum temperature pairs from data EEPROM and displays them on the terminal window together with an informative message. LD2 is also switched off. This state can onlye be entered by pressing Button2. state 3 = rmal mode The state machine rmal mode is entered every second. It is triggered by the TRtc_CntUpdate() routine that monitors the application time elapsed. Each time this state is entered, the average temperature is computed from 16 samples saved in the buffer array. If this temperature value exceeds the high threshold or is below the low threshold, LD2 is switched on. The current temperature is displayed on the terminal window once per minute together with a specific informative message when it is critical. A pair of maximum and minimum measured temperatures is recorded in data EEPROM over one-hour period. Up to 10 pairs can be stored in EEPROM. This means that a history of ten hour - Rev 1 page 14/26

Application software flowcharts measurements is kept. Writing the 11th hour data resets the EEPROM address pointer and overwrites the previous data. As a consequence, the data from the previous ten hours is overwritten. When entering states 1 and 2, the TIM3 counter is disabled as the normal mode is exited. When exiting these states, the timer registers are reassigned and the counter is enabled again to resume the default execution mode. See below the flowchart of the State_Machine() function. - Rev 1 page 15/26

Application software flowcharts Figure 10. State_Machine function flowchart Start state = 1? state = 3? Disable TIM3 counter state = 2? 1 s elapsed? Prompt the user for thresholds Get and save user inputs Disable TIM3 Read minimum and maximum temperatures from data EEPROM and display them on the terminal Calculate average temperature Update minimum and maximum temperature Enable TIM3 state = 0 Switch LD2 off Enable TIM3 Min. or Max. out of range? Switch LD2 state = 0 1 min elapsed? Display current temperature on terminal with specific message if critical 1 hr elapsed? Display current temperatures over the hour in data EEPROM (10 sets maximum) state = 0 ButtonPressed1 = 1? state = 1 ButtonPressed2 = 1? state = 3 End - Rev 1 page 16/26

Application software flowcharts 3.3.4 Terminal communication functions For a detailed description of the terminal communication functions, refer to Section A Configuring the terminal window. - Rev 1 page 17/26

Configuring the terminal window A Configuring the terminal window The terminal window connected to the STM8 Nucleo-64 board must be configured with the following settings valid for all terminal types: Communication port: COM1 or other available Bits per second: 9600 Data bits: 8 Parity: none Stop bits: 1 Flow control: none To provide a ready-to-use application example, a preconfigured terminal using Windows HyperTerminal and COM1 port is provided within the project folder. To launch it, simply execute the.ht file included in the project. However, the user can also set up a new connection with the STM8 Nucleo-64 board based on Windows HyperTerminal and related to this example by following the steps below: 1. Open Windows HyperTerminal application and choose a connection name, such as MyConnection and validate it by clicking OK. Figure 11. Launch Windows HyperTerminal 2. Select COM1 or any available port on your computer and validate your choice by clicking OK. Other fields can remain set to the default value. - Rev 1 page 18/26

Configuring the terminal window Figure 12. Select communication port 3. Configure the communication port properties as shown in the figure below. Windows HyperTerminal is launched and communications can start. Figure 13. Configure connection properties 4. To check communication settings: Disconnect the HyperTerminal by choosing Call > Disconnect from the HyperTerminal main menu. - Rev 1 page 19/26

Configuring the terminal window Once communications are stopped, go to the Settings tab in MyConnection Properties menu. The parameters should be set as shown below. Figure 14. Check communication settings Finally, click ASCII Setup in MyConnection Properties menu, and ensure that the ASCII parameters match those shown in the figure below. - Rev 1 page 20/26

Configuring the terminal window Figure 15. ASCII setup parameters Close MyConnection Properties menu, and restart communications by choosing Call > Call from the HyperTerminal main menu. The STM8 Nucleo-64 application is now ready to start. - Rev 1 page 21/26

Revision history Date Version Changes 29-Jun-2018 1 Initial release. Table 5. Document revision history - Rev 1 page 22/26

Contents Contents 1 Prerequisites...2 2 Application description...3 2.1 Hardware requirements...3 2.2 Application schematics...3 2.3 Application principle...5 2.4 Launching the application...7 3 Software description...9 3.1 STM8 peripherals used by the application...9 3.2 Exclusion of the STM8S Series and STM8L Series standard firmware library...9 3.3 Application software flowcharts...9 3.3.1 Main loop flowchart...10 3.3.2 Interrupt function flowchart...11 3.3.3 State machine flowchart...14 3.3.4 Terminal communication functions...16 A Configuring the terminal window...18 Revision history...22 - Rev 1 page 23/26

List of tables List of tables Table 1. Applicable products...1 Table 2. List of passive components...3 Table 3. List of packaged components...3 Table 4. Application typical behaviors...6 Table 5. Document revision history... 22 - Rev 1 page 24/26

List of figures List of figures Figure 1. STM8L Series application schematic...4 Figure 2. STM8S Series application schematic....5 Figure 3. Application state machine...6 Figure 4. STM8S terminal window at startup...7 Figure 5. STM8L terminal window at startup....8 Figure 6. Main loop flowchart... 11 Figure 7. STM8L Series: PORTG_IRQhandler() function flowchart... 12 Figure 8. STM8S Series: PORTA_IRQhandler() and PORTE_IRQhandler() functions flowcharts.... 13 Figure 9. TIM3_Init() function flowchart... 14 Figure 10. State_Machine function flowchart... 16 Figure 11. Launch Windows HyperTerminal... 18 Figure 12. Select communication port... 19 Figure 13. Configure connection properties... 19 Figure 14. Check communication settings... 20 Figure 15. ASCII setup parameters.... 21 - Rev 1 page 25/26

IMPORTANT NOTICE PLEASE READ CAREFULLY STMicroelectronics NV and its subsidiaries ( ST ) reserve the right to make changes, corrections, enhancements, modifications, and improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST s terms and conditions of sale in place at the time of order acknowledgement. Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design of Purchasers products. license, express or implied, to any intellectual property right is granted by ST herein. Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product. ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners. Information in this document supersedes and replaces information previously supplied in any prior versions of this document. 2018 STMicroelectronics All rights reserved - Rev 1 page 26/26