欢迎一起交流
STM32单片机源程序如下:
- #include "config.h"
- /***********************************************************************
- 外设时钟使能
- ************************************************************************/
- void RCC_Configuration(void)
- {
- //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);//DMA时钟
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_ADC1|RCC_APB2Periph_ADC2,ENABLE);//PA和ADC1&2时钟
- }
- /*******************************************************************************
- *
- 全部用到的引脚将在在配置
- *
- *******************************************************************************/
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /*模拟输入 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //模拟输入引脚
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- }
- static void ADC_Mode_Config(void)
- {
- ADC_InitTypeDef ADC_InitStructure;
-
- /* ADC1 configuration */
- ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;//双ADC模式
- ADC_InitStructure.ADC_ScanConvMode = DISABLE;
- ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
- ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
- ADC_InitStructure.ADC_NbrOfChannel = 1;
- ADC_Init(ADC1, &ADC_InitStructure); //初始化ADC1
- ADC_Init(ADC2, &ADC_InitStructure); //初始化ADC2
- /* ADC1 regular channel1 configuration */
- ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_55Cycles5);
- /* ADC2 regular channel2 configuration */
- ADC_RegularChannelConfig(ADC2, ADC_Channel_2, 1, ADC_SampleTime_55Cycles5);
-
- /* Enable ADC1 DMA */
- ADC_DMACmd(ADC1, ENABLE); //在双ADC模式下,即使不使用ADC,也要使能DMA
- /* Enable ADC2 DMA */
- ADC_DMACmd(ADC2, ENABLE);
-
- /* Enable ADC1 */
- ADC_Cmd(ADC1, ENABLE);
- /* Enable ADC2 */
- ADC_Cmd(ADC2, ENABLE);
- /* Enable ADC1 reset calibaration register */
- ADC_ResetCalibration(ADC1);
- /* Check the end of ADC1 reset calibration register */
- while(ADC_GetResetCalibrationStatus(ADC1));
- /* Enable ADC1 reset calibaration register */
- ADC_ResetCalibration(ADC2);
- /* Check the end of ADC2 reset calibration register */
- while(ADC_GetResetCalibrationStatus(ADC2));
- /* Start ADC1 calibaration */
- ADC_StartCalibration(ADC1);
- /* Check the end of ADC1 calibration */
- while(ADC_GetCalibrationStatus(ADC1));
-
- /* Start ADC2 calibaration */
- ADC_StartCalibration(ADC2);
- /* Check the end of ADC2 calibration */
- while(ADC_GetCalibrationStatus(ADC2));
- /* Start ADC1 Software Conversion */
- ADC_SoftwareStartConvCmd(ADC1, ENABLE);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
ADC之双ADC模式.rar
(346.71 KB, 下载次数: 60)
|