找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4746|回復: 1
收起左側(cè)

STM32 ADC之雙ADC模式

[復制鏈接]
ID:222135 發(fā)表于 2017-7-24 21:44 | 顯示全部樓層 |閱讀模式
歡迎一起交流

STM32單片機源程序如下:
  1. #include "config.h"

  2. /***********************************************************************
  3.          外設(shè)時鐘使能
  4. ************************************************************************/
  5. void RCC_Configuration(void)
  6. {
  7.         //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);//DMA時鐘
  8.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_ADC1|RCC_APB2Periph_ADC2,ENABLE);//PA和ADC1&2時鐘
  9. }

  10. /*******************************************************************************
  11. *      
  12.         全部用到的引腳將在在配置
  13. *
  14. *******************************************************************************/
  15. void GPIO_Configuration(void)
  16. {
  17.         GPIO_InitTypeDef GPIO_InitStructure;
  18.   /*模擬輸入 */       
  19.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2;
  20.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;                //模擬輸入引腳
  21.         GPIO_Init(GPIOA, &GPIO_InitStructure);                                       
  22. }

  23. static void ADC_Mode_Config(void)
  24. {
  25.         ADC_InitTypeDef ADC_InitStructure;
  26.                
  27.         /* ADC1 configuration */
  28.         ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;//雙ADC模式                         
  29.         ADC_InitStructure.ADC_ScanConvMode = DISABLE;
  30.         ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  31.         ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  32.         ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  33.         ADC_InitStructure.ADC_NbrOfChannel = 1;
  34.         ADC_Init(ADC1, &ADC_InitStructure);                 //初始化ADC1
  35.         ADC_Init(ADC2, &ADC_InitStructure);                 //初始化ADC2

  36.         /* ADC1 regular channel1 configuration */
  37.         ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_55Cycles5);
  38.         /* ADC2 regular channel2 configuration */
  39.         ADC_RegularChannelConfig(ADC2, ADC_Channel_2, 1, ADC_SampleTime_55Cycles5);
  40.        
  41.         /* Enable ADC1 DMA */
  42.         ADC_DMACmd(ADC1, ENABLE);                   //在雙ADC模式下,即使不使用ADC,也要使能DMA
  43.         /* Enable ADC2 DMA */
  44.         ADC_DMACmd(ADC2, ENABLE);
  45.                
  46.         /* Enable ADC1 */
  47.         ADC_Cmd(ADC1, ENABLE);
  48.                 /* Enable ADC2 */
  49.         ADC_Cmd(ADC2, ENABLE);

  50.         /* Enable ADC1 reset calibaration register */   
  51.         ADC_ResetCalibration(ADC1);
  52.         /* Check the end of ADC1 reset calibration register */
  53.         while(ADC_GetResetCalibrationStatus(ADC1));
  54.                 /* Enable ADC1 reset calibaration register */   
  55.         ADC_ResetCalibration(ADC2);
  56.         /* Check the end of ADC2 reset calibration register */
  57.         while(ADC_GetResetCalibrationStatus(ADC2));

  58.         /* Start ADC1 calibaration */
  59.         ADC_StartCalibration(ADC1);
  60.         /* Check the end of ADC1 calibration */
  61.         while(ADC_GetCalibrationStatus(ADC1));
  62.        
  63.         /* Start ADC2 calibaration */
  64.         ADC_StartCalibration(ADC2);
  65.         /* Check the end of ADC2 calibration */
  66.         while(ADC_GetCalibrationStatus(ADC2));

  67.         /* Start ADC1 Software Conversion */
  68.         ADC_SoftwareStartConvCmd(ADC1, ENABLE);
  69. ……………………

  70. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
ADC之雙ADC模式.rar (346.71 KB, 下載次數(shù): 60)


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

ID:1013911 發(fā)表于 2022-3-29 10:29 | 顯示全部樓層
好兄弟,這個怎么用?新人不會用
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表