![](/media/cache/group/ST_logo_2020_blue_V_cmyk.jpg.50x50_q85.jpg)
ADC internal channels read example.
Dependencies: mbed
main.cpp
- Committer:
- bcostm
- Date:
- 2016-11-18
- Revision:
- 2:9bab1d673af9
- Parent:
- 1:55c36e464885
- Child:
- 3:5467a013d0a0
File content as of revision 2:9bab1d673af9:
#include "mbed.h" #define VREF 3300.0f /* Device power supply in mV */ // Parameters for temperature sensor only #define AMBIENT_TEMP 25.0f /* Ambient Temperature in °C */ #define VSENS_AT_AMBIENT_TEMP 760.0f /* VSENSE value in mV at ambient temperature */ #define AVG_SLOPE 25.0f /* Average slope in mV/°C multiplied by 10 */ //AnalogIn vbat(ADC_VBAT); // To measure VBat AnalogIn tempsensor(ADC_TEMP); // To measure Temperature sensor DigitalOut led(LED1); int main() { float meas_f; float JTemp_f; printf("\nSTM32 Internal Channels example\n"); while(1) { /* Note 1: As VBAT voltage could be higher than VDDA, to ensure the correct operation of the ADC, the VBAT pin is internally connected to a bridge divider by 4. Note 2: On some devices the VBAT and temperature sensor are connected to the same ADC internal channel Only one conversion, either temperature sensor or VBAT, must be selected at a time. When both conversion are enabled simultaneously, only the VBAT conversion is performed. */ //printf("\nVBat = %.1f mV\n", vbat.read() * VREF * 4); meas_f = tempsensor.read(); /* Compute the Junction Temperature value JTemp = ((Vsens - V25)/Avg_Slope) + 25°C The internal temperature sensor supports a temperature range of –40 to 125°C with an accuracy of +/-1.5°C. */ JTemp_f = (((meas_f * VREF) - VSENS_AT_AMBIENT_TEMP) * 10.0f / AVG_SLOPE) + AMBIENT_TEMP; printf("Internal Temperature = %.1f degree C\n", JTemp_f); led = !led; wait(1.0); } }