After a tedious struggle with the so far undeveloped Maple dual simultaneous adc, (and myself as an undeveloped programmer…) I believe I got to the point where dual adc data is being collected (supposed to) and sent in a series of 32 bit dual-adc samples to the DMA. (As defined in the dual adc setup).
Now, I need help in fetching the data from the dma buffers and sending it to an array, where I can manipulate it.
I have no idea how to do that.
Here is the DMA setup I have: (and hope is correct. No errors shown)
/*
*/
dma_setup_transfer (
DMA1, /*dev*/
DMA_CH1, /*chan*/
ADC1_BASE, /*peripheral_address*/
DMA_SIZE_32BITS, /*peripheral_size*/
DMA1_BASE, /*memory_address */
DMA_SIZE_32BITS, /*peripheral_size*/
DMA_MEM_2_MEM /*mode, Memory to memory mode */
);
dma_set_num_transfers(DMA1,DMA_CH1,4); //4 pairs analog channels = four 32 bit values.
/*
*/
My understanding is that my sampled and collected data is located as a set of 32 bits dual channels data in the dma space.
Please, be specific and detailed, and send an example if available. It will be my first dma use.
Thanks
samtal
Help in Reading DMA
(2 posts) (2 voices)-
Posted 4 years ago #
-
the call to dma_setup_transfer() has some bugs:
- the peripheral address should not be ADC1_BASE -- if you take a look at the ADC register map, the register map base address actually points to the status register (ADC_SR). the register which contains the converted results is the regular data register (ADC_DR). so you want to pass its address (&ADC1_BASE->DR) instead of ADC1_BASE.
- the desired memory address is not DMA1_BASE. that's the base address of DMA1's register map, which is not a place where you want to store accumulated values. since you say you're trying to accumulate results in an array, you need to pass that array's address as the target. make sure it's an array of uint32.
- the mode argument should not include DMA_MEM_2_MEM. that's for transfers from SRAM to SRAM. what you are trying to do is to transfer from a peripheral address (namely ADC1_DR) to SRAM.
based on your description, you at least want DMA_MINC_MODE; without this, you'll just keep overwriting the first array index with the converted values. if you use DMA_MINC_MODE, the DMA controller will store the first converted result at array index 0, then increment the index as it goes, storing the second converted result at index 1, the third at index 2, and so on.
there's an example in the libmaple /examples/ directory which shows how to set up the DMA peripheral for use with a USART which you may find useful, in particular the function init_dma_xfer():
https://github.com/leaflabs/libmaple/blob/master/examples/test-usart-dma.cpp#L95
if you want to be interrupted when the transfer is done, you'll also need DMA_TRNS_CMPLT in the mode flags. this leaves you with the following call to dma_setup_transfer() (leave out the "
| DMA_TRNS_CMPLT
" if you don't want an interrupt):dma_setup_transfer(DMA1, DMA_CH1, &ADC1_BASE->DR, DMA_SIZE_32BITS, name_of_your_array, DMA_SIZE_32BITS, DMA_MINC_MODE | DMA_TRNS_CMPLT);
you'll then also need to attach an interrupt handler (which gets called when the transfer is complete) with
dma_attach_interrupt(DMA1, DMA_CH1, your_interrupt_handler)
.Posted 4 years ago #
Reply
You must log in to post.