-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathanalogReadDMA.ino
50 lines (39 loc) · 1.01 KB
/
analogReadDMA.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
/*
analogReadDMA
This sketch shows how to use analogReadDMA() method.
analogReadDMA uses ADC with DMA to read samples and increases sampling rate.
*/
// Define the number of sample to read
#define NB_SAMPLE 16
// Array where save the samples
uint32_t samples[NB_SAMPLE] = {0};
// callback parameter
bool readingOver = false;
// callback function
void callback(void *cbParam)
{
*((bool *)cbParam) = true;
}
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("-- analogReadDMA sketch --");
delay(500);
// Start DMA acquisiton
analogReadDMA(A0, samples, NB_SAMPLE, callback, &readingOver);
}
void loop() {
if (readingOver == true)
{
for (uint32_t idx=0; idx<NB_SAMPLE; idx++)
{
Serial.print("raw: ");
Serial.println(samples[idx], DEC);
}
readingOver = false;
analogReadDMA(A0, samples, NB_SAMPLE, callback, &readingOver);
}
}