00001 /**@file temperature_sensor.c 00002 * @brief MB851 temperature sensor APIS 00003 * 00004 * 00005 * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. --> 00006 */ 00007 #include PLATFORM_HEADER 00008 #include BOARD_HEADER 00009 #include "hal/hal.h" 00010 #include "hal/error.h" 00011 #include "hal/micro/temperature_sensor.h" 00012 #include "hal/micro/adc.h" 00013 00014 void temperatureSensor_Init(void) 00015 { 00016 /* Configure temperature sensor GPIO */ 00017 halGpioConfig(TEMPERATURE_SENSOR_GPIO,GPIOCFG_ANALOG); 00018 /* Init ADC driver */ 00019 halInternalInitAdc(); 00020 00021 /* 00022 NOTE: 00023 The ADC extended range is inaccurate due to the high voltage mode bug of the general purpose ADC 00024 (see STM32W108 errata). As consequence, it is not reccomended to use this ADC driver for getting 00025 the temperature values. 00026 */ 00027 #ifdef ENABLE_ADC_EXTENDED_RANGE_BROKEN 00028 halAdcSetRange(TRUE); 00029 #endif /* ENABLE_ADC_EXTENDED_RANGE_BROKEN */ 00030 }/* end temperatureSensor_Init() */ 00031 00032 int32u temperatureSensor_GetValue(void) 00033 { 00034 static int16u ADCvalue; 00035 static int16s volts; 00036 00037 /* 00038 NOTE: 00039 The ADC extended range is inaccurate due to the high voltage mode bug of the general purpose ADC 00040 (see STM32W108 errata). As consequence, it is not reccomended to use this ADC driver for getting 00041 the temperature values. 00042 */ 00043 halStartAdcConversion(ADC_USER_APP, ADC_REF_INT, ADC_SOURCE_ADC2_VREF2, ADC_CONVERSION_TIME_US_4096); 00044 00045 halReadAdcBlocking(ADC_USER_APP, &ADCvalue); // This blocks for a while, about 4ms. 00046 00047 // 100 uVolts 00048 volts = halConvertValueToVolts(ADCvalue); 00049 00050 return ((18641 - (int32s)volts)*100)/1171; 00051 }/* end temperatureSensor_GetValue() */ 00052