2019-07-20 07:32发布
jizhendong1994 发表于 2017-7-24 09:27 还是原子大哥,确实复位了,把复位程序段注释掉就可以了。多谢
jizhendong1994 发表于 2017-7-24 15:20 留邮箱呀
最多设置5个标签!
搞错了,那个是单个ADC的三通道采集,不是三ADC
这个才是
[mw_shl_code=c,true]/**
* @brief ADC configuration
* @note This function Configure the ADC peripheral
1) Enable peripheral clocks
2) Configure ADC Channel 12 pin as analog input
3) DMA2_Stream0 channel2 configuration
4) Configure ADC1 Channel 12
5) Configure ADC2 Channel 12
6) Configure ADC3 Channel 12
* @param None
* @retval None
*/#if defined (USE_STM324xG_EVAL)
#define ADC_CHANNEL ADC_Channel_12
#define ADC1_2_CHANNEL_GPIO_CLK RCC_AHB1Periph_GPIOC
#define GPIO_PIN GPIO_Pin_2
#define GPIO_PORT GPIOC
#define DMA_CHANNELx DMA_Channel_0
#define DMA_STREAMx DMA2_Stream0
#define ADC_CDR_ADDRESS ((uint32_t)0x40012308)
#elif defined (USE_STM324x7I_EVAL)
#define ADC_CHANNEL ADC_Channel_12
#define ADC1_2_CHANNEL_GPIO_CLK RCC_AHB1Periph_GPIOC
#define GPIO_PIN GPIO_Pin_2
#define GPIO_PORT GPIOC
#define DMA_CHANNELx DMA_Channel_0
#define DMA_STREAMx DMA2_Stream0
#define ADC_CDR_ADDRESS ((uint32_t)0x40012308)
#else
#define ADC_CHANNEL ADC_Channel_12
#define ADC1_2_CHANNEL_GPIO_CLK RCC_AHB1Periph_GPIOC
#define GPIO_PIN GPIO_Pin_2
#define GPIO_PORT GPIOC
#define DMA_CHANNELx DMA_Channel_0
#define DMA_STREAMx DMA2_Stream0
#define ADC_CDR_ADDRESS ((uint32_t)0x40012308)
#endif
static void ADC_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
/* Enable peripheral clocks *************************************************/
RCC_AHB1PeriphClockCmd( ADC1_2_CHANNEL_GPIO_CLK , ENABLE);
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_DMA2 , ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC1 , ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC2 , ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC3 , ENABLE);
/* Configure ADC Channel 12 pin as analog input *****************************/
GPIO_InitStructure.GPIO_Pin = GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIO_PORT, &GPIO_InitStructure);
/* DMA2 Stream0 channel0 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_CHANNELx;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC_CDR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&aADCTripleConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = 3;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA_STREAMx, &DMA_InitStructure);
/* DMA2_Stream0 enable */
DMA_Cmd(DMA_STREAMx, ENABLE);
/* ADC Common configuration *************************************************/
ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_Interl;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInit(&ADC_CommonInitStructure);
/* ADC1 regular channel 12 configuration ************************************/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_CHANNEL, 1, ADC_SampleTime_3Cycles);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* ADC2 regular channel 12 configuration ************************************/
ADC_Init(ADC2, &ADC_InitStructure);
/* ADC2 regular channel12 configuration */
ADC_RegularChannelConfig(ADC2, ADC_CHANNEL, 1, ADC_SampleTime_3Cycles);
/* ADC3 regular channel 12 configuration ************************************/
ADC_Init(ADC3, &ADC_InitStructure);
/* ADC3 regular channel12 configuration */
ADC_RegularChannelConfig(ADC3, ADC_CHANNEL, 1, ADC_SampleTime_3Cycles);
/* Enable DMA request after last transfer (multi-ADC mode) ******************/
ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
/* Enable ADC1 **************************************************************/
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC2 **************************************************************/
ADC_Cmd(ADC2, ENABLE);
/* Enable ADC3 **************************************************************/
ADC_Cmd(ADC3, ENABLE);
} [/mw_shl_code]
372883924@qq.com 谢谢大神
发一份给我可以吗,805863921@qq.com.谢谢
一周热门 更多>