博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
stm32f051 adc单次软件选择循环采样
阅读量:7106 次
发布时间:2019-06-28

本文共 1625 字,大约阅读时间需要 5 分钟。

hot3.png

void ADC1_Config(void){  ADC_InitTypeDef     ADC_InitStruct;  GPIO_InitTypeDef    GPIO_InitStruct;	  /* Enable  GPIOA clock */   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//使能GPIOA时钟  /* ADC1 Periph clock enable */  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);//使能ADC1时钟  /* Configure PA.0 as analog input */  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL  ;  GPIO_Init(GPIOA, &GPIO_InitStruct);		//设置PA0为模拟输入,PA0对应的是通道0    ADC总共19个通道,16个外部通道,一个温度,一个电压,还有一个自己内部的Vbat通道;	  /* ADC1 DeInit */    ADC_DeInit(ADC1);    /* Initialize ADC structure */  ADC_StructInit(&ADC_InitStruct);  /* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits  */  ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;  //12位的分辨率  ADC_InitStruct.ADC_ContinuousConvMode = ENABLE; //循环采样,意思就是在整个程序可以被进行多次转换,单次转换的话整个程序生命周期只能被触发一次  ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;软件触发  ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right; 右对齐  ADC_InitStruct.ADC_ScanDirection = ADC_ScanDirection_Upward;   ADC_Init(ADC1, &ADC_InitStruct); 		  ADC_ChannelConfig(ADC1, ADC_Channel_0, ADC_SampleTime_55_5Cycles); 设置采样通道,一定要把通道号和引脚的串口号对应起来    /* ADC Calibration */  ADC_GetCalibrationFactor(ADC1);   //adc校准  ADC_Cmd(ADC1, ENABLE);     使能adc  /* Wait the ADCEN falg */  while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));     /* ADC1 regular Software Start Conv */   ADC_StartOfConversion(ADC1);   开始ADC转换}ADCData[Num]=ADC_GetConversionValue(ADC1)      在实际程序中可以用这个函数进行采样

转载于:https://my.oschina.net/u/2252538/blog/650966

你可能感兴趣的文章
javascript设计模式:(三)
查看>>
C# 调用FLashPaper2(二)
查看>>
Linux初学(三)
查看>>
JS简易时钟
查看>>
UVA 1347 Tour DP
查看>>
.NET 动态脚本语言
查看>>
Java接口和抽象类用法总结
查看>>
浅析Java中的final关键字
查看>>
通过B表字段更新A表
查看>>
Matlab常用函数(1)
查看>>
19. Remove Nth Node From End of List C++删除链表的倒数第N个节点
查看>>
【原】centos系统命令部分不可用
查看>>
sqllocaldb
查看>>
因果图法设计测试用例
查看>>
BZOJ4807:車(组合数学,高精度)
查看>>
sas中的sql(8)sql选项解析,数据字典
查看>>
BZOJ4567:[SCOI2016]背单词——题解
查看>>
洛谷3676:小清新数据结构题——题解
查看>>
sed 指定行之间的内容替换
查看>>
MQTT协议简记
查看>>