我的ADC为什么不能读数据呢,采用的是软件查询方法,但当我在WHILE(1)前后加上 ADC_Cmd(ADC1, ENABLE);
ADC_Cmd(ADC1, DISABLE);
两个函数时能转换一次,求解啊,搞好几天了,谢谢各位了
int main(void)
{
uint8_t i,j;
//uint32_t sum1;
union SlideSample testadc;
/* System clocks configuration -------------------------------------------*/
RCC_Configuration();
/* NVIC configuration ----------------------------------------------------*/
NVIC_Configuration();
/* GPIO configuration ----------------------------------------------------*/
GPIO_Configuration();
/* USART configuration ----------------------------------------------------*/
USART_Configuration();
/* DMA configuration ----------------------------------------------------*/
DMA_Configuration();
/* PWM configuration ----------------------------------------------------*/
//PWM_Configuration();
/* ADC configuration ----------------------------------------------------*/
ADC_Configuration();
ADC_CH_channel(0);
while(1)
{
// ADC_Cmd(ADC1, ENABLE);
// ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_13Cycles5);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
delay_ms(50);
//while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)!=RESET);
//while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
//ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
ADC_Value[0]=ADC_GetConversionValue(ADC1);
//ADC_SoftwareStartConvCmd(ADC1, DISABLE);
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
ADC_SoftwareStartConvCmd(ADC1, DISABLE);
//ADC_Cmd(ADC1, DISABLE);
testadc.sword = ADC_Value[0];
j = testadc.sbyte[1];
j = j&0x0F;
USART_SendData(USART1,j);
delay_ms(0x5F);
j = testadc.sbyte[0];
USART_SendData(USART1,j);
delay_ms(0x5F);
}
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
/* 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;//选择定时器1的捕获比较1作为转换外部触发
ADC_InitStructure.ADC_ExternalTrigConv =ADC_ExternalTrigInjecConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADC数据右对齐
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel14 configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_13Cycles5);//ADC_Channel_14
/* Set injected sequencer length */
// ADC_InjectedSequencerLengthConfig(ADC1, 1);
/* ADC1 injected channel Configuration */
// ADC_InjectedChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_71Cycles5);
/* ADC1 injected external trigger configuration */
ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None);
// ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigConv_T1_CC1);
/* Enable automatic injected conversion start after regular one */
// ADC_AutoInjectedConvCmd(ADC1, ENABLE);//使能ADC在规则组转化后自动开始注入转换组
/* Enable ADC1 DMA */
// ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 external trigger */
//ADC_ExternalTrigConvCmd(ADC1, ENABLE);//使能ADC的经外部触发启动转换功能
/* Enable JEOC interrupt */
//ADC_ITConfig(ADC1, ADC_IT_EOC, DISABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* Test on channel1 transfer complete flag */
// while(!DMA_GetFlagStatus(DMA1_FLAG_TC1));
/* Clear channel1 transfer complete flag */
// DMA_ClearFlag(DMA1_FLAG_TC1);
ADC_SoftwareStartConvCmd(ADC1, ENABLE); //使能ADC1软件开始转换
// ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
} |