Contiki 3.x
temperature-sensor.c
Go to the documentation of this file.
1 /**@file cpu/stm32w108/hal/micro/cortexm3/temperature-sensor.c
2  * @brief MB851 temperature sensor APIS
3  *
4  *
5  * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
6  */
7 #include PLATFORM_HEADER
8 #include BOARD_HEADER
9 #include "hal/hal.h"
10 #include "hal/error.h"
12 #include "hal/micro/adc.h"
13 
15 {
16  /* Configure temperature sensor GPIO */
17  halGpioConfig(TEMPERATURE_SENSOR_GPIO,GPIOCFG_ANALOG);
18  /* Init ADC driver */
19  halInternalInitAdc();
20 
21  /*
22  NOTE:
23  The ADC extended range is inaccurate due to the high voltage mode bug of the general purpose ADC
24  (see STM32W108 errata). As consequence, it is not reccomended to use this ADC driver for getting
25  the temperature values.
26  */
27 #ifdef ENABLE_ADC_EXTENDED_RANGE_BROKEN
28  halAdcSetRange(TRUE);
29 #endif /* ENABLE_ADC_EXTENDED_RANGE_BROKEN */
30 }/* end temperatureSensor_Init() */
31 
33 {
34  static uint16_t ADCvalue;
35  static int16_t volts;
36 
37  /*
38  NOTE:
39  The ADC extended range is inaccurate due to the high voltage mode bug of the general purpose ADC
40  (see STM32W108 errata). As consequence, it is not reccomended to use this ADC driver for getting
41  the temperature values.
42  */
43  halStartAdcConversion(ADC_USER_APP, ADC_REF_INT, ADC_SOURCE(halGetADCChannelFromGPIO(TEMPERATURE_SENSOR_GPIO),ADC_MUX_VREF2), ADC_CONVERSION_TIME_US_4096);
44 
45  halReadAdcBlocking(ADC_USER_APP, &ADCvalue); // This blocks for a while, about 4ms.
46 
47  // 100 uVolts
48  volts = halConvertValueToVolts(ADCvalue);
49 
50  return ((18641 - (int32_t)volts)*100)/1171;
51 }/* end temperatureSensor_GetValue() */
52 
uint32_t temperatureSensor_GetValue(void)
Get temperature sensor value.
#define TEMPERATURE_SENSOR_GPIO
Description temperature sensor GPIO.
Definition: board.h:226
void temperatureSensor_Init(void)
Temperature Sensor Initialization function.
#define TRUE
An alias for one, used for clarity.
Header for A/D converter.
Header for temperature sensor driver.
Generic set of HAL includes for all platforms.
Return codes for API functions and module definitions.
void halGpioConfig(uint32_t io, uint32_t config)
Configure an IO pin&#39;s operating mode.
Definition: micro-common.c:48