您的位置 首页 主动

AD与DA的完好装备

includeAD_DAHAD的配置函数includestm32f10xhincludestm32f10x_dachinclude

#includeAD_DA.H”

////////////AD的装备函数/////////////////////////////
#include “stm32f10x.h”
#include “stm32f10x_dac.h”
#include “stm32f10x_adc.h”
#include “stm32f10x_dma.h”
u16 ADC_ConvertedValue[BufferSize];

////////////AD滤波函数/////////////////////////////

////////////AD的装备函数/////////////////////////////
////////////AD函数/////////////////////////////
voidADC_configuration()
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

//对应的引脚装备:通道0~15顺次对应:PA(0~7),PB(0~1),PC(0~5)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
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_InitStructure.ADC_NbrOfChannel=1;//指定用于转化的通道数
ADC_Init(ADC1, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_55Cycles5);


ADC_Cmd(ADC1, ENABLE);

ADC_ResetCalibration(ADC1);

while(ADC_GetResetCalibrationStatus(ADC1));//等候ADC的校准寄存器被设置结束

ADC_StartCalibration(ADC1);

while(ADC_GetCalibrationStatus(ADC1));

ADC_SoftwareStartConvCmd(ADC1, ENABLE);

//ADC_ConvertedValue[cnt];
}

void DAC_Configuration(void)
{
DAC_InitTypeDef DAC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin= GPIO_Pin_4|GPIO_Pin_5;//IO端口的第4位
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;//端口形式为模仿输入方法
GPIO_Init(GPIOA, &GPIO_InitStructure);

/
DAC_InitStructure.DAC_Trigger=DAC_Trigger_Software;//DAC触发方法为软件操控
DAC_InitStructure.DAC_WaveGeneration=DAC_WaveGeneration_None;
//不从DAC端口发生波形
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bits8_0; //8位DA波形生成形式
DAC_InitStructure.DAC_OutputBuffer=DAC_OutputBuffer_Enable;
//使能DAC输出缓冲器
//用上面参数初始化DAC通道1
DAC_Init(DAC_Channel_2, &DAC_InitStructure);//用上面参数初始化DAC通道1
DAC_Cmd(DAC_Channel_2, ENABLE);//使能DAC通道1
DAC_Init(DAC_Channel_1, &DAC_InitStructure);//用上面参数初始化DAC通道1
DAC_Cmd(DAC_Channel_1, ENABLE);//使能DAC通道1

//DAC_SetChannel2Data(DAC_Align_12b_L, DAC_data);//设置DAC通道1为12位且数据左对齐形式
//DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE);//使能DAC通道1的软件触发方法,转化一次
//DAC_SetChannel1Data(DAC_Align_12b_L, DAC_data);//设置DAC通道1为12位且数据左对齐形式
//DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);//使能DAC通道1的软件触发方法,转化一次
}

void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr=ADC1_DR_Address;//界说DMA外设基地址
DMA_InitStructure.DMA_MemoryBaseAddr=(u32)&ADC_ConvertedValue; // 界说DMA内存基地址
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC;//外设作为数据传输的来历(外设传到内存) DMA_DIR_PeripheralDST——内存传到外设
DMA_InitStructure.DMA_BufferSize=3;//接连转化3个AD通道值
DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable; //外设寄存器地址不变
DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable;//内存寄存器地址递加
DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_Word; //外设数据宽度32bit
DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize_Word;//内存数据宽度32bit
DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;//DMA形式是循环
DMA_InitStructure.DMA_Priority=DMA_Priority_High; //DMA优先级
DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;//DMA没有设置内存到内存传输
DMA_Init(DMA1_Channel1,&DMA_InitStructure);
DMA_Cmd(DMA1_Channel1,ENABLE);
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/zhudong/257915.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部