ADC启动不了,搞的都晕了也过不去,求大虾们帮帮忙!
NVIC_Configuration();
TIM3_Configuration();
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
TIM_ARRPreloadConfig(TIM3, DISABLE);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_Update);
TIM_Cmd(TIM3, ENABLE);
GPIO_Configuration();
DMA_Configuration();
ADC1_Configuration();
//while(ADC_GetSoftwareStartConvStatus(ADC1)==RESET)
ADC_SoftwareStartConv(ADC1);
while(1) {}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM3_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period = (100-1);
TIM_TimeBaseStructure.TIM_Prescaler = (60-1);
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
}
void TIM3_IRQHandler(void)
{
//TIM_ClearITPendingBit(TIM3,TIM_FLAG_Update);
//test++;
//flag_time=1;
if(TIM_GetITStatus(TIM3, TIM_IT_Update)) //????update????
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //??update??????
test++;
}
flag_time=1;
}
void ADC1_IRQHandler(void)
{
flag_time=1;
}
void DMA2_Stream0_IRQHandler()
{
DMA_ClearITPendingBit(DMA2_Stream0,DMA_IT_TCIF1);
}
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_DMA2, ENABLE);
DMA_DeInit(DMA2_Stream0);
DMA_InitStructure.DMA_Channel=DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->DR;
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)&AD_Value;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = N*M;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
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_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE); //??DMA??
DMA_ClearITPendingBit(DMA2_Stream0,DMA_IT_TCIF1); //????DMA????
DMA_Cmd(DMA2_Stream0,ENABLE);
}
void ADC1_Configuration(void)
{
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;
ADC_DeInit(); //
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2,ENABLE);
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
ADC_CommonInitStructure.ADC_DMAAccessMode=ADC_DMAAccessMode_1;
ADC_CommonInitStructure.ADC_Mode=ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler=ADC_Prescaler_Div4;
ADC_CommonInitStructure.ADC_TwoSamplingDelay=ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_InitStructure.ADC_Resolution= ADC_Resolution_12b;
//ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC
ADC_InitStructure.ADC_ScanConvMode =ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//ADC_ExternalTrigConvEdge_Rising;
//ADC_InitStructure.ADC_ExternalTrigConv =ADC_ExternalTrigConv_T3_TRGO;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = M;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_144Cycles );
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_144Cycles );
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 3, ADC_SampleTime_144Cycles );
//ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 4, ADC_SampleTime_144Cycles );
//ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 5, ADC_SampleTime_144Cycles );
ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 4, ADC_SampleTime_144Cycles );
ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 5, ADC_SampleTime_144Cycles );
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 6, ADC_SampleTime_144Cycles );
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 7, ADC_SampleTime_144Cycles );
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 8, ADC_SampleTime_144Cycles );
//ADC_DMACmd(ADC1, ENABLE);
ADC_DMARequestAfterLastTransferCmd(ADC1,ENABLE);
ADC_DMACmd(ADC1,ENABLE);
ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
ADC_Cmd(ADC1, ENABLE);
//while(ADC_GetSoftwareStartConvStatus(ADC1)==RESET);
//ADC_SoftwareStartConv(ADC1);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC, ENABLE);
//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_1|GPIO_Pin_3|GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//PB
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; //
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//PC
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; //
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
|
|