2014-06-09 12:37 PM
Hello,
I have a problem with configuring ADC & DMA. This is the code ADCRCC -> 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; DMARCC -> 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.2014-06-09 01:48 PM
Yeah, that looks like it will be a whole heap of fun to debug..
2014-06-09 11:45 PM
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.
2014-06-10 05:41 AM
I think you need to set sequence length in ADC->SQR1
2014-06-12 01:45 AM