Contiki 2.5
temperature_sensor.c
Go to the documentation of this file.
1 /**@file 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 int16u ADCvalue;
35  static int16s 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 - (int32s)volts)*100)/1171;
51 }/* end temperatureSensor_GetValue() */
52