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;
addressDMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue; //Define DMA memory base addressDMA_InitStructure.DMA_DIR
= DMA_DIR_PeripheralSRC;
= 3;
= DMA_PeripheralInc_Disable; //Peripheral register address remains
unchangedDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //Peripheral data width 32bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMA priority
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
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
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_GetResetCalibrationStatu
// 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);
{
}
adv[1] = (float)(ADC_ConvertedValue[1]&0x0fff)*1.2/(ADC_ConvertedValue[0]&0X0FFF); //放大100倍
DMA_Cmd(DMA_Channel1, DISABLE);
}
Previous article:arm TFT
Next article:My ARM programming skills---Accumulation
Recommended ReadingLatest update time:2024-11-25 13:22
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Automechanika Shanghai 2024 to feature a record number of concurrent events, bringing together industry wisdom and planning for future development
- Corporate Culture Sharing: How to cultivate scarce silicon IP professionals? SmartDV's journey of personal growth and teamwork
- Corporate Culture Sharing: How to cultivate scarce silicon IP professionals? SmartDV's journey of personal growth and teamwork
- NXP releases first ultra-wideband wireless battery management system solution
- NXP releases first ultra-wideband wireless battery management system solution
- Beijing Jiaotong University undergraduates explore Tektronix's advanced semiconductor open laboratory and experience the charm of cutting-edge high technology
- Beijing Jiaotong University undergraduates explore Tektronix's advanced semiconductor open laboratory and experience the charm of cutting-edge high technology
- New CEO: Dr. Torsten Derr will take over as CEO of SCHOTT AG on January 1, 2025
- How Edge AI Can Improve Everyday Experiences
- How Edge AI Can Improve Everyday Experiences
- RF Microwave Circuit 01
- Op amp compensation capacitor
- I just downloaded SJ/T 10369, it's too old, not worth 5 gold coins. Is there a newer one?
- 【Mil MYS-8MMX】Part 5: Download music online
- How to measure the phase difference between voltage and current of the device under test in LCR
- 【GD32F310G-START】SPI driver ST7735
- Clock Generator MS5351M
- What are the applications of ultrasonic transducers? Medical atomizer-power amplifier case
- TPYBoard development board construction and Alibaba Cloud service sending data
- Does anyone know the standards for embedded OS? What does it mean that RTthread has passed GJB7718-2012 and GJB7706-2012?