新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > STM32學(xué)習(xí)筆記之ADC--DMA方式

STM32學(xué)習(xí)筆記之ADC--DMA方式

作者: 時間:2016-11-28 來源:網(wǎng)絡(luò) 收藏


void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;//定義DMA初始化結(jié)構(gòu)體
DMA_DeInit(DMA_Channel1);//復(fù)位DMA通道1
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;//定義DMA通道外設(shè)基地址=ADC1_DR_Address
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue; //定義DMA通道存儲器地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//指定外設(shè)為源地址
DMA_InitStructure.DMA_BufferSize = 1;//定義DMA緩沖區(qū)大小1
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//當(dāng)前外設(shè)寄存器地址不變
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;//當(dāng)前存儲器地址不變
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//定義外設(shè)數(shù)據(jù)寬度16位
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//定義存儲器數(shù)據(jù)寬度16位
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA通道操作模式位環(huán)形緩沖模式
DMA_InitStructure.DMA_Priority = DMA_Priority_High;//DMA通道優(yōu)先級高
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//禁止DMA通道存儲器到存儲器傳輸
DMA_Init(DMA_Channel1, &DMA_InitStructure);//初始化DMA通道1
DMA_Cmd(DMA_Channel1, ENABLE);//使能DMA通道1
}

void ADC_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;//定義ADC初始化結(jié)構(gòu)體變量
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//ADC1和ADC2工作在獨立模式
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //使能掃描
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//ADC轉(zhuǎn)換工作在連續(xù)模式
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;//有軟件控制轉(zhuǎn)換
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//轉(zhuǎn)換數(shù)據(jù)右對齊
ADC_InitStructure.ADC_NbrOfChannel = 1;//轉(zhuǎn)換通道為通道1
ADC_Init(ADC1, &ADC_InitStructure); //初始化ADC
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_28Cycles5);
//ADC1選擇信道14,音序器等級1,采樣時間239.5個周期
ADC_DMACmd(ADC1, ENABLE);//使能ADC1模塊DMA
ADC_Cmd(ADC1, ENABLE);//使能ADC1
ADC_ResetCalibration(ADC1); //重置ADC1校準(zhǔn)寄存器
while(ADC_GetResetCalibrationStatus(ADC1));//等待ADC1校準(zhǔn)重置完成
ADC_StartCalibration(ADC1);//開始ADC1校準(zhǔn)
while(ADC_GetCalibrationStatus(ADC1));//等待ADC1校準(zhǔn)完成
ADC_SoftwareStartConvCmd(ADC1, ENABLE); //使能ADC1軟件開始轉(zhuǎn)換
}

void USART_Config(void)
{
USART_InitTypeDef USART_InitStructure; //定義串口初始化結(jié)構(gòu)體
USART_InitStructure.USART_BaudRate = 115200;//波特率9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8位數(shù)據(jù)
USART_InitStructure.USART_StopBits = USART_StopBits_1;//1個停止位
USART_InitStructure.USART_Parity = USART_Parity_No ; //無校驗位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
//禁用RTSCTS硬件流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//使能發(fā)送接收
USART_InitStructure.USART_Clock = USART_Clock_Disable; //串口時鐘禁止
USART_InitStructure.USART_CPOL = USART_CPOL_Low; //時鐘下降沿有效
USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;//數(shù)據(jù)在第二個時鐘沿捕捉
USART_InitStructure.USART_LastBit = USART_LastBit_Disable;
//最后數(shù)據(jù)位的時鐘脈沖不輸出到SCLK引腳
USART_Init(USART2, &USART_InitStructure);//初始化串口2
USART_Cmd(USART2, ENABLE);//串口2使能
}

void Put_String(u8 *p)
{
while(*p)
{
USART_SendData(USART2, *p++);
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
{

}
}
}

void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}

PUTCHAR_PROTOTYPE
{
USART_SendData(USART2, (u8) ch);//發(fā)送一字節(jié)數(shù)據(jù)
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
{
}//等待發(fā)送完成
return ch;
}

本文引用地址:http://m.butianyuan.cn/article/201611/322988.htm

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;


ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
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_13Cycles5);


ADC_Cmd(ADC1, ENABLE);


ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}

ADCVal = ADC_GetConversionValue(ADC1);//查詢方式


上一頁 1 2 下一頁

評論


技術(shù)專區(qū)

關(guān)閉