MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / efm32_misc_getCelsius

Function efm32_misc_getCelsius

bsp/efm32/dev_misc.c:155–169  ·  view source on GitHub ↗

/ * @brief * Convert ADC result to degree celsius. * * @details * * @note * See section 2.3.4 in the reference manual for details on this calculatoin * * @param adcResult * Raw value from ADC to be converted to celsius * * @return * The temperature value (signed integer) in degrees celsius times 100 * ***************************************************************************

Source from the content-addressed store, hash-verified

153 *
154 ******************************************************************************/
155rt_int32_t efm32_misc_getCelsius(rt_uint32_t adcResult)
156{
157 /* Factory calibration temperature from device information page. */
158 rt_int32_t cal_temp = ((DEVINFO->CAL & _DEVINFO_CAL_TEMP_MASK) \
159 >> _DEVINFO_CAL_TEMP_SHIFT) * 100;
160
161 /* Factory calibration value from device information page. */
162 rt_int32_t cal_value = ((DEVINFO->ADC0CAL2 & _DEVINFO_ADC0CAL2_TEMP1V25_MASK) \
163 >> _DEVINFO_ADC0CAL2_TEMP1V25_SHIFT) * 10000;
164
165 /* Temperature gradient (from datasheet) in (ADC unit / degree celsius * 100) */
166 rt_int32_t t_grad = -385;
167
168 return (cal_temp - (cal_value - (rt_int32_t)adcResult * 10000) / t_grad);
169}
170
171/*******************************************************************************
172 * Export to FINSH

Callers 1

rt_hw_get_tempFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected