Reading analog input with an STM32F103C8T6 board. ADC is calibrated to achieve higher accuracy.
Reading analog input with STM32F103C8T6 board
Import the program into your online compiler.
Schematic
Diff: main.cpp
- Revision:
- 0:5d7148c1f26a
- Child:
- 1:7522adef9bd0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Nov 18 14:31:54 2017 +0000 @@ -0,0 +1,23 @@ +#include "stm32f103c8t6.h" +#include "mbed.h" +#include "AnalogInCal.h" + +const float REF_VOLT = 3300; // Reference voltage in milivolts + +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; + + while (1) { + voltage = analogIn.read() * REF_VOLT; // convert analog to digital + pc.printf("voltage = %.0f mV\r\n", voltage); + myled = !myled; + wait_ms(1000); + } +} + \ No newline at end of file