STM32F411 上带有 DMA 的 ADC 无法工作

问题描述 投票:0回答:1

我想使用 DMA 在连续扫描模式下读取 4 个 ADC 通道(PA0、PA1、PA2 和 PA3),问题是一旦 uC 运行程序,它只会执行一个 ADC 读取序列,然后就会“卡住”,代码仍在运行,但好像只允许一次 ADC 序列转换,这是代码。

#include "stm32f411xe.h"
int16_t adc_ch[4];
int main()
{
 //Enabling peripheral clocks*/
 RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
 RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
 RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;  // Enable DMA2 clock  
                                                                                
//Pin A0-A3  as analog inputs
GPIOA->MODER |= GPIO_MODER_MODE0|GPIO_MODER_MODE1|GPIO_MODER_MODE2|GPIO_MODER_MODE3;    

// Configuring sequence for analog reading
ADC1->SQR1 |= 3<<20;                    // Configuring sequence length for 4 analog channels 
ADC1->SQR3 |= 0<<0;                     // A0 first in the sequence
ADC1->SQR3 |= 1<<5;                     // A1 second in the sequence
ADC1->SQR3 |= 2<<10;                    // A2 third in the sequence
ADC1->SQR3 |= 3<<15;                    // A3 forth in the sequence
// Setting ADC1 
ADC1->CR1 |= ADC_CR1_SCAN;          // Enabling scanning mode 
ADC1->CR2 |= ADC_CR2_DMA;               // Enabling DMA mode

//Setting DMA channel
DMA2_Stream0->PAR  = (uint32_t)(&(ADC1->DR));           // DMA source address
DMA2_Stream0->M0AR = (uint32_t)(&(adc_ch[0]));      // DMA destination address

DMA2_Stream0->NDTR = 4;                                     // # of transmissions
DMA2_Stream0->CR |= DMA_SxCR_CIRC                           // Enabling circular mode
                    | DMA_SxCR_MINC                         // Enabling memory (destiny address) increase after each transmission 
                    | DMA_SxCR_PSIZE_0                      // Peripheral (source) size set to 16 bits
                    | DMA_SxCR_MSIZE_0;                     // Memory (destiny) size set to 16 bits
DMA2_Stream0->CR |= DMA_SxCR_EN;                                        // DMA channel enable   

//ADC1 A0 config 
ADC1->CR2 |= ADC_CR2_CONT;
ADC1->CR2 |= ADC_CR2_ADON;
ADC1->CR2 |= ADC_CR2_SWSTART;

while(1)
{
}

}

也许有些东西不见了,但我找不到它

stm32 dma adc
1个回答
0
投票

您还必须设置ADC1_CR2.DDS。

© www.soinside.com 2019 - 2024. All rights reserved.