AnsweredAssumed Answered

STM32F4 Discovery ADC + DMA

Question asked by kostyszyn.marcin on Nov 7, 2014
Latest reply on Nov 7, 2014 by Clive One
Hi there, I'm trying to use two ADC channels and send them to array via DMA.
Here is my code.


void ADC_Config (void){
     
    //Rozdzielczosc 12 bitow, 
    //Wyrownanie bitow do prawej
    ADC->CCR |= ADC_CCR_ADCPRE_0 | ADC_CCR_ADCPRE_1;            //PCLK2/8=72MHz/8=9 MHz;
    ADC1->CR1 = ADC_CR1_SCAN;               //Scan mode Enable (do wykonania pomariu z kilku kanalow)
    ADC1->CR2 = ADC_CR2_CONT;               //Pomiar ciagly
     
    ADC1->SQR1|= ADC_SQR1_L_1;                          // wybor liczby pomiarow (2)
    ADC1->SQR3 = ADC_SQR3_SQ1_1 | ADC_SQR3_SQ1_3;       //Jako pierwszy pomiar wykonany jest na kanale 10
    ADC1->SQR3|= ADC_SQR3_SQ2_4;                                        //Jako drugi pomiar - kanal 16 (termometr) 
     
    /*The temperature sensor, VREFINT and the VBAT channel are available only on the master
ADC1 peripheral*/
    //3 cykle dla kanalu 10
    ADC1->SMPR1 |= ADC_SMPR1_SMP16_0 | ADC_SMPR1_SMP16_1 | ADC_SMPR1_SMP16_2;   //480 cykli dla kanalu 16;
    ADC1->CR2|= ADC_CR2_DMA;                //Wlaczenie DMA
    ADC->CCR |= ADC_CCR_TSVREFE;        //Odpalenie termometru
    ADC1->CR2 |= ADC_CR2_ADON;              //Wlaczenie ADC1
    //Kalibracja automatyczna
}
 
void DMA_Config (void){
    DMA2_Stream4->CR = 0;                                       //Wylacz Stream4 dla DM2
    while (DMA2_Stream4->CR & DMA_SxCR_EN);     //Czekaj tak dlugo, az bit EN=0.
    DMA2_Stream4->PAR = ADC1_DR_Address;            //Adres docelowy
    DMA2_Stream4->M0AR = (unsigned int)buforADC;            //buforADC to tablica z wartosciami do przeslania
    DMA2_Stream4->NDTR=2;                                       //Rozmiar przesylanej tablicy to 2
    //ADC1 jest zglaszane na kanale 0
    DMA2_Stream4->CR |= DMA_SxCR_PL_1;              //Ustawienie priorytetu na wysoki
    //Kierunek przesylania danych: pamiec -> peryferia
    DMA2_Stream4->CR |= DMA_SxCR_MINC;              // Autoinkrementacja pamieci (kolejne wartosci z tablicy)
    DMA2_Stream4->CR |= DMA_SxCR_CIRC;              //Circular mode
    DMA2_Stream4->CR |= DMA_SxCR_PSIZE_0  ;     //Half-word dla peryferiow
    DMA2_Stream4->CR |= DMA_SxCR_MSIZE_0;           //Half-word dla pamieci
    DMA2_Stream4->CR |= DMA_SxCR_EN;                    //Enable Stream5   
}
 
////////////////////////////////////////////////////////////////////////
 
//piece of main
 
    ADC1->CR2 |= ADC_CR2_SWSTART;           //ADC enable
    ADC1->CR2 |= ADC_CR2_DDS;
    while(1){
         
        napiecie = buforADC[0] * 8059/10000;
        temperatura = (1430 - buforADC[1] * 8059/10000)*10/43+25;           Delay(50);
    }


My problem is that values from buforADC[0] and buforADC[1] are mixing.Sometimes buforADC[1] has the value from buforADC[0] and so on..
I coulnd't find any solution on polish forums, so I try here. Sorry forry my poor english, hope to get some answers!
Cheers!

Outcomes