stm32f103
今天照着例子整了个定时器启动AD采样,可怎么也采不到数据。
希望高手指点一下!!
部分代码如下: /* System clocks configuration ------------------------------------*/ RCC_Configuration(); /* NVIC configuration ------------------------------------------*/ NVIC_Configuration(); /* GPIO configuration -------------------------------------------*/ GPIO_Configuration(); /* TIM1 configuration ------------------------------------------*/ TIM1_DeInit(); /* Time Base configuration */ TIM1_TimeBaseStructure.TIM1_Prescaler = 0x4; TIM1_TimeBaseStructure.TIM1_CounterMode = TIM1_CounterMode_Up; TIM1_TimeBaseStructure.TIM1_Period = 0xFF; TIM1_TimeBaseStructure.TIM1_ClockDivision = 0x0; TIM1_TimeBaseStructure.TIM1_RepetitionCounter = 0x0; TIM1_TimeBaseInit(&TIM1_TimeBaseStructure);
/* DMA Channel1 Configuration -----------------------------------*/ DMA_DeInit(DMA_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_RegularConvertedValueTab; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 32; 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(DMA_Channel1, &DMA_InitStructure); /* Enable DMA channel1 */ DMA_Cmd(DMA_Channel1, ENABLE);
/* ADC1 configuration ------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel14 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_13Cycles5); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1 external trigger */ ADC_ExternalTrigConvCmd(ADC1, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* TIM1 counter enable */ TIM1_Cmd(ENABLE); /* Test on channel1 transfer complete flag */
while(!DMA_GetFlagStatus(DMA_FLAG_TC1)); /* Clear channel1 transfer complete flag */ DMA_ClearFlag(DMA_FLAG_TC1); /* TIM1 counter disable */ TIM1_Cmd(DISABLE);
while (1) { } }
|