Hello,
I have a problem with Teensy 4.0, that the DMA buffer is correctly filled with the actual values from ADC1_R0 only the first time from start until interruptOnComplete(), then the DMA buffer does not work anymore... What am I missing to set? It worked fine on Teensy 3.2.
Here is my simplified sample code:
I have a problem with Teensy 4.0, that the DMA buffer is correctly filled with the actual values from ADC1_R0 only the first time from start until interruptOnComplete(), then the DMA buffer does not work anymore... What am I missing to set? It worked fine on Teensy 3.2.
Here is my simplified sample code:
Code:
#include <ADC.h>
#include <DMAChannel.h>
const uint16_t buffer_size = 16;
DMAMEM static volatile uint16_t __attribute__((aligned(32))) dma_adc_buff1[buffer_size];
const int readPin_adc0 = A0;
ADC *adc = new ADC();
DMAChannel dma_ch1;
void interruptDMA();
void setup()
{
while (!Serial && millis() < 5000)
;
Serial.begin(9600);
Serial.println("Starting");
pinMode(readPin_adc0, INPUT_DISABLE);
pinMode(LED_BUILTIN, OUTPUT);
adc->adc0->setAveraging(1);
adc->adc0->setResolution(12);
adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED);
adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::HIGH_SPEED);
dma_ch1.source((volatile uint16_t &)(ADC1_R0));
dma_ch1.destinationBuffer((uint16_t *)dma_adc_buff1, buffer_size * 2);
dma_ch1.interruptAtCompletion();
dma_ch1.disableOnCompletion();
dma_ch1.attachInterrupt(&interruptDMA);
dma_ch1.triggerAtHardwareEvent(DMAMUX_SOURCE_ADC1);
dma_ch1.enable(); // Enable the DMA channel
adc->adc0->enableDMA();
adc->adc0->startSingleRead(readPin_adc0);
adc->adc0->startQuadTimer(500);
}
void loop()
{
delay(1000);
int i = 0;
while (i < buffer_size)
{
Serial.printf("%u: %u ", i, dma_adc_buff1[i]);
i++;
}
Serial.printf("ADC1_R0: %u \n", ADC1_R0);
dma_ch1.enable(); // enable DMA again
}
void interruptDMA()
{
//dma_ch1.clearComplete();
dma_ch1.clearInterrupt();
#if defined(__IMXRT1062__) // Teensy 4.0
asm("DSB");
#endif
}