Skip to content

Add analogReadDMA example #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions examples/Analog/analogReadDMA/analogReadDMA.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}