找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4042|回复: 1
打印 上一主题 下一主题
收起左侧

STM32 ADC之双ADC模式

[复制链接]
跳转到指定楼层
楼主
ID:222135 发表于 2017-7-24 21:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
欢迎一起交流

STM32单片机源程序如下:
  1. #include "config.h"

  2. /***********************************************************************
  3.          外设时钟使能
  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, 下载次数: 58)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1013911 发表于 2022-3-29 10:29 | 只看该作者
好兄弟,这个怎么用?新人不会用
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表