STM32-ADC Introduction

Publisher:SereneMelodyLatest update time:2015-10-19 Source: eefocusKeywords:STM32  ADC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Basic steps of ADC configuration:

1. Turn on the clocks of DMA and ADC1.

In RCC_Configuration(), add:

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

2. Configure analog IO input port

Configure in GPIO_Configuration()

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //ADC0 -light
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //ADC9-sound
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOB, &GPIO_InitStructure);

3. Configure DMA initialization and ADC initialization

void DMA_Configuration(void)

void ADC1_Configuration(void)

4. Start and read the ADC data

启动:ADC_SoftwareStartConvCmd(ADC1, ENABLE);

Wait for DMA processing completion flag: if (DMA_GetFlagStatus (DMA_FLAG_TC1) == 1)

deal with:

5. Selection of ADC hardware reference voltage:

void DMA_Configuration(void)
{
DMA_DeInit(DMA_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;       //Define DMA peripheral base
addressDMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue; //Define DMA memory base addressDMA_InitStructure.DMA_DIR
= DMA_DIR_PeripheralSRC;                //Peripheral as the source of data transmission (peripheral to memory) DMA_DIR_PeripheralDST——memory to peripheralDMA_InitStructure.DMA_BufferSize
= 3;                             //Continuously convert 3 AD channel valuesDMA_InitStructure.DMA_PeripheralInc
= DMA_PeripheralInc_Disable; //Peripheral register address remains
unchangedDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;           //Memory register address increments
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //Peripheral data width 32bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;     //Memory data width 32bit
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;      //DMA mode is circular
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMA priority
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;        //DMA is not set for memory to memory transfer
DMA_Init(DMA_Channel1, &DMA_InitStructure);

DMA_Cmd(DMA_Channel1, ENABLE);
}

void ADC1_Configuration(void)
{
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; // ADC1 ADC2 in independent mode
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //ENABLE-ADC multi-channel scan, DISABLE-ADC single channel scan
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // ENABLE--ADC continuous conversion mode DISABLE--ADC single conversion mode
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; // Triggered by software
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //Data aligned to the right
ADC_InitStructure.ADC_NbrOfChannel = 3; //Continuously convert 3 AD channel values
​​ADC_Init(ADC1, &ADC_InitStructure);

//Enable Vrefint channel17
ADC_TempSensorVrefintCmd(ENABLE); //channel17

   // ADC1 regular channel17 configuration
ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 1, ADC_SampleTime_28Cycles5); //Vref
// ADC1 regular channel0 configuration
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 2, ADC_SampleTime_28Cycles5); //light
// ADC1 regular channel9 configuration
ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 3, ADC_SampleTime_28Cycles5); //sound

// ADC_RegularChannelConfig(ADC1, ADC_Channel_1,4, ADC_SampleTime_55Cycles5); //voltage

// Enable ADC1 DMA );
ADC_DMACmd(ADC1, ENABLE);

// Enable ADC1
ADC_Cmd(ADC1, ENABLE);

// Enable ADC1 reset calibaration register   
ADC_ResetCalibration(ADC1);
// Check the end of ADC1 reset calibration register
while(ADC_GetResetCalibrationStatus(ADC1));

// Start ADC1 calibaration
ADC_StartCalibration(ADC1);
// Check the end of ADC1 calibration
while(ADC_GetCalibrationStatus(ADC1));

  
}

void ADC_process_Voltage_Light_Voice(void)
{
ADC_Cmd(ADC1, ENABLE);
DMA_Cmd(DMA_Channel1, ENABLE);
   
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
// Delay(20);
    while(1)
{
      if(DMA_GetFlagStatus(DMA_FLAG_TC1)==1)
   {
        DMA_ClearFlag(DMA_FLAG_TC1); // Clear Channel 1 DMA_FLAG_TC flag
           break;
   }
   if((DMA_GetFlagStatus(DMA_FLAG_HT1)==1)||(DMA_GetFlagStatus(DMA_FLAG_TE1)==1))
   {
   DMA_ClearFlag(DMA_FLAG_HT1);
    DMA_ClearFlag(DMA_FLAG_TE1);
    ADC_SoftwareStartConvCmd(ADC1, ENABLE);
   }

}
   // voltage
    adv[0] = (float)1.2*4096/(ADC_ConvertedValue[0]&0x0fff); //放大50倍
   // light
adv[1] = (float)(ADC_ConvertedValue[1]&0x0fff)*1.2/(ADC_ConvertedValue[0]&0X0FFF); //放大100倍
    // sound
    adv[2] = (float)(ADC_ConvertedValue[2]&0x0fff)*1.2/(ADC_ConvertedValue[0]&0X0FFF); //放大100倍
      
    ADC_Cmd(ADC1, DISABLE);
DMA_Cmd(DMA_Channel1, DISABLE);
                                  
    Voltage = adv[0]*50;
    Light = adv[1]*100;      
    Voice = adv[2]*100;
}

Keywords:STM32  ADC Reference address:STM32-ADC Introduction

Previous article:arm TFT
Next article:My ARM programming skills---Accumulation

Recommended ReadingLatest update time:2024-11-25 13:22

STM32 serial port download method
When playing with STM32, J-LINK emulator is good, but J-Link is expensive. Fortunately, STM32 has its own bootloader, which can download programs through the serial port. I think the serial port download method is simple and cheap, and it can be done with a USB-TTL converter.   1. First, on the minimum system board th
[Microcontroller]
STM32 serial port download method
Summary of STM32 program transplantation skills
1. The project replaces different STM32 chips eg: stm32f103rct6 ---- stm32f103c8t6: 1.1. Modify the chip Click the magic wand, and in the menu bar that appears, select the chip in the Device option. 1.2. Modify the startup file Here is an example of changing RCT6 to C8T6. Because the flash capacity is different
[Microcontroller]
Summary of STM32 program transplantation skills
USB interface design based on high-resolution ADC and PGA to connect thermocouples
The circuitry in this design includes a mixed-signal microcontroller, a USBUART (universal asynchronous receiver/transmitter), and a novel adaptive analog sensor input circuit. This circuit can connect various types of sensors to the two analog input channels of the design, control these devices on a USB host, and rea
[Microcontroller]
USB interface design based on high-resolution ADC and PGA to connect thermocouples
STM32 USART input and output C library function redirection understanding
Redirection: It means that users can rewrite C library functions by themselves. When the connector detects that the user has written a function with the same name as the C library function, the user-written function will be given priority, so that the user can modify the library. In order to redirect the printf() fu
[Microcontroller]
USB learning notes about stm32 USB_HW.c
view plaincopyprint?  #include stm32f10x_lib.h   #include stm32f10x_map.h   #include "usbreg.h"   #include "usbuser.h"   #include "usbcore.h"   #include "usb_hw.h"   #define _DEBUG_   #include "debug.h"      #define USB_EP_NUM  4      /*Start address of endpoint buffer   * Because each buffer block requires an endpoi
[Microcontroller]
"How to make an STM32 development board" - Communication interface part
In the previous article, we planned the serial port (UART) of the STM32 development board. This article introduces the remaining communication interfaces. When we drew the schematic diagram of the STM32F103VET6 microcontroller in the first lesson, we saw that in addition to UART, it also has SPI, CAN, I2C and other co
[Microcontroller]
stm32 touch screen XPT2046
Pin Function Description  Control word control bit command  Description of each bit of control byte  Single-ended input configuration  Differential Mode Input Configuration  Timing  The first 8 clocks are used to input the control byte through the DIN pin, the next 12 clock cycles will complete th
[Microcontroller]
stm32 touch screen XPT2046
STM32 USB keyboard and mouse routines
STM32 USB keyboard and mouse routines can be found on the Internet, but routines that integrate keyboard and mouse in the same device are relatively rare (I only found the 51+D12 version of Quanquan through GOOGLE). The following is a program for STM32 with integrated keyboard and mouse that I made with reference to
[Industrial Control]
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号