AnsweredAssumed Answered

dma config issue

Question asked by Gnichi Mohamed on Nov 9, 2016
Latest reply on Apr 5, 2017 by Hui_Ma

Hello

I want to scan 3 ADC channels with eDMA using two dma channels 0 an 1 on K02 microcontroller. So far my config should make it work but i don't find why it doesn't work.

 

SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK; //enable clock for ADC0
ADC0->SC2 |=ADC_SC2_DMAEN_MASK;
ADC0->CFG1|=ADC_CFG1_MODE(0x03)|ADC_CFG1_ADIV(0x02)|ADC_CFG1_ADLSMP_MASK;
ADC0->CFG2|=ADC_CFG2_ADHSC_MASK|ADC_CFG2_ADLSTS(0);
ADC0->SC3 |=ADC_SC3_CAL_MASK;
while(ADC0->SC3 & ADC_SC3_CAL_MASK){};
ADC0->SC1[0] = ADC_SC1_ADCH(31);
ADC0->SC1[0]|=ADC_SC1_AIEN_MASK;
/* DMA */
SIM->SCGC6|= SIM_SCGC6_DMAMUX_MASK;
SIM->SCGC7|= SIM_SCGC7_DMA_MASK;
DMAMUX->CHCFG[FIRSTDMACHANNEL]&=~DMAMUX_CHCFG_ENBL_MASK;
DMAMUX->CHCFG[FIRSTDMACHANNEL]|=DMAMUX_CHCFG_SOURCE(63);//DMA source is an array
DMAMUX->CHCFG[FIRSTDMACHANNEL]|=DMAMUX_CHCFG_ENBL_MASK;
DMA0->TCD[FIRSTDMACHANNEL].SADDR=(uint32_t)&adc_mux[0];//source is adc_mux array for channel config
DMA0->TCD[FIRSTDMACHANNEL].DADDR=(uint32_t)&(ADC0->SC1[0]);
DMA0->TCD[FIRSTDMACHANNEL].SOFF=0x01;
DMA0->TCD[FIRSTDMACHANNEL].DOFF=0;
DMA0->TCD[FIRSTDMACHANNEL].ATTR=DMA_ATTR_SSIZE(0)| DMA_ATTR_DSIZE(0);
DMA0->TCD[FIRSTDMACHANNEL].NBYTES_MLNO=0x01;
DMA0->TCD[FIRSTDMACHANNEL].CITER_ELINKNO=0x03;
DMA0->TCD[FIRSTDMACHANNEL].BITER_ELINKNO=0x03;
DMA0->TCD[FIRSTDMACHANNEL].SLAST=-3;
DMA0->TCD[FIRSTDMACHANNEL].CSR=0;
DMA0->TCD[FIRSTDMACHANNEL].DLAST_SGA = 0x00;
DMAMUX->CHCFG[SECONDDMACHANNEL]&=~DMAMUX_CHCFG_ENBL_MASK;
DMAMUX->CHCFG[SECONDDMACHANNEL]|=DMAMUX_CHCFG_SOURCE(40);//DMA source is an ADC0
DMAMUX->CHCFG[SECONDDMACHANNEL]|=DMAMUX_CHCFG_ENBL_MASK;
DMA0->TCD[SECONDDMACHANNEL].SADDR=(uint32_t)&(ADC0->R[0]);
DMA0->TCD[SECONDDMACHANNEL].DADDR=(uint32_t)&adc_result[0];
DMA0->TCD[SECONDDMACHANNEL].SOFF=0;
DMA0->TCD[SECONDDMACHANNEL].SLAST=0x00;
DMA0->TCD[SECONDDMACHANNEL].DOFF=0x02;
DMA0->TCD[SECONDDMACHANNEL].ATTR=DMA_ATTR_SSIZE(1)|DMA_ATTR_DSIZE(1);
DMA0->TCD[SECONDDMACHANNEL].NBYTES_MLNO=0x02;
DMA0->TCD[SECONDDMACHANNEL].CITER_ELINKYES= DMA_CITER_ELINKYES_ELINK_MASK|
DMA_CITER_ELINKYES_LINKCH(FIRSTDMACHANNEL)|
DMA_CITER_ELINKYES_CITER(0x0C);
DMA0->TCD[SECONDDMACHANNEL].BITER_ELINKYES=DMA_BITER_ELINKYES_ELINK_MASK|
DMA_BITER_ELINKYES_LINKCH(FIRSTDMACHANNEL)|
DMA_BITER_ELINKYES_BITER(0x0C);
DMA0->TCD[SECONDDMACHANNEL].DLAST_SGA = -24;
DMA0>TCD[SECONDDMACHANNEL].CSR=DMA_CSR_MAJORELINK_MASK

                                                         |DMA_CSR_MAJORLINKCH(FIRSTDMACHANNEL);
ADC0->SC1[0]=ADC_SC1_ADCH(0x14); // trigger first conversion

 

I am using the exact same dma config from this post:DMA Channels Problem (Using DMA to Emulate ADC Flexible Scan Mode) 

Outcomes