|
歡迎一起交流
STM32單片機(jī)源程序如下:
- #include "config.h"
- /***********************************************************************
- 外設(shè)時(shí)鐘使能
- ************************************************************************/
- void RCC_Configuration(void)
- {
- //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);//DMA時(shí)鐘
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_ADC1|RCC_APB2Periph_ADC2,ENABLE);//PA和ADC1&2時(shí)鐘
- }
- /*******************************************************************************
- *
- 全部用到的引腳將在在配置
- *
- *******************************************************************************/
- 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);
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
ADC之雙ADC模式.rar
(346.71 KB, 下載次數(shù): 60)
2017-7-25 00:42 上傳
點(diǎn)擊文件名下載附件
ADC轉(zhuǎn)換 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|