打印
[STM32F2]

没分了,求大虾们免费帮帮忙

[复制链接]
1048|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wanshon|  楼主 | 2014-12-26 20:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
AD, dc, ADC, ST, TI
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);
}
沙发
zh113214| | 2014-12-26 21:01 | 只看该作者
这是干嘛用的呀

使用特权

评论回复
板凳
wanshon|  楼主 | 2014-12-28 09:31 | 只看该作者
AD采集

使用特权

评论回复
地板
wanshon|  楼主 | 2014-12-28 10:29 | 只看该作者
自己已解决,谢谢大侠们,时钟的问题。

使用特权

评论回复
5
玄德| | 2014-12-28 13:05 | 只看该作者

这个绝对有例程。

使用特权

评论回复
6
mmuuss586| | 2014-12-28 18:39 | 只看该作者

自己解决了就好;

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

12

帖子

0

粉丝