資源簡介
STM32F103RCT6程序例——電壓測量例

代碼片段和文件信息
#include?“adc.h“
uint16_t?adc_mem[QUEUE_LEN];??//ADC緩沖隊列
int?ADC_LEN?=?8;???????????????//對列長度
int?ADC_NUM?=?3;???????????????//相當于除數
void?ADC_Config(void)
{
??ADC_InitTypeDef?????ADC_InitStructure;
GPIO_InitTypeDef????GPIO_InitStruct;
??
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA?ENABLE);???//開啟adc1和GPIOA的時鐘
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1?ENABLE);????
??GPIO_InitStruct.GPIO_Pin?=?GPIO_Pin_0?|?GPIO_Pin_1;?????
??GPIO_InitStruct.GPIO_Mode?=?GPIO_Mode_AIN;?????????????//配置PA1,PA2位模擬輸入模式
??GPIO_Init(GPIOA?&GPIO_InitStruct);??????????????????????//注冊到結構體
ADC_DeInit(ADC1);???????????????????????????????????????????//將adc配置為缺省值
??ADC_InitStructure.ADC_Mode?=?ADC_Mode_Independent?;??????????//adc?為獨立轉換模式
??ADC_InitStructure.ADC_ScanConvMode?=?ENABLE?;//使能各通道掃描
??ADC_InitStructure.ADC_ContinuousConvMode?=?ENABLE?;//設置為連續轉換模式
??ADC_InitStructure.ADC_ExternalTrigConv?=?ADC_ExternalTrigConv_None?;//沒有外部觸發
??ADC_InitStructure.ADC_DataAlign?=?ADC_DataAlign_Right?;//adc?數據右對齊
??ADC_InitStructure.ADC_NbrOfChannel?=?2?;?//adc通道數為2個
??ADC_Init(ADC1?&ADC_InitStructure)?;//注冊到結構體?
??/*?ADC1?regular?channels?configuration?*/?
??ADC_RegularChannelConfig(ADC1?ADC_Channel_0?1?ADC_SampleTime_71Cycles5);
ADC_RegularChannelConfig(ADC1?ADC_Channel_1?2?ADC_SampleTime_71Cycles5);
?
ADC_DMACmd(ADC1ENABLE);
??/*?Enable?ADC1?*/
??ADC_Cmd(ADC1?ENABLE);
??/*?Enable?ADC1?reset?calibration?register?*/???
ADC_ResetCalibration(ADC1);
??/*?Check?the?end?of?ADC1?reset?calibration?register?*/
??while(ADC_GetResetCalibrationStatus(ADC1));
??/*?Start?ADC1?calibration?*/
??ADC_StartCalibration(ADC1);
??/*?Check?the?end?of?ADC1?calibration?*/
??while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCmd(ADC1?ENABLE);
}
void?DMA_Config(void){
DMA_InitTypeDef?????DMA_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1??ENABLE);
DMA_DeInit(DMA1_Channel1);
??DMA_InitStruct.DMA_PeripheralbaseAddr?=?(uint32_t)&ADC1->DR;???//dma外設地址為adc的數據寄存器
??DMA_InitStruct.DMA_MemorybaseAddr?=?(uint32_t)&adc_mem;
??DMA_InitStruct.DMA_DIR?=?DMA_DIR_PeripheralSRC;//內存作為數據目的地
??DMA_InitStruct.DMA_BufferSize?=?QUEUE_LEN?;//DMA深度為隊列的總長度?這里是16
??DMA_InitStruct.DMA_PeripheralInc?=?DMA_PeripheralInc_Disable;//外設地址固定不變
??DMA_InitStruct.DMA_MemoryInc?=?DMA_MemoryInc_Enable;//內存地址自動修改
??DMA_InitStruct.DMA_PeripheralDataSize?=?DMA_PeripheralDataSize_HalfWord;//外設半字長
??DMA_InitStruct.DMA_MemoryDataSize?=?DMA_MemoryDataSize_HalfWord;//內存半字長
??DMA_InitStruct.DMA_Mode?=?DMA_Mode_Circular;//dma循環方式,到達adc_mem末地址后自動返回到開始地址
??DMA_InitStruct.DMA_Priority?=?DMA_Priority_High;//dma為高優先級
??DMA_InitStruct.DMA_M2M?=?DMA_M2M_Disable;//禁止mem之間dma
??DMA_Init(DMA1_Channel1?&DMA_InitStruct);//注冊到結構體
??
??DMA_Cmd(DMA1_Channel1?ENABLE);
}
/*
入口參數?channel??通道值
功能:在dma的緩沖隊列中取出相應通道的ad值求和并且平均值濾波
返回值:濾波后的對應通道的ad值
*/
uint16_t?read_adc(uint8_t?channel)
{
uint32_t?temp?=?0;
uint16_t?adc_val=0;
int
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-12-19?12:08??電壓測量程序例\
?????文件????????3577??2016-11-19?00:52??電壓測量程序例\core_cm3.crf
?????目錄???????????0??2016-12-19?12:08??電壓測量程序例\drive\
?????文件????????3413??2016-11-22?22:09??電壓測量程序例\drive\adc.c
?????文件?????????201??2015-08-31?09:55??電壓測量程序例\drive\adc.h
?????文件????????1501??2015-07-07?15:17??電壓測量程序例\drive\key.c
?????文件?????????176??2015-07-07?15:14??電壓測量程序例\drive\key.h
?????文件?????????897??2015-07-07?11:10??電壓測量程序例\drive\Systick.c
?????文件?????????404??2015-07-07?11:10??電壓測量程序例\drive\Systick.h
?????文件????????1843??2015-09-01?20:28??電壓測量程序例\drive\tim.c
?????文件?????????266??2015-08-31?09:49??電壓測量程序例\drive\tim.h
?????文件????????1938??2015-09-01?20:41??電壓測量程序例\drive\uart.c
?????文件?????????219??2015-08-31?09:29??電壓測量程序例\drive\uart.h
?????文件???????82718??2016-11-22?22:09??電壓測量程序例\Jli
?????文件?????????671??2016-11-19?00:50??電壓測量程序例\Jli
?????目錄???????????0??2016-12-19?12:08??電壓測量程序例\LCD12864\
?????目錄???????????0??2016-12-19?12:08??電壓測量程序例\LCD1602\
?????文件????????2289??2015-09-01?20:35??電壓測量程序例\LCD1602\lcd1602.c
?????文件?????????511??2015-09-01?22:21??電壓測量程序例\LCD1602\lcd1602.h
?????目錄???????????0??2016-12-19?12:08??電壓測量程序例\lib\
?????目錄???????????0??2016-12-19?12:08??電壓測量程序例\lib\inc\
?????文件???????43603??2015-07-08?22:15??電壓測量程序例\lib\inc\font.h
?????文件????????8982??2014-11-09?16:24??電壓測量程序例\lib\inc\misc.h
?????文件?????????715??2015-07-07?12:47??電壓測量程序例\lib\inc\spi.h
?????文件???????21690??2014-11-09?16:24??電壓測量程序例\lib\inc\stm32f10x_adc.h
?????文件????????7555??2014-11-09?16:24??電壓測量程序例\lib\inc\stm32f10x_bkp.h
?????文件???????27559??2014-11-09?16:24??電壓測量程序例\lib\inc\stm32f10x_can.h
?????文件????????6573??2014-11-09?16:24??電壓測量程序例\lib\inc\stm32f10x_cec.h
?????文件????????2162??2014-11-09?16:24??電壓測量程序例\lib\inc\stm32f10x_crc.h
?????文件???????15233??2014-11-09?16:24??電壓測量程序例\lib\inc\stm32f10x_dac.h
?????文件????????3818??2014-11-09?16:24??電壓測量程序例\lib\inc\stm32f10x_dbgmcu.h
............此處省略165個文件信息
評論
共有 條評論