Contiki 2.5
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
cpu
stm32w108
hal
micro
cortexm3
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"
11
#include "
hal/micro/temperature_sensor.h
"
12
#include "
hal/micro/adc.h
"
13
14
void
temperatureSensor_Init
(
void
)
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
32
int32u
temperatureSensor_GetValue
(
void
)
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
Generated on Fri Aug 30 2013 12:34:09 for Contiki 2.5 by
1.8.3.1