test

Dependencies:   mbed

Committer:
ouxinlitc
Date:
Sat Feb 22 12:07:21 2020 +0000
Revision:
0:926c96080c12
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ouxinlitc 0:926c96080c12 1 #include "mbed.h"
ouxinlitc 0:926c96080c12 2
ouxinlitc 0:926c96080c12 3 /*
ouxinlitc 0:926c96080c12 4 This basic example just shows how to read the ADC internal channels raw values.
ouxinlitc 0:926c96080c12 5 Please look in the corresponding device reference manual for a complete
ouxinlitc 0:926c96080c12 6 description of how to make a temperature sensor, VBat or Vref measurement.
ouxinlitc 0:926c96080c12 7 */
ouxinlitc 0:926c96080c12 8
ouxinlitc 0:926c96080c12 9 AnalogIn adc_temp(ADC_TEMP);
ouxinlitc 0:926c96080c12 10 AnalogIn adc_vref(ADC_VREF);
ouxinlitc 0:926c96080c12 11 #if defined(TARGET_DISCO_F051R8) || defined(TARGET_NUCLEO_F030R8) || defined(TARGET_NUCLEO_F031K6) || defined(TARGET_NUCLEO_F042K6) || defined(TARGET_NUCLEO_F070RB) || defined(TARGET_NUCLEO_F072RB) || defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F207ZG) || defined(TARGET_NUCLEO_F302R8) || defined(TARGET_NUCLEO_F303K8) || defined(TARGET_DISCO_F303VC) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F303ZE) || defined(TARGET_DISCO_F334C8) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_MTS_DRAGONFLY_F411RE) || defined(TARGET_MTS_MDOT_F405RG) || defined(TARGET_MTS_MDOT_F411RE) || defined(TARGET_DISCO_F401VC) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_ARCH_MAX) || defined(TARGET_DISCO_F407VG) || defined(TARGET_NUCLEO_F410RB) || defined(TARGET_ELMO_F411RE) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F412ZG) || defined(TARGET_DISCO_F413ZH) || defined(TARGET_DISCO_F429ZI) || defined(TARGET_NUCLEO_F429ZI) || defined(TARGET_NUCLEO_F439ZI) || defined(TARGET_B96B_F446VE) || defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F446ZE) || defined(TARGET_DISCO_F469NI) || defined(TARGET_DISCO_F746NG) || defined(TARGET_NUCLEO_F746ZG) || defined(TARGET_NUCLEO_F756ZG) || defined(TARGET_NUCLEO_F767ZI) || defined(TARGET_DISCO_F769NI) || defined(TARGET_DISCO_L072CZ_LRWAN1) || defined(TARGET_NUCLEO_L432KC) || defined(TARGET_DISCO_L476VG) || defined(TARGET_NUCLEO_L476RG) || defined(TARGET_NUCLEO_L486RG)
ouxinlitc 0:926c96080c12 12 AnalogIn adc_vbat(ADC_VBAT); // Warning: Not available on all devices
ouxinlitc 0:926c96080c12 13 #endif
ouxinlitc 0:926c96080c12 14
ouxinlitc 0:926c96080c12 15 DigitalOut led(LED1);
ouxinlitc 0:926c96080c12 16
ouxinlitc 0:926c96080c12 17 int main()
ouxinlitc 0:926c96080c12 18 {
ouxinlitc 0:926c96080c12 19 printf("\nSTM32 ADC internal channels reading example\n");
ouxinlitc 0:926c96080c12 20 while(1) {
ouxinlitc 0:926c96080c12 21 printf("ADC Temp = %f\n", (adc_temp.read()*100));
ouxinlitc 0:926c96080c12 22 printf("ADC VRef = %f\n", adc_vref.read());
ouxinlitc 0:926c96080c12 23 #if defined(TARGET_DISCO_F051R8) || defined(TARGET_NUCLEO_F030R8) || defined(TARGET_NUCLEO_F031K6) || defined(TARGET_NUCLEO_F042K6) || defined(TARGET_NUCLEO_F070RB) || defined(TARGET_NUCLEO_F072RB) || defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F207ZG) || defined(TARGET_NUCLEO_F302R8) || defined(TARGET_NUCLEO_F303K8) || defined(TARGET_DISCO_F303VC) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F303ZE) || defined(TARGET_DISCO_F334C8) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_MTS_DRAGONFLY_F411RE) || defined(TARGET_MTS_MDOT_F405RG) || defined(TARGET_MTS_MDOT_F411RE) || defined(TARGET_DISCO_F401VC) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_ARCH_MAX) || defined(TARGET_DISCO_F407VG) || defined(TARGET_NUCLEO_F410RB) || defined(TARGET_ELMO_F411RE) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F412ZG) || defined(TARGET_DISCO_F413ZH) || defined(TARGET_DISCO_F429ZI) || defined(TARGET_NUCLEO_F429ZI) || defined(TARGET_NUCLEO_F439ZI) || defined(TARGET_B96B_F446VE) || defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F446ZE) || defined(TARGET_DISCO_F469NI) || defined(TARGET_DISCO_F746NG) || defined(TARGET_NUCLEO_F746ZG) || defined(TARGET_NUCLEO_F756ZG) || defined(TARGET_NUCLEO_F767ZI) || defined(TARGET_DISCO_F769NI) || defined(TARGET_DISCO_L072CZ_LRWAN1) || defined(TARGET_NUCLEO_L432KC) || defined(TARGET_DISCO_L476VG) || defined(TARGET_NUCLEO_L476RG) || defined(TARGET_NUCLEO_L486RG)
ouxinlitc 0:926c96080c12 24 printf("ADC VBat = %f\n", adc_vbat.read());
ouxinlitc 0:926c96080c12 25 printf("\033[3A");
ouxinlitc 0:926c96080c12 26 #else
ouxinlitc 0:926c96080c12 27 printf("\033[2A");
ouxinlitc 0:926c96080c12 28 #endif
ouxinlitc 0:926c96080c12 29 led = !led;
ouxinlitc 0:926c96080c12 30 wait(1.0);
ouxinlitc 0:926c96080c12 31 }
ouxinlitc 0:926c96080c12 32 }