2013-03-15 16:14:09 +01:00
|
|
|
/**@file temperature-sensor.c
|
2010-10-25 11:03:38 +02:00
|
|
|
* @brief MB851 temperature sensor APIS
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
|
|
|
|
*/
|
|
|
|
#include PLATFORM_HEADER
|
|
|
|
#include BOARD_HEADER
|
|
|
|
#include "hal/hal.h"
|
|
|
|
#include "hal/error.h"
|
2013-03-15 16:14:09 +01:00
|
|
|
#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();
|
|
|
|
|
|
|
|
/*
|
|
|
|
NOTE:
|
|
|
|
The ADC extended range is inaccurate due to the high voltage mode bug of the general purpose ADC
|
|
|
|
(see STM32W108 errata). As consequence, it is not reccomended to use this ADC driver for getting
|
|
|
|
the temperature values.
|
|
|
|
*/
|
|
|
|
#ifdef ENABLE_ADC_EXTENDED_RANGE_BROKEN
|
|
|
|
halAdcSetRange(TRUE);
|
|
|
|
#endif /* ENABLE_ADC_EXTENDED_RANGE_BROKEN */
|
|
|
|
}/* end temperatureSensor_Init() */
|
|
|
|
|
2013-03-15 16:14:09 +01:00
|
|
|
uint32_t temperatureSensor_GetValue(void)
|
2010-10-25 11:03:38 +02:00
|
|
|
{
|
2013-03-15 16:14:09 +01: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
|
|
|
/*
|
|
|
|
NOTE:
|
|
|
|
The ADC extended range is inaccurate due to the high voltage mode bug of the general purpose ADC
|
|
|
|
(see STM32W108 errata). As consequence, it is not reccomended to use this ADC driver for getting
|
|
|
|
the temperature values.
|
|
|
|
*/
|
2011-04-20 12:14:11 +02:00
|
|
|
halStartAdcConversion(ADC_USER_APP, ADC_REF_INT, ADC_SOURCE(halGetADCChannelFromGPIO(TEMPERATURE_SENSOR_GPIO),ADC_MUX_VREF2), ADC_CONVERSION_TIME_US_4096);
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
halReadAdcBlocking(ADC_USER_APP, &ADCvalue); // This blocks for a while, about 4ms.
|
|
|
|
|
|
|
|
// 100 uVolts
|
|
|
|
volts = halConvertValueToVolts(ADCvalue);
|
|
|
|
|
2013-03-15 16:14:09 +01:00
|
|
|
return ((18641 - (int32_t)volts)*100)/1171;
|
2010-10-25 11:03:38 +02:00
|
|
|
}/* end temperatureSensor_GetValue() */
|
|
|
|
|