vu16 ADC_ConvertedValue[SampleNum]
void ADC_DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE)
DMA_DeInit(DMA1_Channel1)
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC
DMA_InitStructure.DMA_BufferSize = 1
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_Normal
DMA_InitStructure.DMA_Priority = DMA_Priority_High
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable
DMA_Init(DMA1_Channel1, &DMA_InitStructure)
DMA_Cmd(DMA1_Channel1,ENABLE)
}
void ADC1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure
ADC_InitTypeDef ADC_InitStructure
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15
GPIO_InitStructure.GPIO_Mode 逗郑= GPIO_Mode_AIN
GPIO_Init(GPIOC, &GPIO_InitStructure)
ADC_DMA_Config()
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE)
// ADC_DeInit(ADC1)
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent//ADC1和ADC2工作在独立模式
ADC_InitStructure.ADC_ScanConvMode = DISABLE//多通道
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE//连续转换
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_CC1//软件启动转换
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right//转换结果右对齐
ADC_InitStructure.ADC_NbrOfChannel = 1//通道数目
ADC_Init(ADC1, &ADC_InitStructure)
RCC_ADCCLKConfig(RCC_PCLK2_Div6) //PCLK 6分频
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_55Cycles5)
ADC_DMACmd(ADC1, ENABLE)
ADC_Cmd(ADC1, ENABLE)
ADC_ResetCalibration(ADC1)
while(ADC_GetResetCalibrationStatus(ADC1))
ADC_StartCalibration(ADC1)//开始校准
while(ADC_GetCalibrationStatus(ADC1))
ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigConv_T3_CC1)//TIM_CC1
ADC_ExternalTrigConvCmd(ADC1, ENABLE)
// ADC_SoftwareStartConvCmd (ADC1, ENABLE)
// ADC_ExternalTrigConvCmd(ADC1, ENABLE)
//设置外部触发模式使能
}
这个以前试过能用
这样的程序没必要使用dma的,dma的标志位你没清干净模知,发送数据容易出去,你直接使用ADC_ConvertedValueLocal = ADC_GetConversionValue( ADC1 )直接歼行拿到adc_dr中的值就可以了氏码哗 你试试
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)