/
SingleConversionInterrupt.ino
54 lines (41 loc) · 1.21 KB
/
SingleConversionInterrupt.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <STM32ADC.h>
STM32ADC myADC(ADC1);
uint8 adc_pin = PA0;
volatile static bool triggered;
volatile uint32 adc_value;
//-----------------------------------------------------------------------------
// This function will be called after the conversion is done
//-----------------------------------------------------------------------------
void adc_int()
{
adc_value = myADC.getData();
triggered = 1;
}
//-----------------------------------------------------------------------------
void setup()
{
// Serial.begin(19200); // useless for USB serial
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); // LED off
while (!Serial); delay(10);
Serial.print("Setup...");
myADC.setPins(&adc_pin, 1);
myADC.calibrate();
myADC.setSampleRate(ADC_SMPR_1_5);
myADC.attachInterrupt(adc_int);
Serial.println("done.");
}
//-----------------------------------------------------------------------------
void loop()
{
// Take our samples
triggered = 0;
myADC.startConversion();
while (triggered == 0); // wait here till conversion is finished
Serial.print("Readin = ");
Serial.println(adc_value);
digitalWrite(LED_BUILTIN, LOW); // on
delay(500);
digitalWrite(LED_BUILTIN, HIGH); // off
delay(500);
}