STM32 ADC single conversion DMA read

Publisher:快乐奇迹Latest update time:2018-09-22 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

 The DMA reading method is very suitable for high-frequency ADC sampling signals.

     The DMA reading method of ADC is actually similar to the interrupt reading method in the previous article, and the initialization code is even more similar. The initialization code is as follows:

static void ADC_GPIO_Config(void)

{

  GPIO_InitTypeDef  GPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //ʹÄÜPB,PE¶Ë¿ÚʱÖÓ

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;

GPIO_Init(GPIOA, &GPIO_InitStructure);

}

static void ADC_Mode_Config(void)

{

  ADC_InitTypeDef ADC_InitStructure;

  DMA_InitTypeDef DMA_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);

DMA_DeInit(DMA1_Channel1);

DMA_InitStructure.DMA_PeripheralBaseAddr=(uint32_t)&ADC1->DR;

DMA_InitStructure.DMA_MemoryBaseAddr=(uint32_t)&adcconverdata;

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

DMA_InitStructure.DMA_BufferSize=1;

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;

DMA_InitStructure.DMA_PeripheralInc =DMA_PeripheralInc_Disable ;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;

DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;

DMA_Init(DMA1_Channel1,&DMA_InitStructure);

DMA_Cmd(DMA1_Channel1,ENABLE);

ADC_DeInit(ADC1);

ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ScanConvMode=DISABLE;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel=ADC_Channel_1;

ADC_Init(ADC1,&ADC_InitStructure);

RCC_ADCCLKConfig(RCC_PCLK2_Div8); 

ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_239Cycles5);

ADC_DMACmd(ADC1,ENABLE);

  ADC_Cmd(ADC1,ENABLE);

ADC_ResetCalibration(ADC1);

while(ADC_GetResetCalibrationStatus(ADC1));

ADC_StartCalibration(ADC1);

while(ADC_GetCalibrationStatus(ADC1));

ADC_SoftwareStartConvCmd(ADC1,ENABLE);

}

void ADC_InitConfig(void)

{

  ADC_GPIO_Config();

  ADC_Mode_Config();

}

The code above is very clear. Although there are no annotations, I believe you can understand it. The code is very simple, so I won’t explain it.


Keywords:STM32 Reference address:STM32 ADC single conversion DMA read

Previous article:STM32 ADC multi-channel DMA transfer
Next article:STM32 ADC conversion interrupt read

Recommended ReadingLatest update time:2024-11-15 07:35

STM32 precise delay function
#include "stm32f10x_systick.h"      //Use SysTick's normal counting mode to manage delays  //Include delay_us, delay_ms    //Fixed the error of calling in the interrupt and causing an infinite loop  //To prevent inaccurate delays, use a do while structure!      static u8 fac_us=0; //us delay multip
[Microcontroller]
Getting Started with STM32 BIT_BAND Bit Band Alias ​​Area
1. What is a bit segment and bit band alias area? 2. What are its benefits? Answer 1: Yes, remember MCS51? MCS51 has bit operation, which takes one bit (BIT) as the data object.       MCS51 can simply operate the second bit of P1 port independently: P1.2=0;P1.2=1; just like this, the third pin (BIT2) of P1 port
[Microcontroller]
Getting Started with STM32 BIT_BAND Bit Band Alias ​​Area
How the intelligent STM32 F7 microcontroller meets the higher processing performance requirements of embedded systems
STMicroelectronics (ST) has launched the industry's first STM32 F7 series of microcontrollers based on ARM's latest Cortex-M7 core, which far exceeds ST's previous 32-bit STM32F4 microcontrollers and can double the processing performance and DSP performance through a seamless upgrade path. "As a high-end product in t
[Microcontroller]
How the intelligent STM32 F7 microcontroller meets the higher processing performance requirements of embedded systems
Summary of the use of STM32's CRH, CRL, ODR and IDR registers
1. Download:     STM32F103 Chinese Reference Manual     Baidu Netdisk: Link: http://pan.baidu.com/s/1boYtx0b  Password: lwcg 2. Introduction of CRH and CRL: The usage of CRH and CRL is basically the same. CRH is used to control the high 8 bits (Pin15---Pin8) of GPIOX (X represents A---G), while CRL is used to control
[Microcontroller]
stm32 RS485 SP3485
RS485 is half-duplex communication (2-wire)   The DE and RE of the SP3485 chip are short-circuited together and connected to the PG3 of the STM32F1 chip. The PG3 pin can be used to control the transmission and reception of the SP3485. When PG3=0, it is in the receiving mode, and when PG3=1, it is in the sending mod
[Microcontroller]
stm32 RS485 SP3485
STM32 uses ultra-high precision synchronous clock design
Some occasions may require ultra-high-precision synchronous clocks, such as 0.5ppm or even lower clocks, and ensure a good repetition rate for multiple devices. Therefore, this article mainly describes how to design an ultra-high-precision clock based on stm32. First of all, if the clock accuracy is 0.5ppm or even
[Microcontroller]
STM32 Getting Started Learning EXTI External Interrupt (STM32F030F4P6 based on CooCox IDE)
The following code treats PA0 as a button port, pulls up inside the chip, and when the button is closed, the IO port is pulled low, triggering an interrupt. #include "stm32_lib/inc/stm32f0xx_rcc.h" #include "stm32_lib/inc/stm32f0xx_exti.h" #include "stm32_lib/inc/stm32f0xx_gpio.h" #include "stm32_lib/inc/stm32f0xx_s
[Microcontroller]
STM32 Development Board Getting Started Tutorial (Thirteen) - SPI Mode Read and Write SD Card
Function introduction: Use SPI mode to read and write SD card block data and send it to PC through serial port for viewing SD card is the abbreviation of Secure Digital Card, which literally translates into Chinese as "Secure Digital Card". It is a brand-new memory card product jointly developed by Japan's Panasoni
[Microcontroller]
STM32 Development Board Getting Started Tutorial (Thirteen) - SPI Mode Read and Write SD Card
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号