Reading analog input with an STM32F103C8T6 board. ADC is calibrated to achieve higher accuracy.

Dependencies:   mbed

Reading analog input with STM32F103C8T6 board

Import the program into your online compiler.

Schematic

/media/uploads/hudakz/stm32f103c8t6_aanalogin.png

Revision:
1:7522adef9bd0
Parent:
0:5d7148c1f26a
Child:
2:b0563c2ef616
--- a/main.cpp	Sat Nov 18 14:31:54 2017 +0000
+++ b/main.cpp	Tue Feb 05 13:04:43 2019 +0000
@@ -1,18 +1,15 @@
-#include "stm32f103c8t6.h"
 #include "mbed.h"
-#include "AnalogInCal.h"
+#include "AnalogIn.h"
+
+const float REF_VOLT = 3300; // Reference voltage in millivolts
 
-const float REF_VOLT = 3300; // Reference voltage in milivolts
+Serial      pc(PA_2, PA_3);
+DigitalOut  myled(LED1);
+AnalogIn    analogIn(PA_0); // Create an analog input
+float       voltage;    
  
-int main() {
-    confSysClock();     //Configure system clock (72MHz HSE clock, 48MHz USB clock)
-    
-    Serial      pc(PA_2, PA_3);
-    DigitalOut  myled(LED1);
-//    AnalogIn    analogIn(PA_0); // Create an uncalibrated analog input
-    AnalogInCal analogIn(PA_0); // Create an analog input with calibrated AD convertor
-    float       voltage;    
-    
+int main()
+{       
     while (1) {
         voltage = analogIn.read() * REF_VOLT;  // convert analog to digital
         pc.printf("voltage = %.0f mV\r\n", voltage);