初级会员
- 积分
- 90
- 金钱
- 90
- 注册时间
- 2016-3-15
- 在线时间
- 27 小时
|
楼主 |
发表于 2017-3-23 10:50:58
|
显示全部楼层
这是ADC+DMA的配置函数#include "bsp_adc.h"
__IO uint16_t ADC_ConvertedValue[15000];
static void ADC_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// ê1Äü GPIO ê±Öó
RCC_AHB1PeriphClockCmd(RHEOSTAT_ADC_GPIO_CLK, ENABLE);
// ÅäÖÃ IO
GPIO_InitStructure.GPIO_Pin = RHEOSTAT_ADC_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; //2»éÏà-2»ÏÂà-
GPIO_Init(RHEOSTAT_ADC_GPIO_PORT, &GPIO_InitStructure);
}
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the DMA2_Stream0 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = DMA_IRQ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
static void ADC_Mode_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
// ------------------DMA Init ½á11ìå2Îêy 3õê¼»ˉ--------------------------
// ADC1ê1óÃDMA2£¬êy¾Yá÷0£¬í¨μà0£¬Õa¸öêÇêÖ2á1춨ËàμÄ
// ¿aÆôDMAê±Öó
RCC_AHB1PeriphClockCmd(RHEOSTAT_ADC_DMA_CLK, ENABLE);
// íaéè»ùÖ·Îa£oADC êy¾Y¼Ä′æÆ÷μØÖ·
DMA_InitStructure.DMA_PeripheralBaseAddr = RHEOSTAT_ADC_DR_ADDR;
// ′æ′¢Æ÷μØÖ·£¬êμ¼êéϾíêÇò»¸öÄú2¿SRAMμıäá¿
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)&ADC_ConvertedValue;
// êy¾Y′«êä·½ÏòÎaíaéèμ½′æ′¢Æ÷
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
// »o3åÇø′óD¡Îa£¬Ö¸ò»′Î′«êäμÄêy¾Yá¿
DMA_InitStructure.DMA_BufferSize = 15000;
// íaéè¼Ä′æÆ÷Ö»óDò»¸ö£¬μØÖ·2»óÃμYÔö
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
// ′æ′¢Æ÷μØÖ·1춨
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
// // íaéèêy¾Y′óD¡Îa°ë×Ö£¬¼′ὸö×Ö½ú
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
// ′æ′¢Æ÷êy¾Y′óD¡ò2Îa°ë×Ö£¬¸úíaéèêy¾Y′óD¡Ïàí¬
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
// Ñ-»·′«êäÄ£ê½
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
// DMA ′«êäí¨μàóÅÏ輶Îa¸ß£¬μ±ê1óÃò»¸öDMAí¨μàê±£¬óÅÏ輶éèÖÃ2»ó°Ïì
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
// ½ûÖ1DMA FIFO £¬ê1óÃÖ±á¬Ä£ê½
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
// FIFO ′óD¡£¬FIFOģ꽽ûÖ1ê±£¬Õa¸ö2»óÃÅäÖÃ
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
// Ñ¡Ôñ DMA í¨μ࣬í¨μà′æÔúóúá÷ÖD
DMA_InitStructure.DMA_Channel = RHEOSTAT_ADC_DMA_CHANNEL;
//3õê¼»ˉDMAá÷£¬á÷Ïàμ±óúò»¸ö′óμÄ1üμ࣬1üμààïÃæóDoü¶àí¨μà
DMA_Init(RHEOSTAT_ADC_DMA_STREAM, &DMA_InitStructure);
// ê1ÄüDMAá÷
DMA_Cmd(RHEOSTAT_ADC_DMA_STREAM, ENABLE);
//ê1ÄüDMA′«êäíê3éÖD¶Ï
DMA_ITConfig(RHEOSTAT_ADC_DMA_STREAM, DMA_IT_TC, ENABLE);
// ¿aÆôADCê±Öó
RCC_APB2PeriphClockCmd(RHEOSTAT_ADC_CLK , ENABLE);
// -------------------ADC Common ½á11ìå 2Îêy 3õê¼»ˉ------------------------
// ¶àá¢ADCÄ£ê½
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
// ê±ÖóÎafpclk x·ÖÆμ
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;
// ½ûÖ1DMAÖ±½ó·ÃÎêÄ£ê½
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
// 2éÑùê±¼ä¼ä¸ô
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
// -------------------ADC Init ½á11ìå 2Îêy 3õê¼»ˉ--------------------------
// ADC ·Ö±æÂê
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
// ½ûÖ1é¨Ãèģ꽣¬¶àí¨μà2é¼ˉ2ÅDèòa
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
// á¬Dø×a»»
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
//½ûÖ1ía2¿±ßÑØ′¥·¢
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
//ê1óÃèí¼t′¥·¢£¬ía2¿′¥·¢2»óÃÅäÖã¬×¢êíμô¼′¿é
// ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
//êy¾Yóò¶ÔÆë
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
//×a»»í¨μà 1¸ö
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(RHEOSTAT_ADC, &ADC_InitStructure);
//---------------------------------------------------------------------------
// ÅäÖà ADC í¨μà×a»»Ë3DòÎa1£¬μúò»¸ö×a»»£¬2éÑùê±¼äÎa3¸öê±ÖóÖüÆú
ADC_RegularChannelConfig(RHEOSTAT_ADC, RHEOSTAT_ADC_CHANNEL, 1, ADC_SampleTime_3Cycles);
// ê1ÄüDMAÇëÇó after last transfer (Single-ADC mode)
ADC_DMARequestAfterLastTransferCmd(RHEOSTAT_ADC, ENABLE);
// ê1ÄüADC
ADC_Cmd(RHEOSTAT_ADC, ENABLE);
// ê1ÄüADC DMA
ADC_DMACmd(RHEOSTAT_ADC, ENABLE);
//¿aê¼adc×a»»£¬èí¼t′¥·¢
ADC_SoftwareStartConv(RHEOSTAT_ADC);
}
void ADC_Configuration(void)
{
NVIC_Config();
ADC_GPIO_Config();
ADC_Mode_Config();
}
|
|