Hi,
I stumbled upon this topic Arduino Due ADC->DMA->USB 1MSPS and I might need some hints. Differing from the solution presented there, I am trying to sample with an external 18bit ADC with at least 100k samples afap with a maximum of 1.6M samples the ADC can handle. It is connected via 19 wires to the PIOC Register, 18 data one clock. On the rising edge of the clock the 18bit data is valid, so I am triggering an edge detect interrupt, the PIOC_Handler() then reads the register.
I understand the idea of DMA, but i have not fully understood the Atmel Datasheet regarding DMA and USB, so I am not really sure how to store the data and how to send it via USB.
void setup() {
PMC->PMC_WPMR = 0x504D4300; //Disable Write Protect for PMC
PIOC->PIO_WPMR = 0x50494F00; //Disable Write Protect for PIO
PMC->PMC_PCER0 |= 0b00000000000000000010000000000000; // Enable Clock for PID13 -> PIOC
PIOC->PIO_PER |= 0b00000001111011111111001111111110; // Disable peripheral functions and enable PIO on PC1-PC9, PC12-PC19, PC21-PC24
PIOC->PIO_ODR |= 0b00000001111011111111001111111110; // Make all Pins Inputs
PIOC->PIO_OER |= 0b00000001000000000000000000000000; // Make PC24 an Output
PIOC->PIO_AIMER |= 0b00000000100000000000000000000000; // Interrupt source is described in ELSR and FRLHSR
PIOC->PIO_ESR |= 0b00000000100000000000000000000000; // Interrupt source is an Edge detection event on PC23
PIOC->PIO_REHLSR |= 0b00000000100000000000000000000000; // Interrupt on Rising Edge (ELSR = 0)(ESR = 1)/High Level (ELSR = 1) on PC23
PIOC->PIO_IDR = ~0b00000000100000000000000000000000; // Disable all Interrupts on PC except for PC23
PIOC->PIO_IER |= 0b00000000100000000000000000000000; // Enable Interrupt on PC23
NVIC_EnableIRQ(PIOC_IRQn); // Enable Interrupts for PIOC
}
volatile uint32_t ergebnis;
void PIOC_Handler(void) {
uint32_t isr = PIOC->PIO_ISR;
ergebnis = PIOC->PIO_PDSR;
}
Previously, I was sending out the data via UART, but that resulted in errors at baudrates > 1MBaud.
- If of any use for my application, how do i store the data via DMA (DPRAM?) instead of using uint32_t ergebnis?
- How do i then send it out via USB? I understand that I will need a buffer, but which size? As far as i can see from the CDC.cpp at \Arduino15\packages\arduino\hardware\sam\1.6.4\cores\arduino\USB the buffersize used by the Arduino IDE is 512 Byte, but as I understand from the SAM3X datasheet on page 1053, 1024 Byte out of 3 DPRAM Banks is supported.
Your help is appreciated.
Regards,
Laura