osd-contiki/cpu/stm32w108/hal/micro/cortexm3/temperature-sensor.c

53 lines
1.7 KiB
C
Raw Normal View History

2014-06-19 14:30:33 +02:00
/**@file cpu/stm32w108/hal/micro/cortexm3/temperature-sensor.c
* @brief MB851 temperature sensor APIS
2010-10-25 11:03:38 +02:00
*
*
* <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
*/
#include PLATFORM_HEADER
#include BOARD_HEADER
#include "hal/hal.h"
#include "hal/error.h"
#include "hal/micro/temperature-sensor.h"
2010-10-25 11:03:38 +02:00
#include "hal/micro/adc.h"
void temperatureSensor_Init(void)
{
/* Configure temperature sensor GPIO */
halGpioConfig(TEMPERATURE_SENSOR_GPIO,GPIOCFG_ANALOG);
/* Init ADC driver */
halInternalInitAdc();
2014-06-19 14:28:13 +02:00
2010-10-25 11:03:38 +02:00
/*
2014-06-19 14:28:13 +02:00
NOTE:
The ADC extended range is inaccurate due to the high voltage mode bug of the general purpose ADC
2010-10-25 11:03:38 +02:00
(see STM32W108 errata). As consequence, it is not reccomended to use this ADC driver for getting
2014-06-19 14:28:13 +02:00
the temperature values.
2010-10-25 11:03:38 +02:00
*/
#ifdef ENABLE_ADC_EXTENDED_RANGE_BROKEN
halAdcSetRange(TRUE);
#endif /* ENABLE_ADC_EXTENDED_RANGE_BROKEN */
}/* end temperatureSensor_Init() */
uint32_t temperatureSensor_GetValue(void)
2010-10-25 11:03:38 +02:00
{
static uint16_t ADCvalue;
static int16_t volts;
2010-10-25 11:03:38 +02:00
2011-03-21 13:11:52 +01:00
/*
2014-06-19 14:28:13 +02:00
NOTE:
The ADC extended range is inaccurate due to the high voltage mode bug of the general purpose ADC
2011-03-21 13:11:52 +01:00
(see STM32W108 errata). As consequence, it is not reccomended to use this ADC driver for getting
2014-06-19 14:28:13 +02:00
the temperature values.
2011-03-21 13:11:52 +01:00
*/
halStartAdcConversion(ADC_USER_APP, ADC_REF_INT, ADC_SOURCE(halGetADCChannelFromGPIO(TEMPERATURE_SENSOR_GPIO),ADC_MUX_VREF2), ADC_CONVERSION_TIME_US_4096);
2014-06-19 14:28:13 +02:00
2010-10-25 11:03:38 +02:00
halReadAdcBlocking(ADC_USER_APP, &ADCvalue); // This blocks for a while, about 4ms.
2014-06-19 14:28:13 +02:00
2010-10-25 11:03:38 +02:00
// 100 uVolts
volts = halConvertValueToVolts(ADCvalue);
2014-06-19 14:28:13 +02:00
return ((18641 - (int32_t)volts)*100)/1171;
2010-10-25 11:03:38 +02:00
}/* end temperatureSensor_GetValue() */