cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F100C6, ADC & DMA

peter_l
Associate II
Posted on June 09, 2014 at 21:37

Hello,

I have a problem with configuring ADC & DMA. This is the code

ADC

RCC -> APB2ENR |= RCC_APB2ENR_ADC1EN;

ADC1 -> CR1 |= ADC_CR1_SCAN;

ADC1 -> CR2 |= ADC_CR2_EXTSEL_0 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_2;

ADC1 -> CR2 |= ADC_CR2_CONT;

ADC1 -> SMPR2 |= ADC_SMPR2_SMP1_0 | ADC_SMPR2_SMP1_1;

ADC1 -> SMPR2 |= ADC_SMPR2_SMP2_0 | ADC_SMPR2_SMP2_1;

ADC1 -> SQR3 |= ADC_SQR3_SQ1_0 | ADC_SQR3_SQ2_1;

ADC1 -> CR2 |= ADC_CR2_ADON;

ADC1 -> CR2 |= ADC_CR2_RSTCAL;

while (((ADC1 -> CR2) & ADC_CR2_RSTCAL) == ADC_CR2_RSTCAL) {}

ADC1 -> CR2 |= ADC_CR2_CAL;

while (((ADC1 -> CR2) & ADC_CR2_CAL) == ADC_CR2_CAL) {}

ADC1 -> CR2 |= ADC_CR2_SWSTART | ADC_CR2_EXTTRIG;

DMA

RCC -> AHBENR |= RCC_AHBENR_DMA1EN;

DMA1_Channel1 -> CCR |= DMA_CCR1_CIRC;

DMA1_Channel1 -> CCR |= DMA_CCR1_MINC;

DMA1_Channel1 -> CCR |= DMA_CCR1_PSIZE_0;

DMA1_Channel1 -> CCR |= DMA_CCR1_MSIZE_0;

DMA1_Channel1 -> CCR |= DMA_CCR1_PL_1;

DMA1_Channel1 -> CNDTR |= 0x02;

DMA1_Channel1 -> CPAR = (uint32_t)&ADC1->DR;

DMA1_Channel1 -> CMAR = (uint32_t) &Battery -> AdcValue;

DMA1_Channel1 -> CCR |= DMA_CCR1_EN;

ADC1 -> CR2 |= ADC_CR2_DMA;

Port

A.1

GPIOA -> CRL &= ~(0x0F<<

4

);

GPIOA -> CRL &= ~(0x03 <<

6

); // Analog mode

GPIOA -> CRL &= ~(0x03 <<

4

);

A.2

GPIOA -> CRL &= ~(0x0F <<

8

); // Clear old value

GPIOA -> CRL &= ~(0x03 <<

10

); // Analog mode

GPIOA -> CRL &= ~(0x03 << 8);

The problem is that I can measure voltage only on Port A.1 andi wantPort A.2 too.

4 REPLIES 4
Posted on June 09, 2014 at 22:48

Yeah, that looks like it will be a whole heap of fun to debug..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
peter_l
Associate II
Posted on June 10, 2014 at 08:45

Hello,

voltage on port A.1 is 0.93V and ADC shows 1160.It works in 12 bit mode, for reference voltage i use Vcc = 3.3V. Voltage

on port A.2 is 0.3V and ADC shows again 1160. My question is how to setup ADC to work with both channel? I want to work in continuous

mode, first measure port A.1 then port A.2.

p.s. I have missed some code. AdcValue is one-dimensional array (uint16_t AdcValue[2];) declared in structure.

zzdz2
Associate II
Posted on June 10, 2014 at 14:41

I think you need to set sequence length in ADC->SQR1

peter_l
Associate II
Posted on June 12, 2014 at 10:45

Thank's !