ST AN3964 APPLICATION NOTE

September 2011 Doc ID 022101 Rev 1 1/12
AN3964
Application note
How to design a simple temperature measurement application
using the STM32L-DISCOVERY

1 Introduction

This application note describes a method of implementing a simple application for
temperature measurement using the STM32L-DISCOVERY. The solution described in this
factory or user calibration method is described to improve the accuracy of the temperature
sensor.
The demonstration application does not require any additional hardware. Once the
STM32L-DISCOVERY board is updated with the associated firmware and is powered-up
through a USB cable connected to the host PC, the application is ready to display the
temperature of the STM32L1 microcontroller.

1.1 Reference documents

STM32L-DISCOVERY user manual (UM1079)
STM32L-DISCOVERY Application note: Current consumption measurement and touch
sensing demonstration (AN3413)
STM32L151xx and STM32L152xx Flash and EEPROM programming (PM0062)
STM32L151xx and STM32L152xx Ultralow power ARM-based 32-bit MCU with up to 128
Kbytes of Flash memory, RTC, LCD, USB, USART, I2C, SPI, timers, ADC, DAC,
comparators datasheet
The above documents are available at http://www.st.com.
www.st.com
Contents AN3964
2/12 Doc ID 022101 Rev 1
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Reference documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Application overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 Temperature sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Temperature measurement and data processing . . . . . . . . . . . . . . . . . . . . 3
2.3 Application example description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1 Setting up the board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Using the demonstration application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2.1 Temperature sensor calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.3 Estimation of temperature sensor engineering tolerance . . . . . . . . . . . . . . 8
4 Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1 STM32L peripherals used by the application . . . . . . . . . . . . . . . . . . . . . . . 9
4.2 STM32L15x standard firmware library configuration . . . . . . . . . . . . . . . . 10
5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
AN3964 Application overview
Doc ID 022101 Rev 1 3/12

2 Application overview

This section describes how the temperature sensor works and its measurements performed
by the STM32L1 microcontroller embedded on the STM32L-DISCOVERY board.
A brief description of how the example temperature measurement application was
implemented follows afterwards.

2.1 Temperature sensor

The temperature sensor integrated in the STM32L microcontroller provides an analog
output voltage proportional to the chip junction temperature of the device.
Note: Please note that the temperature information provided by sensor is the thermal chip junction
temperature (actual temperature of semiconductor surface) and may differ from the ambient
temperature. Please see section “Thermal characteristics” of product datasheet for more
details.
The integrated temperature sensor provides reasonably linear characteristics with a
deviation typically of ± 1% from linear asymptotic functions and a temperature range equal
to that of the device (–40 °C to 85 °C) with a maximum junction temperature of 150 °C.
The sensor provides good linearity but quite poor interchangeability and must be calibrated
to obtain good overall accuracy. If the application is designed to only measure the relative
temperature variations, the temperature sensor does not need to be calibrated.

2.2 Temperature measurement and data processing

The temperature sensor is internally connected to Channel 16 (ADC_IN16) of the ADC
(analog-to-digital converter) in the STM32L1 and is used to sample and convert the
temperature sensor output voltage. The raw ADC data must be further processed to display
the temperature in a standardized unit of measurement (Celsius, Farenheit or Kelvin).
The ADC reference voltage is connected to the 3V V
DD
power supply of the STM32L-
Discovery board. If the V
DD
value is not accurately known, as in case of battery-operated
applications, it must be measured in order to obtain a correct overall ADC conversion range.
To easily measure the power supply voltage, we recommend using the embedded internal
reference (bandgap) voltage. The precise voltage of the embedded bandgap is individually
measured during the manufacturing process and stored in the protected memory area at
address @1FF80078.
The embedded bandgap voltage calibration data is a 12-bit unsigned number (right-aligned
bits, stored in 2 bytes) acquired by the STM32L1 ADC with a 3V (± 10 mV) reference
voltage. The accuracy of the factory measured bandgap calibration data is provided with an
accuracy of ± 5 mV. Please see the datasheet for more details.
Application overview AN3964
4/12 Doc ID 022101 Rev 1

2.3 Application example description

Every 2 seconds the application acquires 16 samples from the temperature sensor voltage.
The ADC raw data are filtered and averaged using an interquartile mean algorithm to reduce
noise from the power supply system and the result is recalculated into standard units of
temperature measurement (°C, in this example).
The LCD display is updated every 2 seconds either by ADC raw data or by the current
temperature value in degrees Celsius. The user can switch between both temperature data
representations by pressing the user button.
To demonstrate the low power capabilities of the STM32L1 ultra-low power microcontroller,
the CPU is switched to Stop mode with the RTC (real-time clock) wake-up set to 2 seconds
within the time interval between temperature sensor data measurements. The ADC data
acquisition and data transfers are managed by direct memory access (DMA) while the CPU
is in Low-power Sleep mode. The CPU is in Run mode at 16 MHz based on the HSI
oscillator clock) only during the initialization phase and during the data processing period.
Loading...
+ 8 hidden pages