I encountered a strange behaviour of the DMA and wanted to ask if I'm missing some point to get it working correctly.
I'm working on the FRDM-KL27Z board.
The idea is to measure from 2 ADC Inputs and save the data inside a buffer.
I'm trying an approach like described in AN4590, just without the PDB trigger.
The raw funcionality should be to trigger the ADC in software mode and safe the result inside a buffer.
- ADC reads Input 1 and writes inside ADC0_RA
- COCO is set and DMA0 is set to start at peripheral request from ADC
- DMA0 Transfers data to a buffer and increments
- DMA1 is linked to start after DMA0 finishes
- DMA1 reads a value from an array and writes it to ADC0_SC1A, then increments the sopurce array
- ADC now starts a new conversion on the channel described inside the Array
And from here everything starts over.
After completing a whole cyclus an interrupt is called, which resets the destination address of DMA0 and the source address of DMA1.
Everything works, except one little detail:
DMA0 does not increment if DMA1 triggers a new ADC conversion.
The channel is changed and the result written inside the correct destination buffer, but always inside the first address of this buffer.
Has anyone ever encountered such a behaviour?
I'll post the DMA and ADC settings at the end of this post.
ADC0_CFG1_Mode = 11
ADC0_SC2_DMAEN = 1
DMA_DCR0_EINT = 1
DMA_DCR0_ERQ = 1
DMA_DCR0_CS = 1
DMA_DCR0_EADREQ = 1
DMA_DCR0_SSIZE = 10
DMA_DCR0_DSIZE = 10
DMA_DCR0_DINC = 1
DMA_DCR0_DREQ = 1
DMA_DCR0_LINKCC = 10
DMA_DCR0_LCH1 = 01
DMAMUX0_CHCFG0_SOURCE = 0d40 (ADC0)
DMA_DCR1_EINT = 1
DMA_DCR1_ERQ = 1
DMA_DCR1_CS = 1
DMA_DCR1_EADREQ = 1
DMA_DCR1_SSIZE = 01
DMA_DCR1_DSIZE = 01
DMA_DCR1_SINC = 1
DMA_DCR1_DREQ = 1
DMAMUX0_CHCFG1_SOURCE = 0d60 (always on)